forked from intercom/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_api.go
52 lines (45 loc) · 1.22 KB
/
event_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
package intercom
import (
"encoding/json"
"gopkg.in/intercom/intercom-go.v2/interfaces"
)
// EventRepository defines the interface for working with Events through the API.
type EventRepository interface {
save(*Event) error
list(params eventParams) (EventList, error)
summary(params eventParams) (EventSummaries, error)
}
// EventAPI implements EventRepository
type EventAPI struct {
httpClient interfaces.HTTPClient
}
func (api EventAPI) save(event *Event) error {
_, err := api.httpClient.Post("/events", event)
return err
}
func (api EventAPI) list(params eventParams) (EventList, error) {
eventList := EventList{}
data, err := api.listEvents(params)
if err != nil {
return eventList, err
}
err = json.Unmarshal(data, &eventList)
return eventList, err
}
func (api EventAPI) summary(params eventParams) (EventSummaries, error) {
eventSummaries := EventSummaries{}
data, err := api.listEvents(params)
if err != nil {
return eventSummaries, err
}
err = json.Unmarshal(data, &eventSummaries)
return eventSummaries, err
}
func (api EventAPI) listEvents(params eventParams) ([]byte, error) {
params.Type = "user"
data, err := api.httpClient.Get("/events", params)
if err != nil {
return nil, err
}
return data, nil
}