forked from sogko/go-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 2
/
posts_terms.go
75 lines (69 loc) · 2.42 KB
/
posts_terms.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package wordpress
import (
"fmt"
"net/http"
)
type PostsTerm struct {
ID int `json:"id,omitempty"`
Count int `json:"integer,omitempty"`
Description string `json:"description,omitempty"`
Link string `json:"link,omitempty"`
Name string `json:"name"`
Slug string `json:"slug,omitempty"`
Taxonomy string `json:"taxonomy,omitempty"`
Parent int `json:"parent,omitempty"`
}
type PostsTermsCollection struct {
client *Client
url string
parent interface{}
parentType string
}
func (col *PostsTermsCollection) List(taxonomy string, params interface{}) ([]PostsTerm, *http.Response, []byte, error) {
var terms []PostsTerm
url := fmt.Sprintf("%v/%v", col.url, taxonomy)
resp, body, err := col.client.List(url, params, &terms)
return terms, resp, body, err
}
func (col *PostsTermsCollection) Tag() *PostsTermsTaxonomyCollection {
return &PostsTermsTaxonomyCollection{
client: col.client,
url: fmt.Sprintf("%v/tag", col.url),
taxonomyBase: "tag",
}
}
func (col *PostsTermsCollection) Category() *PostsTermsTaxonomyCollection {
return &PostsTermsTaxonomyCollection{
client: col.client,
url: fmt.Sprintf("%v/category", col.url),
taxonomyBase: "category",
}
}
type PostsTermsTaxonomyCollection struct {
client *Client
url string
taxonomyBase string
}
func (col *PostsTermsTaxonomyCollection) List(params interface{}) ([]PostsTerm, *http.Response, []byte, error) {
var terms []PostsTerm
resp, body, err := col.client.List(col.url, params, &terms)
return terms, resp, body, err
}
func (col *PostsTermsTaxonomyCollection) Create(id int) (*PostsTerm, *http.Response, []byte, error) {
var created PostsTerm
entityURL := fmt.Sprintf("%v/%v", col.url, id)
resp, body, err := col.client.Create(entityURL, nil, &created)
return &created, resp, body, err
}
func (col *PostsTermsTaxonomyCollection) Get(id int, params interface{}) (*PostsTerm, *http.Response, []byte, error) {
var entity PostsTerm
entityURL := fmt.Sprintf("%v/%v", col.url, id)
resp, body, err := col.client.Get(entityURL, params, &entity)
return &entity, resp, body, err
}
func (col *PostsTermsTaxonomyCollection) Delete(id int, params interface{}) (*PostsTerm, *http.Response, []byte, error) {
var deleted PostsTerm
entityURL := fmt.Sprintf("%v/%v", col.url, id)
resp, body, err := col.client.Delete(entityURL, params, &deleted)
return &deleted, resp, body, err
}