forked from genert/pipedrive-api
/
activity_types.go
154 lines (122 loc) · 4.3 KB
/
activity_types.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
142
143
144
145
146
147
148
149
150
151
152
153
154
package pipedrive
import (
"context"
"fmt"
"net/http"
)
// ActivityTypesService handles activities related
// methods of the Pipedrive API.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ActivityTypes
type ActivityTypesService service
// ActivityType represents a Pipedrive activity type.
type ActivityType struct {
ID int `json:"id"`
OrderNr int `json:"order_nr"`
Name string `json:"name"`
KeyString string `json:"key_string"`
IconKey string `json:"icon_key"`
ActiveFlag bool `json:"active_flag"`
Color interface{} `json:"color"`
IsCustomFlag bool `json:"is_custom_flag"`
AddTime string `json:"add_time"`
UpdateTime interface{} `json:"update_time"`
}
func (at ActivityType) String() string {
return Stringify(at)
}
// ActivityTypesResponse represents multiple activity types response.
type ActivityTypesResponse struct {
Success bool `json:"success"`
Data []ActivityType `json:"data"`
AdditionalData AdditionalData `json:"additional_data,omitempty"`
}
// ActivityTypeResponse represents single activity type response.
type ActivityTypeResponse struct {
Success bool `json:"success"`
Data ActivityType `json:"data"`
}
// List all activity types.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ActivityTypes/get_activityTypes
func (s *ActivityTypesService) List(ctx context.Context) (*ActivityTypesResponse, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "/activityTypes", nil, nil)
if err != nil {
return nil, nil, err
}
var record *ActivityTypesResponse
resp, err := s.client.Do(ctx, req, &record)
if err != nil {
return nil, resp, err
}
return record, resp, nil
}
// ActivityTypesAddOptions specifices the optional parameters to the
// ActivityTypesService.Create method.
type ActivityTypesAddOptions struct {
Name string `url:"name"`
IconKey string `url:"icon_key"`
Color string `url:"color,omitempty"`
}
// Create a new activity type.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ActivityTypes/post_activityTypes
func (s *ActivityTypesService) Create(ctx context.Context, opt *ActivityTypesAddOptions) (*ActivityTypeResponse, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "/activityTypes", nil, opt)
if err != nil {
return nil, nil, err
}
var record *ActivityTypeResponse
resp, err := s.client.Do(ctx, req, &record)
if err != nil {
return nil, resp, err
}
return record, resp, nil
}
// ActivityTypesEditOptions specifices the optional parameters to the
// ActivityTypesService.Update method.
type ActivityTypesEditOptions struct {
Name string `url:"name,omitempty"`
IconKey string `url:"icon_key,omitempty"`
Color string `url:"color,omitempty"`
OrderNr uint `url:"order_nr,omitempty"`
}
// Update activity type.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ActivityTypes/put_activityTypes_id
func (s *ActivityTypesService) Update(ctx context.Context, id int, opt *ActivityTypesEditOptions) (*ActivityTypeResponse, *Response, error) {
uri := fmt.Sprintf("/activityTpes/%v", id)
req, err := s.client.NewRequest(http.MethodPut, uri, nil, opt)
if err != nil {
return nil, nil, err
}
var record *ActivityTypeResponse
resp, err := s.client.Do(ctx, req, &record)
if err != nil {
return nil, resp, err
}
return record, resp, nil
}
// DeleteMultiple deletes activity types in bulk.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ActivityTypes/delete_activityTypes
func (s *ActivityTypesService) DeleteMultiple(ctx context.Context, ids []int) (*Response, error) {
req, err := s.client.NewRequest(http.MethodDelete, "/activityTypes", &DeleteMultipleOptions{
Ids: arrayToString(ids, ","),
}, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Delete an activity type.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ActivityTypes/delete_activityTypes_id
func (s *ActivityTypesService) Delete(ctx context.Context, id int) (*Response, error) {
uri := fmt.Sprintf("/activityTypes/%v", id)
req, err := s.client.NewRequest(http.MethodDelete, uri, nil, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}