forked from ohookins/contentful-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tag.go
56 lines (45 loc) · 1.16 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
package contentful
import (
"context"
"fmt"
"net/http"
"net/url"
)
// TagsService servıce
type TagsService service
// Tag model
type Tag struct {
Sys *Sys `json:"sys"`
Name string `json:"name,omitempty"`
}
// List returns tags collection
func (service *TagsService) List(ctx context.Context, spaceID string) *Collection {
path := fmt.Sprintf("/spaces/%s%s/tags", spaceID, getEnvPath(service.c))
method := http.MethodGet
req, err := service.c.newRequest(ctx, method, path, nil, nil, nil)
if err != nil {
return &Collection{}
}
col := NewCollection(&CollectionOptions{})
col.c = service.c
col.req = req
return col
}
// Get returns a single entry
func (service *TagsService) Get(ctx context.Context, spaceID, tagID string, locale ...string) (*Tag, error) {
path := fmt.Sprintf("/spaces/%s%s/entries/%s", spaceID, getEnvPath(service.c), tagID)
query := url.Values{}
if len(locale) > 0 {
query["locale"] = locale
}
method := http.MethodGet
req, err := service.c.newRequest(ctx, method, path, query, nil, nil)
if err != nil {
return &Tag{}, err
}
var tag Tag
if ok := service.c.do(req, &tag); ok != nil {
return nil, err
}
return &tag, err
}