forked from intercom/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment_api.go
39 lines (33 loc) · 896 Bytes
/
segment_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
package intercom
import (
"encoding/json"
"fmt"
"gopkg.in/intercom/intercom-go.v2/interfaces"
)
// SegmentRepository defines the interface for working with Segments through the API.
type SegmentRepository interface {
list() (SegmentList, error)
find(id string) (Segment, error)
}
// SegmentAPI implements SegmentRepository
type SegmentAPI struct {
httpClient interfaces.HTTPClient
}
func (api SegmentAPI) list() (SegmentList, error) {
segmentList := SegmentList{}
data, err := api.httpClient.Get("/segments", nil)
if err != nil {
return segmentList, err
}
err = json.Unmarshal(data, &segmentList)
return segmentList, err
}
func (api SegmentAPI) find(id string) (Segment, error) {
segment := Segment{}
data, err := api.httpClient.Get(fmt.Sprintf("/segments/%s", id), nil)
if err != nil {
return segment, err
}
err = json.Unmarshal(data, &segment)
return segment, err
}