forked from isuruceanu/gohubspot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactlists.go
99 lines (76 loc) · 2.26 KB
/
contactlists.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package gohubspot
import (
"fmt"
)
type ContactListsService service
type ContactList struct {
ParentID int `json:"parentId"` // Integer, read-only; The ID of the folder that the list belongs to. Currently folders can only be managed in the HubSpot app
Dynamic bool `json:"dynamic"`
Name string `json:"name"`
Filters Filters `json:"filters"`
PortalID int `json:"portalId"`
CreatedAt UnixTime `json:"createdAt"`
ListID int `json:"listId"`
UpdatedAt UnixTime `json:"updatedAt"`
InternalListID int `json:"internalListId"`
Deleteable bool `json:"deleteable"`
Metadata Metadata `json:"metaData"`
}
type Metadata struct {
Processing ProcessingType `json:"processing"`
Size int `json:"size"`
// Integer, read-only; The number of contacts in the list.
Error string `json:"error"`
// String, read-only; Any errors that happened the last time the list was processed.
LastProcessingStateChangeAt UnixTime `json:"lastProcessingStateChangeAt"`
LastSizeChangeAt UnixTime `json:"lastSizeChangeAt"`
}
type ContactLists struct {
Lists []ContactList `json:"lists"`
Page
}
type contactListsOptions struct {
listCount int
offset int
}
func NewContactListOptions(listCount, offset int) *contactListsOptions {
if listCount > 250 {
listCount = 250
}
return &contactListsOptions{listCount: listCount, offset: offset}
}
func (s *ContactListsService) GetContactLists() (*ContactLists, error) {
url := "/contacts/v1/lists"
req, err := s.client.Get(url)
if err != nil {
return nil, err
}
list := new(ContactLists)
err = s.client.Do(req, list)
return list, err
}
func (s *ContactListsService) CreateContactList(name string) (*ContactList, error) {
nameBody := struct {
Name string `json:"name"`
}{
Name: name,
}
url := "/contacts/v1/lists"
req, err := s.client.Post(url, nameBody)
if err != nil {
return nil, err
}
list := new(ContactList)
err = s.client.Do(req, list)
return list, err
}
func (s *ContactListsService) GetContactList(listId int) (*ContactList, error) {
url := fmt.Sprintf("/contacts/v1/lists/%d", listId)
req, err := s.client.Get(url)
if err != nil {
return nil, err
}
list := new(ContactList)
err = s.client.Do(req, list)
return list, err
}