Skip to content

Commit c56d2d0

Browse files
committed
Add GetPerson API call, add 'label' structure field, add CreateOrg API call, add some custom fields
1 parent 05c5363 commit c56d2d0

File tree

5 files changed

+167
-28
lines changed

5 files changed

+167
-28
lines changed

pipedrive/activities.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ func (s *ActivitiesService) Create(ctx context.Context, opt *ActivitiesCreateOpt
137137
// ActivitiesCreateOptions specifices the optional parameters to the
138138
// ActivitiesService.Update method.
139139
type ActivitiesCreateOptions struct {
140-
Subject string `url:"subject,omitempty"`
141-
Done uint8 `url:"done,omitempty"`
142-
Type string `url:"type,omitempty"`
143-
DueDate string `url:"due_date,omitempty"`
144-
DueTime string `url:"due_time,omitempty"`
145-
Duration string `url:"duration,omitempty"`
146-
UserID uint `url:"user_id,omitempty"`
147-
DealID uint `url:"user_id,omitempty"`
148-
PersonID uint `url:"person_id,omitempty"`
149-
Participants interface{} `url:"participants,omitempty"`
150-
OrgID uint `url:"org_id,omitempty"`
140+
Subject string `json:"subject,omitempty"`
141+
Done uint8 `json:"done,omitempty"`
142+
Type string `json:"type,omitempty"`
143+
DueDate string `json:"due_date,omitempty"`
144+
DueTime string `json:"due_time,omitempty"`
145+
Duration string `json:"duration,omitempty"`
146+
UserID uint `json:"user_id,omitempty"`
147+
DealID uint `json:"user_id,omitempty"`
148+
PersonID uint `json:"person_id,omitempty"`
149+
Participants interface{} `json:"participants,omitempty"`
150+
OrgID uint `json:"org_id,omitempty"`
151151
}
152152

153153
// Update an activity

pipedrive/deals.go

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,17 @@ func (s *DealService) Merge(ctx context.Context, id int, opt *DealsMergeOptions)
236236
// DealsUpdateOptions specifices the optional parameters to the
237237
// DealService.Update method.
238238
type DealsUpdateOptions struct {
239-
Title string `url:"title,omitempty"`
240-
Value string `url:"value,omitempty"`
241-
Currency string `url:"currency,omitempty"`
242-
UserID uint `url:"user_id,omitempty"`
243-
PersonID uint `url:"person_id,omitempty"`
244-
OrganizationID uint `url:"org_id,omitempty"`
245-
StageID uint `url:"stage_id,omitempty"`
246-
Status string `url:"status,omitempty"`
247-
LostReason string `url:"lost_reason,omitempty"`
248-
VisibleTo uint `url:"visible_to,omitempty"`
239+
Title string `json:"title,omitempty"`
240+
Value string `json:"value,omitempty"`
241+
Currency string `json:"currency,omitempty"`
242+
UserID uint `json:"user_id,omitempty"`
243+
PersonID uint `json:"person_id,omitempty"`
244+
OrganizationID uint `json:"org_id,omitempty"`
245+
StageID uint `json:"stage_id,omitempty"`
246+
Status string `json:"status,omitempty"`
247+
LostReason string `json:"lost_reason,omitempty"`
248+
VisibleTo uint `json:"visible_to,omitempty"`
249+
RequirementAnalysis string `json:"56d3d40c37c0db60fff576ae73ba2fea0d58dc09"`
249250
}
250251

251252
// Update a deal.
@@ -331,3 +332,73 @@ func (s *DealService) DeleteAttachedProduct(ctx context.Context, dealID int, pro
331332

332333
return s.client.Do(ctx, req, nil)
333334
}
335+
336+
// DealCreateOptions specifices the optional parameters to the
337+
// DealsService.Create method.
338+
type DealCreateOptions struct {
339+
Title string `json:"title"`
340+
Value string `json:"value"`
341+
Currency string `json:"currency"`
342+
UserID uint `json:"user_id"`
343+
PersonID uint `json:"person_id"`
344+
OrgID uint `json:"org_id"`
345+
StageID uint `json:"stage_id"`
346+
Status string `json:"status"`
347+
Probability uint `json:"probability"`
348+
LostReason string `json:"lost_reason"`
349+
AddTime Timestamp `json:"add_time"`
350+
VisibleTo VisibleTo `json:"visible_to"`
351+
RequirementAnalysis string `json:"56d3d40c37c0db60fff576ae73ba2fea0d58dc09"`
352+
WantedStartTime Timestamp `json:"a3114acce61bb930180af173b395d76f42af8794"`
353+
}
354+
355+
// Create a new deal.
356+
//
357+
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Deals/post_deals
358+
func (s *DealService) Create(ctx context.Context, opt *DealCreateOptions) (*DealResponse, *Response, error) {
359+
req, err := s.client.NewRequest(http.MethodPost, "/deals", nil, struct {
360+
Title string `json:"title"`
361+
Value string `json:"value"`
362+
Currency string `json:"currency"`
363+
UserID uint `json:"user_id"`
364+
PersonID uint `json:"person_id"`
365+
OrgID uint `json:"org_id"`
366+
StageID uint `json:"stage_id"`
367+
Status string `json:"status"`
368+
Probability uint `json:"probability"`
369+
LostReason string `json:"lost_reason"`
370+
AddTime string `json:"add_time"`
371+
VisibleTo VisibleTo `json:"visible_to"`
372+
RequirementAnalysis string `json:"56d3d40c37c0db60fff576ae73ba2fea0d58dc09"`
373+
WantedStartTime string `json:"a3114acce61bb930180af173b395d76f42af8794"`
374+
}{
375+
opt.Title,
376+
opt.Value,
377+
opt.Currency,
378+
opt.UserID,
379+
opt.PersonID,
380+
opt.OrgID,
381+
opt.StageID,
382+
opt.Status,
383+
opt.Probability,
384+
opt.LostReason,
385+
opt.AddTime.FormatFull(),
386+
opt.VisibleTo,
387+
opt.RequirementAnalysis,
388+
opt.WantedStartTime.FormatFull(),
389+
})
390+
391+
if err != nil {
392+
return nil, nil, err
393+
}
394+
395+
var record *DealResponse
396+
397+
resp, err := s.client.Do(ctx, req, &record)
398+
399+
if err != nil {
400+
return nil, resp, err
401+
}
402+
403+
return record, resp, nil
404+
}

pipedrive/notes.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ func (s *NotesService) GetByID(ctx context.Context, id int) (*NoteResponse, *Res
9292
// NoteCreateOptions specifices the optional parameters to the
9393
// NotesService.Create method.
9494
type NoteCreateOptions struct {
95-
DealID uint `url:"deal_id"`
96-
Content string `url:"content"`
97-
PersonID uint `url:"person_id"`
98-
OrgID uint `url:"org_id"`
99-
PinnedToDealFlag uint8 `url:"pinned_to_deal_flag"`
100-
PinnedToOrganizationFlag uint8 `url:"pinned_to_organization_flag"`
101-
PinnedToPersonFlag uint8 `url:"pinned_to_person_flag"`
95+
DealID uint `json:"deal_id"`
96+
Content string `json:"content"`
97+
PersonID uint `json:"person_id"`
98+
OrgID uint `json:"org_id"`
99+
PinnedToDealFlag uint8 `json:"pinned_to_deal_flag"`
100+
PinnedToOrganizationFlag uint8 `json:"pinned_to_organization_flag"`
101+
PinnedToPersonFlag uint8 `json:"pinned_to_person_flag"`
102102
}
103103

104104
// Create a note.

pipedrive/organizations.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,46 @@ func (s *OrganizationsService) DeleteMultiple(ctx context.Context, ids []int) (*
180180

181181
return s.client.Do(ctx, req, nil)
182182
}
183+
184+
// OrganizationCreateOptions specifices the optional parameters to the
185+
// OrganizationsService.Create method.
186+
type OrganizationCreateOptions struct {
187+
Name string `json:"name"`
188+
OwnerID uint `json:"owner_id"`
189+
VisibleTo VisibleTo `json:"visible_to"`
190+
AddTime Timestamp `json:"add_time"`
191+
Label uint `json:"label"`
192+
}
193+
194+
// Create a new organizations.
195+
//
196+
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Organizations/post_organizations
197+
func (s *OrganizationsService) Create(ctx context.Context, opt *OrganizationCreateOptions) (*OrganizationResponse, *Response, error) {
198+
req, err := s.client.NewRequest(http.MethodPost, "/organizations", nil, struct {
199+
Name string `json:"name"`
200+
OwnerID uint `json:"owner_id"`
201+
Label uint `json:"label"`
202+
VisibleTo VisibleTo `json:"visible_to"`
203+
AddTime string `json:"add_time"`
204+
}{
205+
opt.Name,
206+
opt.OwnerID,
207+
opt.Label,
208+
opt.VisibleTo,
209+
opt.AddTime.FormatFull(),
210+
})
211+
212+
if err != nil {
213+
return nil, nil, err
214+
}
215+
216+
var record *OrganizationResponse
217+
218+
resp, err := s.client.Do(ctx, req, &record)
219+
220+
if err != nil {
221+
return nil, resp, err
222+
}
223+
224+
return record, resp, nil
225+
}

pipedrive/persons.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type Person struct {
7373
OrgName interface{} `json:"org_name"`
7474
OwnerName string `json:"owner_name"`
7575
CcEmail string `json:"cc_email"`
76+
Label uint `json:"label"`
7677
}
7778

7879
func (p Person) String() string {
@@ -161,6 +162,7 @@ type PersonCreateOptions struct {
161162
Phone string `json:"phone"`
162163
VisibleTo VisibleTo `json:"visible_to"`
163164
AddTime Timestamp `json:"add_time"`
165+
Label uint `json:"label"`
164166
}
165167

166168
// Create a new person.
@@ -173,6 +175,7 @@ func (s *PersonsService) Create(ctx context.Context, opt *PersonCreateOptions) (
173175
OrgID uint `json:"org_id"`
174176
Email string `json:"email"`
175177
Phone string `json:"phone"`
178+
Label uint `json:"label"`
176179
VisibleTo VisibleTo `json:"visible_to"`
177180
AddTime string `json:"add_time"`
178181
}{
@@ -181,6 +184,7 @@ func (s *PersonsService) Create(ctx context.Context, opt *PersonCreateOptions) (
181184
opt.OrgID,
182185
opt.Email,
183186
opt.Phone,
187+
opt.Label,
184188
opt.VisibleTo,
185189
opt.AddTime.FormatFull(),
186190
})
@@ -315,3 +319,24 @@ func (s *PersonsService) DeleteMultiple(ctx context.Context, ids []int) (*Respon
315319

316320
return s.client.Do(ctx, req, nil)
317321
}
322+
323+
// Get a person.
324+
//
325+
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Persons/get_persons_id
326+
func (s *PersonsService) Get(ctx context.Context, personID int) (*PersonResponse, *Response, error) {
327+
req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("/persons/%d", personID), nil, nil)
328+
329+
if err != nil {
330+
return nil, nil, err
331+
}
332+
333+
var record *PersonResponse
334+
335+
resp, err := s.client.Do(ctx, req, &record)
336+
337+
if err != nil {
338+
return nil, resp, err
339+
}
340+
341+
return record, resp, nil
342+
}

0 commit comments

Comments
 (0)