forked from genert/pipedrive-api
/
product_fields.go
191 lines (153 loc) · 5.78 KB
/
product_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
package pipedrive
import (
"context"
"fmt"
"net/http"
)
// ProductFieldsService handles pipelines related
// methods of the Pipedrive API.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ProductFields
type ProductFieldsService service
// ProductField represents a Pipedrive product field.
type ProductField struct {
ID int `json:"id"`
Key string `json:"key"`
Name string `json:"name"`
OrderNr int `json:"order_nr"`
PicklistData interface{} `json:"picklist_data,omitempty"`
FieldType string `json:"field_type"`
AddTime string `json:"add_time"`
UpdateTime string `json:"update_time"`
ActiveFlag bool `json:"active_flag"`
EditFlag bool `json:"edit_flag"`
IndexVisibleFlag bool `json:"index_visible_flag"`
DetailsVisibleFlag bool `json:"details_visible_flag"`
AddVisibleFlag bool `json:"add_visible_flag"`
ImportantFlag bool `json:"important_flag"`
BulkEditAllowed bool `json:"bulk_edit_allowed"`
SearchableFlag bool `json:"searchable_flag"`
FilteringAllowed bool `json:"filtering_allowed"`
SortableFlag bool `json:"sortable_flag"`
UseField string `json:"use_field,omitempty"`
Link string `json:"link,omitempty"`
MandatoryFlag bool `json:"mandatory_flag"`
DisplayField string `json:"display_field,omitempty"`
Options []struct {
ID bool `json:"id"`
Label string `json:"label"`
} `json:"options,omitempty"`
}
func (p ProductField) String() string {
return Stringify(p)
}
// ProductFieldsResponse represents multiple product fields response.
type ProductFieldsResponse struct {
Success bool `json:"success"`
Data []ProductField `json:"data"`
AdditionalData AdditionalData `json:"additional_data"`
}
// ProductFieldResponse represents single product field response.
type ProductFieldResponse struct {
Success bool `json:"success"`
Data ProductField `json:"data"`
AdditionalData AdditionalData `json:"additional_data"`
}
// List returns all data about product fields.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ProductFields/get_productFields
func (s *ProductFieldsService) List(ctx context.Context) (*ProductFieldsResponse, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "/productFields", nil, nil)
if err != nil {
return nil, nil, err
}
var record *ProductFieldsResponse
resp, err := s.client.Do(ctx, req, &record)
if err != nil {
return nil, resp, err
}
return record, resp, nil
}
// GetByID returns a specific product field.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ProductFields/get_productFields_id
func (s *ProductFieldsService) GetByID(ctx context.Context, id int) (*ProductFieldResponse, *Response, error) {
uri := fmt.Sprintf("/productFields/%v", id)
req, err := s.client.NewRequest(http.MethodGet, uri, nil, nil)
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
}
// ProductFieldCreateOptions specifices the optional parameters to the
// ProductFieldsService.Create method.
type ProductFieldCreateOptions struct {
Name string `url:"name"`
FieldType FieldType `url:"field_type"`
Options string `url:"options"`
}
// Create a new product field.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ProductFields/post_productFields
func (s *ProductFieldsService) Create(ctx context.Context, opt *ProductFieldCreateOptions) (*ProductFieldResponse, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "/productFields", 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
}
// ProductFieldUpdateOptions specifices the optional parameters to the
// ProductFieldsService.Update method.
type ProductFieldUpdateOptions struct {
Name string `url:"name"`
Options string `url:"options"`
}
// Update a specific product field.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ProductFields/put_productFields_id
func (s *ProductFieldsService) Update(ctx context.Context, id int, opt *ProductFieldUpdateOptions) (*ProductFieldResponse, *Response, error) {
uri := fmt.Sprintf("/productFields/%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 marks multiple product fields as deleted.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ProductFields/delete_productFields
func (s *ProductFieldsService) DeleteMultiple(ctx context.Context, ids []int) (*Response, error) {
req, err := s.client.NewRequest(http.MethodDelete, "/productFields", &DeleteMultipleOptions{
Ids: arrayToString(ids, ","),
}, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Delete marks a specific product field as deleted.
//
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/ProductFields/delete_productFields_id
func (s *ProductFieldsService) Delete(ctx context.Context, id int) (*Response, error) {
uri := fmt.Sprintf("/productFields/%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)
}