@@ -117,7 +117,7 @@ public function importLeadsCsv($args)
117
117
$ args ['format ' ] = 'csv ' ;
118
118
}
119
119
120
- return json_decode ( $ this ->post ('leads.json ' , $ args)-> getBody () );
120
+ return $ this ->_post ('leads.json ' , $ args );
121
121
122
122
}
123
123
@@ -136,7 +136,7 @@ public function getBulkUploadStatus($batchId)
136
136
throw new \Exception ('Invalid $batchId provided in ' . __METHOD__ );
137
137
}
138
138
139
- return json_decode ( $ this ->get (sprintf ('leads/batch/%d.json ' , $ batchId))-> getBody ( ));
139
+ return $ this ->_get (sprintf ('leads/batch/%d.json ' , $ batchId ));
140
140
}
141
141
142
142
/**
@@ -154,7 +154,7 @@ public function getBulkUploadFailures($batchId)
154
154
throw new \Exception ('Invalid $batchId provided in ' . __METHOD__ );
155
155
}
156
156
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 ));
158
158
}
159
159
160
160
/**
@@ -172,7 +172,7 @@ public function getBulkUploadWarnings($batchId)
172
172
throw new \Exception ('Invalid $batchId provided in ' . __METHOD__ );
173
173
}
174
174
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 ));
176
176
}
177
177
178
178
/**
@@ -202,7 +202,7 @@ private function createOrUpdateLeadsCommand($action, $leads, $lookupField, $args
202
202
}
203
203
204
204
return new CreateOrUpdateLeadsResponse (
205
- json_decode ( $ this ->get ('leads.json ' , $ args)-> getBody () )
205
+ $ this ->_post ('leads.json ' , $ args )
206
206
);
207
207
}
208
208
@@ -291,7 +291,7 @@ public function getLists($ids = null, $args = array())
291
291
}
292
292
293
293
return new GetListsResponse (
294
- json_decode ( $ this ->get ('lists.json ' , $ args)-> getBody () )
294
+ $ this ->_get ('lists.json ' , $ args )
295
295
);
296
296
}
297
297
@@ -310,7 +310,7 @@ public function getList($id, $args = array())
310
310
$ args ['id ' ] = $ id ;
311
311
312
312
return new GetListResponse (
313
- json_decode ( $ this ->get (sprintf ('lists/%d.json ' , $ id), $ args )-> getBody ( ))
313
+ $ this ->_get (sprintf ('lists/%d.json ' , $ id ))
314
314
);
315
315
}
316
316
@@ -339,7 +339,7 @@ public function getLeadsByFilterType($filterType, $filterValues, $fields = array
339
339
}
340
340
341
341
return new GetLeadsResponse (
342
- json_decode ( $ this ->get ('leads.json ' , $ args)-> getBody () )
342
+ $ this ->_get ('leads.json ' , $ args )
343
343
);
344
344
}
345
345
@@ -367,7 +367,7 @@ public function getLeadByFilterType($filterType, $filterValue, $fields = array()
367
367
}
368
368
369
369
return new GetLeadResponse (
370
- json_decode ( $ this ->get ('leads.json ' , $ args)-> getBody () )
370
+ $ this ->_get ('leads.json ' , $ args )
371
371
);
372
372
}
373
373
@@ -381,7 +381,7 @@ public function getLeadByFilterType($filterType, $filterValue, $fields = array()
381
381
public function getLeadPartitions ($ args = array ())
382
382
{
383
383
return new GetLeadPartitionsResponse (
384
- json_decode ( $ this ->get ('leads/partitions.json ' , $ args)-> getBody () )
384
+ $ this ->_get ('leads/partitions.json ' , $ args )
385
385
);
386
386
}
387
387
@@ -400,7 +400,7 @@ public function getLeadsByList($listId, $args = array())
400
400
$ args ['listId ' ] = $ listId ;
401
401
402
402
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 ))
404
404
);
405
405
}
406
406
@@ -424,7 +424,7 @@ public function getLead($id, $fields = null, $args = array())
424
424
}
425
425
426
426
return new GetLeadResponse (
427
- json_decode ( $ this ->get (sprintf ('lead/%d.json ' , $ id ), $ args)-> getBody () )
427
+ $ this ->_get (sprintf ('lead/%d.json ' , $ id ), $ args )
428
428
);
429
429
}
430
430
@@ -445,7 +445,7 @@ public function isMemberOfList($listId, $id, $args = array(), $returnRaw = false
445
445
$ args ['id ' ] = $ id ;
446
446
447
447
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 )
449
449
);
450
450
}
451
451
@@ -464,7 +464,7 @@ public function getCampaign($id, $args = array())
464
464
$ args ['id ' ] = $ id ;
465
465
466
466
return new GetCampaignResponse (
467
- json_decode ( $ this ->get (sprintf ('campaigns/%d.json ' , $ id ), $ args)-> getBody () )
467
+ $ this ->_get (sprintf ('campaigns/%d.json ' , $ id ), $ args )
468
468
);
469
469
}
470
470
@@ -485,7 +485,7 @@ public function getCampaigns($ids = null, $args = array())
485
485
}
486
486
487
487
return new GetCampaignsResponse (
488
- json_decode ( $ this ->get ('campaigns.json ' , $ args)-> getBody () )
488
+ $ this ->_get ('campaigns.json ' , $ args )
489
489
);
490
490
}
491
491
@@ -506,7 +506,7 @@ public function addLeadsToList($listId, $leads, $args = array(), $returnRaw = fa
506
506
$ args ['id ' ] = (array ) $ leads ;
507
507
508
508
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 )
510
510
);
511
511
}
512
512
@@ -527,7 +527,7 @@ public function removeLeadsFromList($listId, $leads, $args = array(), $returnRaw
527
527
$ args ['id ' ] = (array ) $ leads ;
528
528
529
529
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 )
531
531
);
532
532
}
533
533
@@ -545,9 +545,7 @@ public function deleteLead($leads, $args = array(), $returnRaw = false)
545
545
{
546
546
$ args ['id ' ] = (array ) $ leads ;
547
547
548
- return new DeleteLeadResponse (
549
- json_decode ($ this ->delete ('leads.json ' , $ args )->getBody ())
550
- );
548
+ return new DeleteLeadResponse ($ this ->_delete ('leads.json ' , $ args ));
551
549
}
552
550
553
551
/**
@@ -575,7 +573,7 @@ public function requestCampaign($id, $leads, $tokens = array(), $args = array(),
575
573
}
576
574
577
575
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 )
579
577
);
580
578
}
581
579
@@ -604,7 +602,7 @@ public function scheduleCampaign($id, \DateTime $runAt = NULL, $tokens = array()
604
602
}
605
603
606
604
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 )
608
606
);
609
607
}
610
608
@@ -628,7 +626,7 @@ public function associateLead($id, $cookie = null, $args = array(), $returnRaw =
628
626
}
629
627
630
628
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 )
632
630
);
633
631
}
634
632
@@ -648,7 +646,7 @@ public function getPagingToken($sinceDatetime, $args = array(), $returnRaw = fal
648
646
$ args ['sinceDatetime ' ] = $ sinceDatetime ;
649
647
650
648
return new AssociateLeadResponse (
651
- json_decode ( $ this ->post ('activities/pagingtoken.json ' , $ args)-> getBody () )
649
+ $ this ->_post ('activities/pagingtoken.json ' , $ args )
652
650
);
653
651
}
654
652
@@ -675,7 +673,7 @@ public function getLeadChanges($nextPageToken, $fields, $args = array(), $return
675
673
}
676
674
677
675
return new GetLeadChanges (
678
- json_decode ( $ this ->post ('activities/leadchanges.json ' , $ args)-> getBody () )
676
+ $ this ->_post ('activities/leadchanges.json ' , $ args )
679
677
);
680
678
}
681
679
@@ -690,12 +688,12 @@ public function getLeadChanges($nextPageToken, $fields, $args = array(), $return
690
688
*
691
689
* @return Response
692
690
*/
693
- public function updateEmailContent ($ emailId , $ args = array (), $ returnRaw = false )
691
+ public function updateEmailContent ($ emailId , $ args = array ())
694
692
{
695
693
$ args ['id ' ] = $ emailId ;
696
694
697
695
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 )
699
697
);
700
698
}
701
699
@@ -710,13 +708,13 @@ public function updateEmailContent($emailId, $args = array(), $returnRaw = false
710
708
*
711
709
* @return UpdateEmailContentInEditableSectionResponse
712
710
*/
713
- public function updateEmailContentInEditableSection ($ emailId , $ htmlId , $ args = array (), $ returnRaw = false )
711
+ public function updateEmailContentInEditableSection ($ emailId , $ htmlId , $ args = array ())
714
712
{
715
713
$ args ['id ' ] = $ emailId ;
716
714
$ args ['htmlId ' ] = $ htmlId ;
717
715
718
716
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 )
720
718
);
721
719
}
722
720
@@ -731,12 +729,45 @@ public function updateEmailContentInEditableSection($emailId, $htmlId, $args = a
731
729
*
732
730
* @return ApproveEmailResponse
733
731
*/
734
- public function approveEmail ($ emailId , $ args = array (), $ returnRaw = false )
732
+ public function approveEmail ($ emailId , $ args = array ())
735
733
{
736
734
$ args ['id ' ] = $ emailId ;
737
735
738
736
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 )
740
738
);
741
739
}
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
+ }
742
773
}
0 commit comments