From 49cd2a740511af95a9ddb48888fa6b2a99734939 Mon Sep 17 00:00:00 2001 From: Sergii Kauk Date: Mon, 27 Aug 2012 01:19:00 +0300 Subject: [PATCH 1/2] Added moveSubscriptionToList, a fix for PUT calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new method added moveSubscriptionToList that moves a contact between lists. Also, to make it work a fix was added to makeCall to handle json PUT calls correctly. --- lib/iContactApi.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/iContactApi.php b/lib/iContactApi.php index a901d98..0f57ea1 100644 --- a/lib/iContactApi.php +++ b/lib/iContactApi.php @@ -405,7 +405,9 @@ public function makeCall($sResource, $sMethod = 'GET', $mPostData = null, $sRetu } elseif (!is_string($mPostData) || !file_exists($mPostData)) { // Not a file, so we assume this is just data curl_setopt($rHandle, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($rHandle, CURLOPT_POSTFIELDS, $mPostData); + curl_setopt($rHandle, CURLOPT_POSTFIELDS, json_encode($mPostData)); + // Set the request JSON + $this->sLastRequest = (string) json_encode($mPostData); } else { $rFileContentHandle = fopen($mPostData, 'r'); if ($rFileContentHandle === false) { @@ -528,6 +530,30 @@ public function subscribeContactToList($iContactId, $iListId, $sStatus = 'normal return $aSubscriptions; } + /** + * This method moves a contact to another list + * @access public + * @param string $sSubscriptionId + * @param integer $iListId + * @param string $sStatus + * @return object + **/ + public function moveSubscriptionToList($sSubscriptionId, $iListId, $sStatus = 'normal') { + // Valid statuses + $aValidStatuses = array('normal', 'pending', 'unsubscribed'); + // Check for a valid status + if (!empty($sStatus) && !in_array($sStatus, $aValidStatuses)) { + $sStatus = 'normal'; + } + // Setup the subscription and make the call + $aSubscription = $this->makeCall("/a/{$this->setAccountId()}/c/{$this->setClientFolderId()}/subscriptions/{$sSubscriptionId}", 'PUT', array( + 'listId' => $iListId, + 'status' => $sStatus + ), 'subscription'); + // Return the subscription + return $aSubscription; + } + /** * This method updates a contact in your iContact account * @access public From 1b9ffd75806b399debe88600fa30c456c13bb1e2 Mon Sep 17 00:00:00 2001 From: Sergii Kauk Date: Mon, 27 Aug 2012 01:31:39 +0300 Subject: [PATCH 2/2] Example of moveSubscriptionToList --- examples.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples.php b/examples.php index f47b993..4914fa1 100644 --- a/examples.php +++ b/examples.php @@ -29,6 +29,8 @@ var_dump($oiContact->addList('somelist', 1698, true, false, false, 'Just an example list', 'Some List')); // Subscribe contact to list var_dump($oiContact->subscribeContactToList(42094396, 179962, 'normal')); + // Move contact to another list + var_dump($oiContact->moveSubscriptionToList("179962_42094396", 179963, 'normal')); // Grab all campaigns var_dump($oiContact->getCampaigns()); // Create message