-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtag.go
44 lines (36 loc) · 1017 Bytes
/
tag.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
package verniy
import "context"
type tagResponse struct {
Data struct {
Tags []MediaTag `json:"mediaTagCollection"`
} `json:"data"`
}
func (c *Client) tagQuery(fields ...MediaTagField) string {
p := make([]string, len(fields))
for i := range fields {
p[i] = string(fields[i])
}
return FieldObject("MediaTagCollection", nil, p...)
}
// GetTags to get all tag list.
func (c *Client) GetTags(fields ...MediaTagField) ([]MediaTag, error) {
return c.GetTagsWithContext(context.Background(), fields...)
}
// GetTagsWithContext to get all tag list with context.
func (c *Client) GetTagsWithContext(ctx context.Context, fields ...MediaTagField) ([]MediaTag, error) {
if len(fields) == 0 {
fields = []MediaTagField{
MediaTagFieldName,
MediaTagFieldDescription,
MediaTagFieldCategory,
MediaTagFieldIsAdult,
}
}
query := FieldObject("query", nil, c.tagQuery(fields...))
var d tagResponse
err := c.post(ctx, query, nil, &d)
if err != nil {
return nil, err
}
return d.Data.Tags, nil
}