forked from belong-inc/go-hubspot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crm_tickets.go
141 lines (118 loc) · 4.69 KB
/
crm_tickets.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package hubspot
import "fmt"
const (
crmTicketsBasePath = "tickets"
)
// CrmTicketsServivce is an interface of CRM tickets endpoints of the HubSpot API.
// Reference: https://developers.hubspot.com/docs/api/crm/tickets
type CrmTicketsServivce interface {
List(option *RequestQueryOption) (*CrmTicketsList, error)
Get(ticketId string, option *RequestQueryOption) (*CrmTicket, error)
Create(reqData *CrmTicketCreateRequest) (*CrmTicket, error)
Archive(ticketId string) error
Update(ticketId string, reqData *CrmTicketUpdateRequest) (*CrmTicket, error)
Search(reqData *CrmTicketSearchRequest) (*CrmTicketsList, error)
}
// CrmTicketsServivceOp handles communication with the CRM tickets endpoints of the HubSpot API.
type CrmTicketsServivceOp struct {
client *Client
crmTicketsPath string
}
var _ CrmTicketsServivce = (*CrmTicketsServivceOp)(nil)
type CrmTicket struct {
Id *HsStr `json:"id,omitempty"`
Properties map[string]interface{} `json:"properties,omitempty"`
PropertiesWithHistory map[string]interface{} `json:"propertiesWithHistory,omitempty"`
CreatedAt *HsTime `json:"createdAt,omitempty"`
UpdatedAt *HsTime `json:"updatedAt,omitempty"`
Archived *HsBool `json:"archived,omitempty"`
ArchivedAt *HsTime `json:"archivedAt,omitempty"`
}
type CrmTicketsPagingData struct {
After *HsStr `json:"after,omitempty"`
Link *HsStr `json:"link,omitempty"`
}
type CrmTicketsPaging struct {
Next *CrmTicketsPagingData `json:"next,omitempty"`
}
type CrmTicketsList struct {
Total *HsInt `json:"total,omitempty"`
Results []*CrmTicket `json:"results"`
Paging *CrmTicketsPaging `json:"paging,omitempty"`
}
func (s *CrmTicketsServivceOp) List(option *RequestQueryOption) (*CrmTicketsList, error) {
var resource CrmTicketsList
if err := s.client.Get(s.crmTicketsPath, &resource, option); err != nil {
return nil, err
}
return &resource, nil
}
func (s *CrmTicketsServivceOp) Get(ticketId string, option *RequestQueryOption) (*CrmTicket, error) {
var resource CrmTicket
path := fmt.Sprintf("%s/%s", s.crmTicketsPath, ticketId)
if err := s.client.Get(path, &resource, option); err != nil {
return nil, err
}
return &resource, nil
}
type CrmTicketAssociationTarget struct {
Id *HsStr `json:"id,omitempty"`
}
type CrmTicketAssociationType struct {
AssociationCategory *HsStr `json:"associationCategory,omitempty"`
AssociationTypeId *HsInt `json:"associationTypeId,omitempty"`
}
type CrmTicketAssociation struct {
To CrmTicketAssociationTarget `json:"to,omitempty"`
Types []CrmTicketAssociationType `json:"types,omitempty"`
}
type CrmTicketCreateRequest struct {
Properties map[string]interface{} `json:"properties,omitempty"`
Associations []*CrmTicketAssociation `json:"associations,omitempty"`
}
type CrmTicketUpdateRequest = CrmTicketCreateRequest
func (s *CrmTicketsServivceOp) Create(reqData *CrmTicketCreateRequest) (*CrmTicket, error) {
var resource CrmTicket
if err := s.client.Post(s.crmTicketsPath, reqData, &resource); err != nil {
return nil, err
}
return &resource, nil
}
func (s *CrmTicketsServivceOp) Archive(ticketId string) error {
path := fmt.Sprintf("%s/%s", s.crmTicketsPath, ticketId)
return s.client.Delete(path, nil)
}
func (s *CrmTicketsServivceOp) Update(ticketId string, reqData *CrmTicketUpdateRequest) (*CrmTicket, error) {
var resource CrmTicket
path := fmt.Sprintf("%s/%s", s.crmTicketsPath, ticketId)
if err := s.client.Patch(path, reqData, &resource); err != nil {
return nil, err
}
return &resource, nil
}
type CrmTicketSearchFilter struct {
Value *HsStr `json:"value,omitempty"`
HighValue *HsStr `json:"highValue,omitempty"`
Values []*HsStr `json:"values,omitempty"`
PropertyName *HsStr `json:"propertyName,omitempty"`
Operator *HsStr `json:"operator,omitempty"`
}
type CrmTicketSearchFilterGroup struct {
Filters []*CrmTicketSearchFilter `json:"filters,omitempty"`
Sorts []*HsStr `json:"sorts,omitempty"`
Query *HsStr `json:"query"`
Properties []*HsStr `json:"properties,omitempty"`
Limit *HsInt `json:"limit,omitempty"`
After *HsInt `json:"after,omitempty"`
}
type CrmTicketSearchRequest struct {
FilterGroups []*CrmTicketSearchFilterGroup `json:"filterGroups,omitempty"`
}
func (s *CrmTicketsServivceOp) Search(reqData *CrmTicketSearchRequest) (*CrmTicketsList, error) {
var resource CrmTicketsList
path := fmt.Sprintf("%s/search", s.crmTicketsPath)
if err := s.client.Post(path, reqData, &resource); err != nil {
return nil, err
}
return &resource, nil
}