-
Notifications
You must be signed in to change notification settings - Fork 79
/
tag_api.go
56 lines (48 loc) · 1.21 KB
/
tag_api.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 intercom
import (
"encoding/json"
"fmt"
"gopkg.in/intercom/intercom-go.v2/interfaces"
)
// TagRepository defines the interface for working with Tags through the API.
type TagRepository interface {
list() (TagList, error)
save(tag *Tag) (Tag, error)
delete(id string) error
tag(tagList *TaggingList) (Tag, error)
}
// TagAPI implements TagRepository
type TagAPI struct {
httpClient interfaces.HTTPClient
}
func (api TagAPI) list() (TagList, error) {
tagList := TagList{}
data, err := api.httpClient.Get("/tags", nil)
if err != nil {
return tagList, err
}
err = json.Unmarshal(data, &tagList)
return tagList, err
}
func (api TagAPI) save(tag *Tag) (Tag, error) {
savedTag := Tag{}
data, err := api.httpClient.Post("/tags", tag)
if err != nil {
return savedTag, err
}
err = json.Unmarshal(data, &savedTag)
return savedTag, err
}
func (api TagAPI) delete(id string) error {
_, err := api.httpClient.Delete(fmt.Sprintf("/tags/%s", id), nil)
return err
}
func (api TagAPI) tag(taggingList *TaggingList) (Tag, error) {
savedTag := Tag{}
data, err := api.httpClient.Post("/tags", taggingList)
if err != nil {
return savedTag, err
}
err = json.Unmarshal(data, &savedTag)
return savedTag, err
}