Skip to content

Commit 0ddb739

Browse files
committed
Breakout HTTP methods into their own function
1 parent a1445ea commit 0ddb739

File tree

1 file changed

+62
-31
lines changed

1 file changed

+62
-31
lines changed

src/Client.php

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function importLeadsCsv($args)
117117
$args['format'] = 'csv';
118118
}
119119

120-
return json_decode($this->post('leads.json', $args)->getBody());
120+
return $this->_post('leads.json', $args);
121121

122122
}
123123

@@ -136,7 +136,7 @@ public function getBulkUploadStatus($batchId)
136136
throw new \Exception('Invalid $batchId provided in ' . __METHOD__);
137137
}
138138

139-
return json_decode($this->get(sprintf('leads/batch/%d.json', $batchId))->getBody());
139+
return $this->_get(sprintf('leads/batch/%d.json', $batchId));
140140
}
141141

142142
/**
@@ -154,7 +154,7 @@ public function getBulkUploadFailures($batchId)
154154
throw new \Exception('Invalid $batchId provided in ' . __METHOD__);
155155
}
156156

157-
return json_decode($this->get(sprintf('leads/batch/%d/failures.json', $batchId))->getBody());
157+
return $this->_get(sprintf('leads/batch/%d/failures.json', $batchId));
158158
}
159159

160160
/**
@@ -172,7 +172,7 @@ public function getBulkUploadWarnings($batchId)
172172
throw new \Exception('Invalid $batchId provided in ' . __METHOD__);
173173
}
174174

175-
return json_decode($this->get(sprintf('leads/batch/%d/warnings.json', $batchId))->getBody());
175+
return $this->_get(sprintf('leads/batch/%d/warnings.json', $batchId));
176176
}
177177

178178
/**
@@ -202,7 +202,7 @@ private function createOrUpdateLeadsCommand($action, $leads, $lookupField, $args
202202
}
203203

204204
return new CreateOrUpdateLeadsResponse(
205-
json_decode($this->get('leads.json', $args)->getBody())
205+
$this->_post('leads.json', $args)
206206
);
207207
}
208208

@@ -291,7 +291,7 @@ public function getLists($ids = null, $args = array())
291291
}
292292

293293
return new GetListsResponse(
294-
json_decode($this->get('lists.json', $args)->getBody())
294+
$this->_get('lists.json', $args)
295295
);
296296
}
297297

@@ -310,7 +310,7 @@ public function getList($id, $args = array())
310310
$args['id'] = $id;
311311

312312
return new GetListResponse(
313-
json_decode($this->get(sprintf('lists/%d.json', $id), $args)->getBody())
313+
$this->_get(sprintf('lists/%d.json', $id))
314314
);
315315
}
316316

@@ -339,7 +339,7 @@ public function getLeadsByFilterType($filterType, $filterValues, $fields = array
339339
}
340340

341341
return new GetLeadsResponse(
342-
json_decode($this->get('leads.json', $args)->getBody())
342+
$this->_get('leads.json', $args)
343343
);
344344
}
345345

@@ -367,7 +367,7 @@ public function getLeadByFilterType($filterType, $filterValue, $fields = array()
367367
}
368368

369369
return new GetLeadResponse(
370-
json_decode($this->get('leads.json', $args)->getBody())
370+
$this->_get('leads.json', $args)
371371
);
372372
}
373373

@@ -381,7 +381,7 @@ public function getLeadByFilterType($filterType, $filterValue, $fields = array()
381381
public function getLeadPartitions($args = array())
382382
{
383383
return new GetLeadPartitionsResponse(
384-
json_decode($this->get('leads/partitions.json', $args)->getBody())
384+
$this->_get('leads/partitions.json', $args)
385385
);
386386
}
387387

@@ -400,7 +400,7 @@ public function getLeadsByList($listId, $args = array())
400400
$args['listId'] = $listId;
401401

402402
return new GetLeadsResponse(
403-
json_decode($this->get(sprintf('list/%d/leads.json', $listId), $args)->getBody())
403+
$this->_get(sprintf('list/%d/leads.json', $listId))
404404
);
405405
}
406406

@@ -424,7 +424,7 @@ public function getLead($id, $fields = null, $args = array())
424424
}
425425

426426
return new GetLeadResponse(
427-
json_decode($this->get(sprintf('lead/%d.json', $id), $args)->getBody())
427+
$this->_get(sprintf('lead/%d.json', $id), $args)
428428
);
429429
}
430430

@@ -445,7 +445,7 @@ public function isMemberOfList($listId, $id, $args = array(), $returnRaw = false
445445
$args['id'] = $id;
446446

447447
return new IsMemberOfListResponse(
448-
json_decode($this->get(sprintf('lists/%d/leads/ismember.json', $listId), $args)->getBody())
448+
$this->_get(sprintf('lists/%d/leads/ismember.json', $listId), $args)
449449
);
450450
}
451451

@@ -464,7 +464,7 @@ public function getCampaign($id, $args = array())
464464
$args['id'] = $id;
465465

466466
return new GetCampaignResponse(
467-
json_decode($this->get(sprintf('campaigns/%d.json', $id), $args)->getBody())
467+
$this->_get(sprintf('campaigns/%d.json', $id), $args)
468468
);
469469
}
470470

@@ -485,7 +485,7 @@ public function getCampaigns($ids = null, $args = array())
485485
}
486486

487487
return new GetCampaignsResponse(
488-
json_decode($this->get('campaigns.json', $args)->getBody())
488+
$this->_get('campaigns.json', $args)
489489
);
490490
}
491491

@@ -506,7 +506,7 @@ public function addLeadsToList($listId, $leads, $args = array(), $returnRaw = fa
506506
$args['id'] = (array) $leads;
507507

508508
return new AddOrRemoveLeadsToListResponse(
509-
json_decode($this->get(sprintf('lists/%d/leads.json', $listId), $args)->getBody())
509+
$this->_get(sprintf('lists/%d/leads.json', $listId), $args)
510510
);
511511
}
512512

@@ -527,7 +527,7 @@ public function removeLeadsFromList($listId, $leads, $args = array(), $returnRaw
527527
$args['id'] = (array) $leads;
528528

529529
return new AddOrRemoveLeadsToListResponse(
530-
json_decode($this->delete(sprintf('lists/%d/leads.json', $listId), $args)->getBody())
530+
$this->_delete(sprintf('lists/%d/leads.json', $listId), $args)
531531
);
532532
}
533533

@@ -545,9 +545,7 @@ public function deleteLead($leads, $args = array(), $returnRaw = false)
545545
{
546546
$args['id'] = (array) $leads;
547547

548-
return new DeleteLeadResponse(
549-
json_decode($this->delete('leads.json', $args)->getBody())
550-
);
548+
return new DeleteLeadResponse($this->_delete('leads.json', $args));
551549
}
552550

553551
/**
@@ -575,7 +573,7 @@ public function requestCampaign($id, $leads, $tokens = array(), $args = array(),
575573
}
576574

577575
return new RequestCampaignResponse(
578-
json_decode($this->post(sprintf('campaigns/%d/trigger.json', $id), $args)->getBody())
576+
$this->_post(sprintf('campaigns/%d/trigger.json', $id), $args)
579577
);
580578
}
581579

@@ -604,7 +602,7 @@ public function scheduleCampaign($id, \DateTime $runAt = NULL, $tokens = array()
604602
}
605603

606604
return new ScheduleCampaignResponse(
607-
json_decode($this->post(sprintf('campaigns/%d/schedule.json', $id), $args)->getBody())
605+
$this->_post(sprintf('campaigns/%d/schedule.json', $id), $args)
608606
);
609607
}
610608

@@ -628,7 +626,7 @@ public function associateLead($id, $cookie = null, $args = array(), $returnRaw =
628626
}
629627

630628
return new AssociateLeadResponse(
631-
json_decode($this->post(sprintf('leads/%d/associate.json', $id), $args)->getBody())
629+
$this->_post(sprintf('leads/%d/associate.json', $id), $args)
632630
);
633631
}
634632

@@ -648,7 +646,7 @@ public function getPagingToken($sinceDatetime, $args = array(), $returnRaw = fal
648646
$args['sinceDatetime'] = $sinceDatetime;
649647

650648
return new AssociateLeadResponse(
651-
json_decode($this->post('activities/pagingtoken.json', $args)->getBody())
649+
$this->_post('activities/pagingtoken.json', $args)
652650
);
653651
}
654652

@@ -675,7 +673,7 @@ public function getLeadChanges($nextPageToken, $fields, $args = array(), $return
675673
}
676674

677675
return new GetLeadChanges(
678-
json_decode($this->post('activities/leadchanges.json', $args)->getBody())
676+
$this->_post('activities/leadchanges.json', $args)
679677
);
680678
}
681679

@@ -690,12 +688,12 @@ public function getLeadChanges($nextPageToken, $fields, $args = array(), $return
690688
*
691689
* @return Response
692690
*/
693-
public function updateEmailContent($emailId, $args = array(), $returnRaw = false)
691+
public function updateEmailContent($emailId, $args = array())
694692
{
695693
$args['id'] = $emailId;
696694

697695
return new Response(
698-
json_decode($this->post(sprintf('rest/asset/v1/email/%d/content.json', $emailId), $args)->getBody())
696+
$this->_post(sprintf('rest/asset/v1/email/%d/content.json', $emailId), $args)
699697
);
700698
}
701699

