diff --git a/src/Mailchimp.php b/src/Mailchimp.php index e709683..512fd51 100644 --- a/src/Mailchimp.php +++ b/src/Mailchimp.php @@ -299,6 +299,7 @@ public function request($method, $path, $tokens = NULL, $parameters = NULL, $bat 'headers' => [ 'Authorization' => $this->api_user . ' ' . $this->api_key, ], + 'convert_to_object' => TRUE ]; // Add trigger error header if a debug error code has been set. @@ -306,6 +307,14 @@ public function request($method, $path, $tokens = NULL, $parameters = NULL, $bat $options['headers']['X-Trigger-Error'] = $this->debug_error_code; } + // Set the object conversion status if its passed in. + if (isset($parameters['convert_to_object'])) { + $options['convert_to_object'] = $parameters['convert_to_object']; + + // Remove status from being sent to MailChimp. + unset($parameters['convert_to_object']); + } + if ($this->use_curl) { return $this->handleRequestCURL($method, $this->endpoint . $path, $options, $parameters, $returnAssoc); } @@ -327,7 +336,12 @@ public function handleRequest($method, $uri = '', $options = [], $parameters = [ } else { // Send parameters as JSON in request body. - $options['json'] = (object) $parameters; + if ($options['convert_to_object']) { + $options['json'] = (object) $parameters; + } + else { + $options['json'] = $parameters; + } } } diff --git a/src/MailchimpLists.php b/src/MailchimpLists.php index 349f42b..0561910 100644 --- a/src/MailchimpLists.php +++ b/src/MailchimpLists.php @@ -387,8 +387,6 @@ public function addSegment($list_id, $name, $parameters = [], $batch = FALSE) { * The ID of the list. * @param int $segment_id * The ID of the segment. - * @param string $name - * The name of the segment. * @param array $parameters * Associative array of optional request parameters. * @param bool $batch @@ -398,17 +396,17 @@ public function addSegment($list_id, $name, $parameters = [], $batch = FALSE) { * * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/segments/#edit-patch_lists_list_id_segments_segment_id */ - public function updateSegment($list_id, $segment_id, $name, $parameters = [], $batch = FALSE) { + public function updateSegment($list_id, $segment_id, $parameters = [], $batch = FALSE) { $tokens = [ 'list_id' => $list_id, 'segment_id' => $segment_id, ]; $parameters += [ - 'name' => $name, + 'convert_to_object' => FALSE ]; - return $this->request('PATCH', '/lists/{list_id}/segments/{segment_id}', $tokens, $parameters, $batch); + return $this->request('POST', '/lists/{list_id}/segments/{segment_id}', $tokens, $parameters, $batch); } /** diff --git a/tests/MailchimpListsTest.php b/tests/MailchimpListsTest.php index 6a83863..75773bf 100644 --- a/tests/MailchimpListsTest.php +++ b/tests/MailchimpListsTest.php @@ -249,19 +249,23 @@ public function testAddSegment() { public function testUpdateSegment() { $list_id = '57afe96172'; $segment_id = '49381'; - $name = 'Updated Test Segment'; + $emails = array( + 'members_to_add' => array( + 'new-employee@mailchimp.com' + ) + ); $mc = new MailchimpLists(); - $mc->updateSegment($list_id, $segment_id, $name); + $mc->updateSegment($list_id, $segment_id, $emails); - $this->assertEquals('PATCH', $mc->getClient()->method); + $this->assertEquals('POST', $mc->getClient()->method); $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/segments/' . $segment_id, $mc->getClient()->uri); $this->assertNotEmpty($mc->getClient()->options['json']); $request_body = $mc->getClient()->options['json']; - $this->assertEquals($name, $request_body->name); + $this->assertEquals('new-employee@mailchimp.com', $request_body['members_to_add'][0]); } /**