diff --git a/.travis.yml b/.travis.yml index f04ab82..f3b6214 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php +sudo: required php: - - 5.3 - 5.4 script: phpunit --configuration build/phpunit.xml diff --git a/README.md b/README.md index 402b27b..3901a43 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,11 @@ subscriber information. Changelog: ---------- +2017-09-02: v1.1.18 + * Fixing issues on the formatting of nested objects on 'application/json' requests + * Fixing issue with extra data being sent in header. + * Fixing issue to allow the creation of custom fields to be sent as form encoded. + 2017-08-21: v1.1.17 * Fixing UTF-8 issues on creates diff --git a/aweber_api/aweber_collection.php b/aweber_api/aweber_collection.php index 26c0bc5..0ce6fed 100644 --- a/aweber_api/aweber_collection.php +++ b/aweber_api/aweber_collection.php @@ -116,7 +116,8 @@ protected function _type() { public function create($kv_pairs) { # Create Resource $params = array_merge(array('ws.op' => 'create'), $kv_pairs); - $data = $this->adapter->request('POST', $this->url, $params, array('return' => 'headers'), array('Content-Type: application/json')); + $headers = $this->_type() == 'custom_fields' ? array() : array('Content-Type: application/json'); + $data = $this->adapter->request('POST', $this->url, $params, array('return' => 'headers'), $headers); # Return new Resource $url = $data['Location']; diff --git a/aweber_api/oauth_application.php b/aweber_api/oauth_application.php index 4276a02..35891b6 100644 --- a/aweber_api/oauth_application.php +++ b/aweber_api/oauth_application.php @@ -65,7 +65,7 @@ class OAuthApplication implements AWeberOAuthAdapter { public $signatureMethod = 'HMAC-SHA1'; - public $clientVersion = '1.1.17'; + public $clientVersion = '1.1.18'; public $oAuthVersion = '1.0'; @@ -86,7 +86,8 @@ class OAuthApplication implements AWeberOAuthAdapter { * * Create a new OAuthApplication, based on an OAuthServiceProvider * @access public - * @return void + * @param bool $parentApp + * @throws Exception */ public function __construct($parentApp = false) { if ($parentApp) { @@ -116,14 +117,6 @@ public function request($method, $uri, $data = array(), $options = array(), $hea $uri = $this->app->removeBaseUri($uri); $url = $this->app->getBaseUri() . $uri; - # WARNING: non-primative items in data must be json serialized in GET and POST. - if ($method == 'POST' or $method == 'GET') { - foreach ($data as $key => $value) { - if (is_array($value)) { - $data[$key] = json_encode($value); - } - } - } $response = $this->makeRequest($method, $url, $data, $headers); if (!empty($options['return'])) { @@ -171,6 +164,7 @@ public function getRequestToken($callbackUrl=false) { * * @access public * @return void + * @throws AWeberOAuthDataMissing */ public function getAccessToken() { $resp = $this->makeRequest('POST', $this->app->getAccessTokenUrl(), @@ -212,10 +206,11 @@ public function parseAsError($response) { * Enforce that all the fields in requiredFields are present and not * empty in data. If a required field is empty, throw an exception. * - * @param mixed $data Array of data - * @param mixed $requiredFields Array of required field names. - * @access protected + * @param mixed $data Array of data + * @param mixed $requiredFields Array of required field names. * @return void + * @throws AWeberOAuthDataMissing + * @access protected */ protected function requiredFromResponse($data, $requiredFields) { foreach ($requiredFields as $field) { @@ -229,14 +224,14 @@ protected function requiredFromResponse($data, $requiredFields) { * get * * Make a get request. Used to exchange user tokens with serice provider. - * @param mixed $url URL to make a get request from. - * @param array $data Data for the request. - * @param mixed $headers Headers for the request + * @param mixed $url URL to make a get request from. + * @param String $url_params URL parameter string + * @param mixed $headers Headers for the request * @access protected * @return void */ - protected function get($url, $data, $headers) { - $url = $this->_addParametersToUrl($url, $data); + protected function get($url, $url_params, $headers = array()) { + $url = $this->_addParametersToUrl($url, $url_params); $handle = $this->curl->init($url); $resp = $this->_sendRequest($handle, $headers); return $resp; @@ -248,7 +243,7 @@ protected function get($url, $data, $headers) { * Adds the parameters in associative array $data to the * given URL * @param String $url URL - * @param array $data Parameters to be added as a query string to + * @param String $data Parameters to be added as a query string to * the URL provided * @access protected * @return void @@ -256,9 +251,9 @@ protected function get($url, $data, $headers) { protected function _addParametersToUrl($url, $data) { if (!empty($data)) { if (strpos($url, '?') === false) { - $url .= '?'.$this->buildData($data); + $url .= '?' . $data; } else { - $url .= '&'.$this->buildData($data); + $url .= '&' . $data; } } return $url; @@ -441,32 +436,34 @@ public function signRequest($method, $url, $data) { * @param mixed $method * @param mixed $url - Reserved characters in query params MUST be escaped * @param mixed $data - Reserved characters in values MUST NOT be escaped + * @param mixed $headers - Reserved characters in values MUST NOT be escaped * @access public * @return void + * + * @throws AWeberAPIException */ public function makeRequest($method, $url, $data=array(), $headers=array()) { if ($this->debug) echo "\n** {$method}: $url\n"; + list($urlParams, $requestBody) = $this->formatRequestData($method, $url, $data, $headers); + switch (strtoupper($method)) { case 'POST': - $oauth = $this->prepareRequest($method, $url, $data); - $resp = $this->post($url, $oauth, $data, $headers); + $resp = $this->post($url, $urlParams, $requestBody, $headers); break; case 'GET': - $oauth = $this->prepareRequest($method, $url, $data); - $resp = $this->get($url, $oauth, $data, $headers); + $resp = $this->get($url, $urlParams, $headers); break; case 'DELETE': - $oauth = $this->prepareRequest($method, $url, $data); - $resp = $this->delete($url, $oauth, $headers); + $resp = $this->delete($url, $urlParams, $headers); break; case 'PATCH': - $oauth = $this->prepareRequest($method, $url, array()); - $resp = $this->patch($url, $oauth, $data, $headers); + $headers = $this->_ensureContentType($headers, 'application/json'); + $resp = $this->patch($url, $urlParams, $requestBody, $headers); break; } @@ -495,21 +492,22 @@ public function makeRequest($method, $url, $data=array(), $headers=array()) { } /** - * put + * patch * - * Prepare an OAuth put method. + * Prepare an OAuth patch method. * - * @param mixed $url URL where we are making the request to - * @param mixed $data Data that is used to make the request - * @param mixed $headers Headers for the request + * @param mixed $url URL where we are making the request to + * @param mixed $url_params URL parameter string + * @param mixed $post_field Data that is used to make the request + * @param mixed $headers Headers for the request * @access protected * @return void */ - protected function patch($url, $oauth, $data, $headers) { - $url = $this->_addParametersToUrl($url, $oauth); + protected function patch($url, $url_params, $post_field, $headers = array()) { + $url = $this->_addParametersToUrl($url, $url_params); $handle = $this->curl->init($url); $this->curl->setopt($handle, CURLOPT_CUSTOMREQUEST, 'PATCH'); - $this->curl->setopt($handle, CURLOPT_POSTFIELDS, json_encode($data)); + $this->curl->setopt($handle, CURLOPT_POSTFIELDS, $post_field); $resp = $this->_sendRequest($handle, $headers); return $resp; } @@ -519,18 +517,18 @@ protected function patch($url, $oauth, $data, $headers) { * * Prepare an OAuth post method. * - * @param mixed $url URL where we are making the request to - * @param mixed $data Data that is used to make the request - * @param mixed $headers Headers for the request + * @param mixed $url URL where we are making the request to + * @param mixed $url_params URL parameter string + * @param mixed $post_field Data that is used to make the request + * @param mixed $headers Headers for the request * @access protected * @return void */ - protected function post($url, $oauth, $data, $headers = array()) { - $url = $this->_addParametersToUrl($url, $oauth); + protected function post($url, $url_params, $post_field, $headers = array()) { + $url = $this->_addParametersToUrl($url, $url_params); $handle = $this->curl->init($url); $this->curl->setopt($handle, CURLOPT_POST, true); - $postData = in_array("Content-Type: application/json", $headers) ? json_encode($data) : $this->buildData($data); - $this->curl->setopt($handle, CURLOPT_POSTFIELDS, $postData); + $this->curl->setopt($handle, CURLOPT_POSTFIELDS, $post_field); $resp = $this->_sendRequest($handle, $headers); return $resp; } @@ -540,13 +538,13 @@ protected function post($url, $oauth, $data, $headers = array()) { * * Makes a DELETE request * @param mixed $url URL where we are making the request to - * @param mixed $data Data that is used in the request + * @param mixed $url_params URL parameter string * @param mixed $headers Headers for the request * @access protected * @return void */ - protected function delete($url, $data, $headers = array()) { - $url = $this->_addParametersToUrl($url, $data); + protected function delete($url, $url_params, $headers = array()) { + $url = $this->_addParametersToUrl($url, $url_params); $handle = $this->curl->init($url); $this->curl->setopt($handle, CURLOPT_CUSTOMREQUEST, 'DELETE'); $resp = $this->_sendRequest($handle, $headers); @@ -649,6 +647,63 @@ protected function userAgent() { return $this->userAgentTitle . $this->clientVersion . ' PHP/' . PHP_VERSION . ' ' . php_uname('m') . '-' . strtolower(php_uname('s')) . '-'. php_uname('r'); } + /** + * @param $method + * @param $headers + * @return bool + * + * Return True if headers array does not contain 'Content-Type: application/json' and is a POST, GET, or DELETE request + */ + protected function needsUrlFormatting($method, $headers) { + return !in_array("Content-Type: application/json", $headers) && in_array($method, array('POST', 'GET', 'DELETE')); + } + + /** + * @param $method + * @param $url + * @param $data + * @param $headers + * @return array + */ + protected function formatRequestData($method, $url, $data, $headers) + { + # WARNING: If not being sent as json, non-primitive items in data must be json serialized in GET and POST. + if ($this->needsUrlFormatting($method, $headers)) { + foreach ($data as $key => $value) { + if (is_array($value)) { + $data[$key] = json_encode($value); + } + } + $urlParams = $this->buildData($this->prepareRequest($method, $url, $data)); + $requestBody = $this->buildData($data); + } else { + $urlParams = $this->buildData($this->prepareRequest($method, $url, array())); + $requestBody = json_encode($data); + } + return array($urlParams, $requestBody); + } + + /** + * Checks the $headers array for content-type and adds the header if it doesn't exist and replaces it if isn't + * what is passed. + * + * @param $headers + * @param $expectedContentType + * @return array + */ + private function _ensureContentType($headers, $expectedContentType) { + + foreach ($headers as $key => $value) { + if ( stripos($value, 'content-type:') !== false ) { + unset($headers[$key]); + } + + } + + $headers[] = 'Content-Type: ' . $expectedContentType; + return $headers; + } + } /** diff --git a/tests/AWeberCollectionTest.php b/tests/AWeberCollectionTest.php index 44ca90c..7263e7d 100644 --- a/tests/AWeberCollectionTest.php +++ b/tests/AWeberCollectionTest.php @@ -17,6 +17,60 @@ public function setUp() { $this->found = $this->subscribers->find($this->params); } + /** + * Test to ensure that the nested objects, such as "custom_fields", are formatted correctly for GET request. The + * nested objects should be a JSON encoded string. + */ + public function testFormatOfGetData() { + $findParams = array('custom_fields' => array('test' => 'test')); + $expectedUri = '/accounts/1/lists/303449/subscribers?custom_fields=%7B%22test%22%3A%22test%22%7D&ws.op=find'; + + $this->adapter->clearRequests(); + + $resp = $this->subscribers->find($findParams); + + $req = $this->adapter->requestsMade[0]; + $this->assertEquals($req['method'], 'GET'); + $this->assertEquals($expectedUri, $req['uri']); + $this->assertEmpty($req['headers'], "Find request shouldn't have a Content-Type header"); + } + + /** + * Checks that the nested objects, such as "custom_fields", are formatted correctly. The "create" method + * is a POST with Content-Type of 'application/json'. The data should be formatted as JSON. + */ + public function testFormatOfPostData() { + + $createParams = array( + 'email' => 'test@example.com', + 'ip_address' => '127.0.0.1', + 'name' => 'John Doe', + 'custom_fields' => array( + 'custom' => 'test' + ) + ); + + $expectedCreateParams = array( + 'ws.op' => 'create', + 'email' => 'test@example.com', + 'ip_address' => '127.0.0.1', + 'name' => 'John Doe', + 'custom_fields' => array( + 'custom' => 'test' + ) + ); + + $this->adapter->clearRequests(); + + $resp = $this->subscribers->create($createParams); + + $req = $this->adapter->requestsMade[0]; + $this->assertEquals($req['method'], 'POST'); + $this->assertEquals($req['data'], $expectedCreateParams); + $this->assertEquals(array('Content-Type: application/json'), $req['headers'], "Create request should have a Content-Type header"); + + } + /** * The find method makes two requests, one for the collection, and the other to get total_size. */ @@ -30,7 +84,7 @@ public function testShouldInitiallyMake2APIRequests() { public function testShouldRequestCollectionPageFirst() { #$this->subscribers->find($this->params); $uri = $this->adapter->requestsMade[0]['uri']; - $this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=0&ws.op=find'); + $this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.size=1&ws.start=0'); } /** @@ -38,7 +92,7 @@ public function testShouldRequestCollectionPageFirst() { */ public function testShouldRequestTotalSizePageSecond() { $uri = $this->adapter->requestsMade[1]['uri']; - $this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=0&ws.op=find&ws.show=total_size'); + $this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.show=total_size&ws.size=1&ws.start=0'); } /** @@ -57,7 +111,7 @@ public function testShouldRequestCorrectCollectionPage() { $this->adapter->clearRequests(); $subscriber = $this->found[1]; $uri = $this->adapter->requestsMade[0]['uri']; - $this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=1&ws.op=find'); + $this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.size=1&ws.start=1'); } /** diff --git a/tests/AWeberCreateEntryTest.php b/tests/AWeberCreateEntryTest.php index aa10909..ede35ea 100644 --- a/tests/AWeberCreateEntryTest.php +++ b/tests/AWeberCreateEntryTest.php @@ -18,17 +18,22 @@ public function setUp() { $data = $this->adapter->request('GET', $url); $this->custom_fields = new AWeberCollection($data, $url, $this->adapter); + $subscribers_url = '/accounts/1/lists/303449/subscribers'; + $this->subscribers = new AWeberCollection( + $this->adapter->request('GET', $subscribers_url), + $subscribers_url, + $this->adapter); } /** - * Create Success + * Create Custom Field Success * * A unit test of a successful call to the Collection create method. * Testing is limited to the Collection module; the OAuthAdapater * module that handles the communications with the AWeber Public * API Web Service is stubbed out. */ - public function testCreateSuccess() { + public function testCreateCustomFieldSuccess() { $this->adapter->clearRequests(); $resp = $this->custom_fields->create(array('name' => 'AwesomeField')); @@ -38,18 +43,47 @@ public function testCreateSuccess() { $req = $this->adapter->requestsMade[0]; $this->assertEquals($req['method'], 'POST'); - $this->assertEquals($req['uri'], $this->custom_fields->url); + $this->assertEquals($req['uri'], '/accounts/1/lists/303449/custom_fields?name=AwesomeField&ws.op=create'); $this->assertEquals($req['data'], array( 'ws.op' => 'create', 'name' => 'AwesomeField')); - $this->assertEquals(array('Content-Type: application/json'), $req['headers'], "Create request should have a Content-Type header"); + $this->assertEmpty($req['headers'], "Custom Field create request should have a Content-Type header"); $req = $this->adapter->requestsMade[1]; $this->assertEquals($req['method'], 'GET'); $this->assertEquals($req['uri'], '/accounts/1/lists/303449/custom_fields/2'); $this->assertEmpty($req['headers'], "Get Custom fields request shouldn't have a Content-Type header"); } - + + /** + * Create Success + * + * A unit test of a successful call to the Collection create method. + * Testing is limited to the Collection module; the OAuthAdapater + * module that handles the communications with the AWeber Public + * API Web Service is stubbed out. + */ + public function testCreateSubscriberSuccess() { + + $this->adapter->clearRequests(); + $resp = $this->subscribers->create(array('email' => 'test@test.com')); + + + $this->assertEquals(sizeOf($this->adapter->requestsMade), 2); + + $req = $this->adapter->requestsMade[0]; + $this->assertEquals($req['method'], 'POST'); + $this->assertEquals($req['data'], array( + 'ws.op' => 'create', + 'email' => 'test@test.com')); + $this->assertEquals(array('Content-Type: application/json'), $req['headers'], "Create request should have a Content-Type header"); + + $req = $this->adapter->requestsMade[1]; + $this->assertEquals($req['method'], 'GET'); + $this->assertEquals($req['uri'], '/accounts/1/lists/303449/subscribers/3'); + $this->assertEmpty($req['headers'], "Get subscriber request shouldn't have a Content-Type header"); + } + /** * Create Success With Adapter * diff --git a/tests/AWeberEntryTest.php b/tests/AWeberEntryTest.php index 29fdb48..82842ce 100644 --- a/tests/AWeberEntryTest.php +++ b/tests/AWeberEntryTest.php @@ -269,6 +269,24 @@ public function testShouldSupportFindSubscribersMethod() { $this->assertEquals($subscribers->data['entries'][0]['self_link'], 'https://api.aweber.com/1.0/accounts/1/lists/303449/subscribers/1'); } + + /** + * Test to ensure that the nested objects, such as "custom_fields", are formatted correctly for GET request. The + * nested objects should be a JSON encoded string. + */ + public function testShouldFormatFindSubscribersParameters() { + + $findSubscribersParameters = array('email' => 'joe@example.com', 'custom_fields' => array('test' => 'test')); + $expectedFindSubscribersUri = '/accounts/1?custom_fields=%7B%22test%22%3A%22test%22%7D&email=joe%40example.com&ws.op=findSubscribers'; + + $subscribers = $this->entry->findSubscribers($findSubscribersParameters); + + $req = $this->adapter->requestsMade[1]; + $this->assertEquals($req['method'], 'GET'); + $this->assertEquals($expectedFindSubscribersUri, $req['uri'],"Request data should be formatted properly."); + + } + } class TestAWeberSubscriberEntry extends PHPUnit_Framework_TestCase { @@ -359,11 +377,11 @@ public function testMove_Success() { $req = $this->adapter->requestsMade[0]; $this->assertEquals($req['method'], 'POST'); - $this->assertEquals($req['uri'], $this->subscriber->url); + $this->assertEquals($req['uri'], '/accounts/1/lists/303449/subscribers/1?list_link=https%3A%2F%2Fapi.aweber.com%2F1.0%2Faccounts%2F1%2Flists%2F505454&ws.op=move'); $this->assertEquals($req['data'], array( 'ws.op' => 'move', 'list_link' => $this->different_list->self_link)); - $this->assertEmpty($req['headers'], "Move request shouldn't have a Content-Type header"); + $this->assertEmpty($req['headers'], "Move request shouldn't have a Content-Type header"); $req = $this->adapter->requestsMade[1]; $this->assertEquals($req['method'], 'GET'); @@ -402,7 +420,7 @@ public function testMoveWLastMessageNumberSent_Success() { $req = $this->adapter->requestsMade[0]; $this->assertEquals($req['method'], 'POST'); - $this->assertEquals($req['uri'], $this->subscriber->url); + $this->assertEquals($req['uri'], '/accounts/1/lists/303449/subscribers/1?last_followup_message_number_sent=1&list_link=https%3A%2F%2Fapi.aweber.com%2F1.0%2Faccounts%2F1%2Flists%2F505454&ws.op=move'); $this->assertEquals($req['data'], array( 'ws.op' => 'move', 'list_link' => $this->different_list->self_link, diff --git a/tests/mock_adapter.php b/tests/mock_adapter.php index ebb7639..f23da9d 100644 --- a/tests/mock_adapter.php +++ b/tests/mock_adapter.php @@ -30,7 +30,8 @@ function get_mock_adapter() { $map['GET' ]['/accounts/1/lists/303449/subscribers?email=someone%40example.com&ws.op=find' ] = array(200, 'subscribers/find'); $map['GET' ]['/accounts/1/lists/505454' ] = array(200, 'lists/505454'); $map['GET' ]['/accounts/1/lists/505454/subscribers/3' ] = array(200, 'subscribers/3'); -$map['GET' ]['/accounts/1/lists?ws.start=20&ws.size=20' ] = array(200, 'lists/page2'); +$map['GET' ]['/accounts/1/lists/303449/subscribers/3' ] = array(200, 'subscribers/3'); +$map['GET' ]['/accounts/1/lists?ws.size=20&ws.start=20' ] = array(200, 'lists/page2'); $map['GET' ]['/accounts/1?email=joe%40example.com&ws.op=findSubscribers&ws.show=total_size' ] = array(200, 'accounts/findSubscribers_ts'); $map['GET' ]['/accounts/1?email=joe%40example.com&ws.op=findSubscribers' ] = array(200, 'accounts/findSubscribers'); $map['GET' ]['/accounts/1?ws.op=getWebFormSplitTests' ] = array(200, 'accounts/webFormSplitTests'); @@ -39,18 +40,25 @@ function get_mock_adapter() { $map['GET' ]['/accounts/1/lists/303449/broadcasts/1337' ] = array(200, 'broadcasts/1337'); # collection pagination tests -$map['GET' ]['/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=0&ws.op=find' ] = array(200, 'subscribers/find_1of2'); -$map['GET' ]['/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=1&ws.op=find' ] = array(200, 'subscribers/find_2of2'); -$map['GET' ]['/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=0&ws.op=find&ws.show=total_size'] = array(200, 'subscribers/find_1of2_tsl'); +$map['GET' ]['/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.size=1&ws.start=0' ] = array(200, 'subscribers/find_1of2'); +$map['GET' ]['/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.size=1&ws.start=1' ] = array(200, 'subscribers/find_2of2'); +$map['GET' ]['/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.show=total_size&ws.size=1&ws.start=0'] = array(200, 'subscribers/find_1of2_tsl'); $map['PATCH' ]['/accounts/1/lists/303449' ] = array(209, 'lists/303449'); $map['PATCH' ]['/accounts/1/lists/303449/subscribers/1' ] = array(209, 'subscribers/1'); $map['PATCH' ]['/accounts/1/lists/505454' ] = array(404, 'error'); -$map['POST' ]['/accounts/1/lists/303449/custom_fields' ] = array(201, '/accounts/1/lists/303449/custom_fields/2'); -$map['POST' ]['/accounts/1/lists/303449/subscribers/1' ] = array(201, '/accounts/1/lists/505454/subscribers/3'); -$map['POST' ]['/accounts/1/lists/303449/subscribers/2' ] = array(400, 'error'); +$map['POST' ]['/accounts/1/lists/303449/custom_fields?name=AwesomeField&ws.op=create' ] = array(201, '/accounts/1/lists/303449/custom_fields/2'); +$map['POST' ]['/accounts/1/lists/303449/subscribers/1?list_link=https%3A%2F%2Fapi.aweber.com%2F1.0%2Faccounts%2F1%2Flists%2F505454&ws.op=move' ] = array(201, '/accounts/1/lists/505454/subscribers/3'); +$map['POST' ]['/accounts/1/lists/303449/subscribers/1?last_followup_message_number_sent=1&list_link=https%3A%2F%2Fapi.aweber.com%2F1.0%2Faccounts%2F1%2Flists%2F505454&ws.op=move' ] = array(201, '/accounts/1/lists/505454/subscribers/3'); +$map['POST' ]['/accounts/1/lists/303449/subscribers/2?list_link=https%3A%2F%2Fapi.aweber.com%2F1.0%2Faccounts%2F1%2Flists%2F505454&ws.op=move' ] = array(400, 'error'); +# Entity Body formatting +$map['POST' ]['/accounts/1/lists/303449/subscribers' ] = array(201, '/accounts/1/lists/303449/subscribers/3'); +$map['GET' ]['/accounts/1?custom_fields=%7B%22test%22%3A%22test%22%7D&email=joe%40example.com&ws.op=findSubscribers&ws.show=total_size' ] = array(200, 'accounts/findSubscribers_ts'); +$map['GET' ]['/accounts/1?custom_fields=%7B%22test%22%3A%22test%22%7D&email=joe%40example.com&ws.op=findSubscribers' ] = array(200, 'accounts/findSubscribers'); +$map['GET' ]['/accounts/1/lists/303449/subscribers?custom_fields=%7B%22test%22%3A%22test%22%7D&ws.op=find' ] = array(200, 'subscribers/find_1of2'); +$map['GET' ]['/accounts/1/lists/303449/subscribers?custom_fields=%7B%22test%22%3A%22test%22%7D&ws.op=find&ws.show=total_size' ] = array(200, 'subscribers/find_1of2_tsl'); class MockOAuthAdapter extends OAuthApplication { @@ -68,14 +76,23 @@ public function clearRequests() { $this->requestsMade = array(); } + /* + * Overriding parent to prevent the addition of the OAuth parameters + */ + public function prepareRequest($method, $url, $data) + { + return $data; + } + public function makeRequest($method, $url, $data=array(), $headers=array()) { global $map; # append params to url (for fixtures) $uri = str_replace($this->app->baseUri, '', $url); - if ($method == 'GET' && !empty($data)) { - $uri = $uri.'?'. http_build_query($data); - } + + list($url_params, $request_body) = $this->formatRequestData($method, $uri, $data, $headers); + + $uri = $this->_addParametersToUrl($uri, $url_params); # extract response map parameters #