forked from sogko/go-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 2
/
terms.go
77 lines (72 loc) · 2.47 KB
/
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
76
77
package wordpress
import (
"fmt"
"net/http"
)
type Term 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 TermsCollection struct {
client *Client
url string
}
func (col *TermsCollection) List(taxonomy string, params interface{}) ([]Term, *http.Response, []byte, error) {
var terms []Term
url := fmt.Sprintf("%v/%v", col.url, taxonomy)
resp, body, err := col.client.List(url, params, &terms)
return terms, resp, body, err
}
func (col *TermsCollection) Tag() *TermsTaxonomyCollection {
return &TermsTaxonomyCollection{
client: col.client,
url: fmt.Sprintf("%v/tag", col.url),
taxonomyBase: "tag",
}
}
func (col *TermsCollection) Category() *TermsTaxonomyCollection {
return &TermsTaxonomyCollection{
client: col.client,
url: fmt.Sprintf("%v/category", col.url),
taxonomyBase: "category",
}
}
type TermsTaxonomyCollection struct {
client *Client
url string
taxonomyBase string
}
func (col *TermsTaxonomyCollection) List(params interface{}) ([]Term, *http.Response, []byte, error) {
var terms []Term
resp, body, err := col.client.List(col.url, params, &terms)
return terms, resp, body, err
}
func (col *TermsTaxonomyCollection) Create(new *Term) (*Term, *http.Response, []byte, error) {
var created Term
resp, body, err := col.client.Create(col.url, new, &created)
return &created, resp, body, err
}
func (col *TermsTaxonomyCollection) Get(id int, params interface{}) (*Term, *http.Response, []byte, error) {
var entity Term
entityURL := fmt.Sprintf("%v/%v", col.url, id)
resp, body, err := col.client.Get(entityURL, params, &entity)
return &entity, resp, body, err
}
func (col *TermsTaxonomyCollection) Update(id int, post *Term) (*Term, *http.Response, []byte, error) {
var updated Term
entityURL := fmt.Sprintf("%v/%v", col.url, id)
resp, body, err := col.client.Update(entityURL, post, &updated)
return &updated, resp, body, err
}
func (col *TermsTaxonomyCollection) Delete(id int, params interface{}) (*Term, *http.Response, []byte, error) {
var deleted Term
entityURL := fmt.Sprintf("%v/%v", col.url, id)
resp, body, err := col.client.Delete(entityURL, params, &deleted)
return &deleted, resp, body, err
}