forked from genert/pipedrive-api
/
deal_fields.go
194 lines (156 loc) · 5.81 KB
/
deal_fields.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package pipedrive
import (
"context"
"fmt"
"net/http"
)
// DealFieldsService handles deal fields related
// methods of the Pipedrive API.
//
// Pipedrive API dcos: https://developers.pipedrive.com/docs/api/v1/#!/DealFields
type DealFieldsService service
// DealField represents a Pipedrive deal.
type DealField struct {
ID int `json:"id"`
Key string `json:"key"`
Name string `json:"name"`
OrderNr int `json:"order_nr,omitempty"`
PicklistData interface{} `json:"picklist_data,omitempty"`
FieldType string `json:"field_type"`
AddTime string `json:"add_time,omitempty"`
UpdateTime string `json:"update_time,omitempty"`
ActiveFlag bool `json:"active_flag"`
EditFlag bool `json:"edit_flag"`
IndexVisibleFlag bool `json:"index_visible_flag,omitempty"`
DetailsVisibleFlag bool `json:"details_visible_flag,omitempty"`
AddVisibleFlag bool `json:"add_visible_flag,omitempty"`
ImportantFlag bool `json:"important_flag,omitempty"`
BulkEditAllowed bool `json:"bulk_edit_allowed,omitempty"`
SearchableFlag bool `json:"searchable_flag,omitempty"`
FilteringAllowed bool `json:"filtering_allowed,omitempty"`
SortableFlag bool `json:"sortable_flag,omitempty"`
UseField string `json:"use_field,omitempty"`
Link string `json:"link,omitempty"`
MandatoryFlag bool `json:"mandatory_flag"`
IsSubfield bool `json:"is_subfield,omitempty"`
Options []struct {
ID string `json:"id"`
Label string `json:"label"`
} `json:"options,omitempty"`
BulkEditAllowedConditions struct {
Status string `json:"status"`
} `json:"bulk_edit_allowed_conditions,omitempty"`
}
func (d DealField) String() string {
return Stringify(d)
}
// DealFieldsResponse represents multiple deal fields response.
type DealFieldsResponse struct {
Success bool `json:"success"`
Data []DealField `json:"data"`
AdditionalData AdditionalData `json:"additional_data"`
}
// DealFieldResponse represents single deal field response.
type DealFieldResponse struct {
Success bool `json:"success"`
Data DealField `json:"data"`
AdditionalData AdditionalData `json:"additional_data"`
}
// List all deal fields.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/DealFields/get_dealFields
func (s *DealFieldsService) List(ctx context.Context) (*DealFieldsResponse, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "/dealFields", nil, nil)
if err != nil {
return nil, nil, err
}
var record *DealFieldsResponse
resp, err := s.client.Do(ctx, req, &record)
if err != nil {
return nil, resp, err
}
return record, resp, nil
}
// GetByID returns specific deal field.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/DealFields/get_dealFields_id
func (s *DealFieldsService) GetByID(ctx context.Context, id int) (*DealFieldResponse, *Response, error) {
uri := fmt.Sprintf("/dealFields/%v", id)
req, err := s.client.NewRequest(http.MethodGet, uri, nil, nil)
if err != nil {
return nil, nil, err
}
var record *DealFieldResponse
resp, err := s.client.Do(ctx, req, &record)
if err != nil {
return nil, resp, err
}
return record, resp, nil
}
// DealFieldCreateOptions specifices the optional parameters to the
// DealFieldsService.Create method.
type DealFieldCreateOptions struct {
Name string `url:"name,omitempty"`
FieldType FieldType `url:"field_type,omitempty"`
Options string `url:"options,omitempty"`
}
// Create a new deal field.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/DealFields/post_dealFields
func (s *DealFieldsService) Create(ctx context.Context, opt *DealFieldCreateOptions) (*DealFieldResponse, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "/dealFields", nil, opt)
if err != nil {
return nil, nil, err
}
var record *DealFieldResponse
resp, err := s.client.Do(ctx, req, &record)
if err != nil {
return nil, resp, err
}
return record, resp, nil
}
// DealFieldUpdateOptions specifices the optional parameters to the
// DealFieldsService.Update method.
type DealFieldUpdateOptions struct {
Name string `url:"name,omitempty"`
Options string `url:"options,omitempty"`
}
// Update a deal field.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/DealFields/put_dealFields_id
func (s *DealFieldsService) Update(ctx context.Context, id int, opt *DealFieldUpdateOptions) (*ProductFieldResponse, *Response, error) {
uri := fmt.Sprintf("/dealFields/%v", id)
req, err := s.client.NewRequest(http.MethodPut, uri, nil, opt)
if err != nil {
return nil, nil, err
}
var record *ProductFieldResponse
resp, err := s.client.Do(ctx, req, &record)
if err != nil {
return nil, resp, err
}
return record, resp, nil
}
// DeleteMultiple deletes deal fields in bulk.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/DealFields/delete_dealFields
func (s *DealFieldsService) DeleteMultiple(ctx context.Context, ids []int) (*Response, error) {
req, err := s.client.NewRequest(http.MethodDelete, "/dealFields", &DeleteMultipleOptions{
Ids: arrayToString(ids, ","),
}, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Delete a deal field.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/DealFields/delete_dealFields_id
func (s *DealFieldsService) Delete(ctx context.Context, id uint) (*Response, error) {
uri := fmt.Sprintf("/dealFields/%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)
}