@@ -710,13 +708,13 @@ public function updateEmailContent($emailId, $args = array(), $returnRaw = false
710708
*
711709
* @return UpdateEmailContentInEditableSectionResponse
712710
*/
713-
public function updateEmailContentInEditableSection($emailId, $htmlId, $args = array(), $returnRaw = false)
711+
public function updateEmailContentInEditableSection($emailId, $htmlId, $args = array())
714712
{
715713
$args['id'] = $emailId;
716714
$args['htmlId'] = $htmlId;
717715

718716
return new UpdateEmailContentInEditableSectionResponse(
719-
json_decode($this->post(sprintf('rest/asset/v1/email/%d/content/{htmlId}.json', $emailId), $args)->getBody())
717+
$this->_post(sprintf('rest/asset/v1/email/%d/content/{htmlId}.json', $emailId), $args)
720718
);
721719
}
722720

@@ -731,12 +729,45 @@ public function updateEmailContentInEditableSection($emailId, $htmlId, $args = a
731729
*
732730
* @return ApproveEmailResponse
733731
*/
734-
public function approveEmail($emailId, $args = array(), $returnRaw = false)
732+
public function approveEmail($emailId, $args = array())
735733
{
736734
$args['id'] = $emailId;
737735

738736
return new ApproveEmailResponse(
739-
json_decode($this->post(sprintf('rest/asset/v1/email/%d/approveDraft.json', $emailId), $args)->getBody())
737+
$this->_post(sprintf('rest/asset/v1/email/%d/approveDraft.json', $emailId), $args)
740738
);
741739
}
740+
741+
/**
742+
* Perform a POST request and JSON decode the response
743+
*
744+
* @param string $url
745+
* @param array $args
746+
* @return array
747+
*/
748+
private function _post(string $url, array $args = []) : array {
749+
return json_decode($this->post($url, $args)->getBody());
750+
}
751+
752+
/**
753+
* Perform a GET request and JSON decode the response
754+
*
755+
* @param string $url
756+
* @param array $args
757+
* @return array
758+
*/
759+
private function _get(string $url, array $args = []) : array {
760+
return json_decode($this->get($url, $args)->getBody());
761+
}
762+
763+
/**
764+
* Perform a DELETE request and JSON decode the response
765+
*
766+
* @param string $url
767+
* @param array $args
768+
* @return array
769+
*/
770+
private function _delete(string $url, array $args = []) : array {
771+
return json_decode($this->delete($url, $args)->getBody());
772+
}
742773
}

0 commit comments

Comments
 (0)