--- tests/Zend/Service/TwitterTest.php (revision 18182) +++ tests/Zend/Service/TwitterTest.php (working copy) @@ -189,7 +189,7 @@ { $response = $this->twitter->account->verifyCredentials(); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -202,7 +202,7 @@ { $response = $this->twitter->status->publicTimeline(); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -217,7 +217,7 @@ $response = $this->twitter->user->featured(); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -230,7 +230,7 @@ $response = $this->twitter->account->rateLimitStatus(); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -263,7 +263,7 @@ public function testFriendshipCreate() { $response = $this->twitter->friendship->create('zftestuser1'); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($response instanceof Zend_Rest_Client_Result); } @@ -277,7 +277,7 @@ $response = $this->twitter->friendship->exists('zftestuser1'); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -291,7 +291,7 @@ /* @var $response Zend_Rest_Client_Result */ $response = $this->twitter->status->friendsTimeline( array('foo' => 'bar') ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -306,7 +306,7 @@ /* @var $response Zend_Rest_Client_Result */ $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1') ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -321,7 +321,7 @@ $this->insertTestTwitterData(); $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'since' => '-2 days') ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -337,7 +337,7 @@ $this->insertTestTwitterData(); $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'since' => strtotime('-2 days')) ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -353,7 +353,7 @@ /* @var $response Zend_Rest_Client_Result */ $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'since' => '-2 days') ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -369,7 +369,7 @@ /* @var $response Zend_Rest_Client_Result */ $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'page' => '2') ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -385,7 +385,7 @@ /* @var $response Zend_Rest_Client_Result */ $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'count' => '2') ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -402,7 +402,7 @@ /* @var $response Zend_Rest_Client_Result */ $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'count' => 2) ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $raw_response = $httpResponse->getHeadersAsString() . $httpResponse->getBody(); @@ -417,7 +417,7 @@ /* @var $response Zend_Rest_Client_Result */ $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'count' => 40) ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -435,7 +435,7 @@ $response = $this->twitter->status->update( 'Test Message - ' . rand() ); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -489,7 +489,7 @@ $response2 = $this->twitter->status->show($status_id); $this->assertTrue($response2 instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -512,7 +512,7 @@ $response2 = $this->twitter->favorite->create($update_id); $this->assertTrue($response2 instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -528,7 +528,7 @@ $response = $this->twitter->favorite->favorites(); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -546,7 +546,7 @@ $response2 = $this->twitter->favorite->destroy($update_id); $this->assertTrue($response2 instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -565,7 +565,7 @@ $response2 = $this->twitter->status->destroy($update_id); $this->assertTrue($response2 instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -576,7 +576,7 @@ { $response = $this->twitter->user->friends(); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -587,7 +587,7 @@ { $response = $this->twitter->user->followers(array('id' =>'zftestuser1')); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -598,7 +598,7 @@ { $response = $this->twitter->user->friends(array('id' =>'zftestuser1')); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -623,7 +623,7 @@ { $response = $this->twitter->status->replies(array('since' => '-800 days', 'page' => 1, 'since_id' => 10000, 'invalid_option' => 'doh')); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -637,7 +637,7 @@ $response = $this->twitter->friendship->destroy('zftestuser1'); $this->assertTrue($response instanceof Zend_Rest_Client_Result); - $httpClient = Zend_Service_Twitter::getHttpClient(); + $httpClient = $this->twitter->getLocalHttpClient(); $httpRequest = $httpClient->getLastRequest(); $httpResponse = $httpClient->getLastResponse(); $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString()); @@ -656,6 +656,16 @@ } $twitter->account->endSession(); } + + /** + * @issue ZF-6284 + */ + public function testTwitterObjectsSoNotShareSameHttpClientToPreventConflictingAuthentication() + { + $twitter1 = new Zend_Service_Twitter('zftestuser1','zftestuser1'); + $twitter2 = new Zend_Service_Twitter('zftestuser2','zftestuser2'); + $this->assertFalse($twitter1->getLocalHttpClient() === $twitter2->getLocalHttpClient()); + } } if (PHPUnit_MAIN_METHOD == 'Zend_Service_TwitterTest::main') { Index: library/Zend/Service/Twitter.php =================================================================== --- library/Zend/Service/Twitter.php (revision 18182) +++ library/Zend/Service/Twitter.php (working copy) @@ -69,7 +69,9 @@ * Types of API methods * @var array */ - protected $_methodTypes = array('status' , 'user' , 'directMessage' , 'friendship' , 'account' , 'favorite'); + protected $_methodTypes = array('status' , 'user' , 'directMessage' , 'friendship' , 'account' , 'favorite'); + + protected $_localHttpClient = null; /** * Constructor * @@ -78,7 +80,8 @@ * @return void */ public function __construct ($username, $password = null) - { + { + $this->_localHttpClient = clone self::getHttpClient(); if (is_array($username) && is_null($password)) { if (isset($username['username']) && isset($username['password'])) { $this->setUsername($username['username']); @@ -92,8 +95,12 @@ $this->setPassword($password); } $this->setUri('http://twitter.com'); - $client = self::getHttpClient(); - $client->setHeaders('Accept-Charset', 'ISO-8859-1,utf-8'); + $this->_localHttpClient->setHeaders('Accept-Charset', 'ISO-8859-1,utf-8'); + } + + public function getLocalHttpClient() + { + return $this->_localHttpClient; } /** * Retrieve username @@ -181,7 +188,7 @@ */ protected function _init () { - $client = self::getHttpClient(); + $client = $this->_localHttpClient; $client->resetParameters(); if (null == $this->_cookieJar) { $client->setCookieJar(); @@ -207,7 +214,7 @@ } else { $date = date($this->_dateFormat, strtotime($value)); } - self::getHttpClient()->setHeaders('If-Modified-Since', $date); + $this->_localHttpClient->setHeaders('If-Modified-Since', $date); } /** * Public Timeline status @@ -219,7 +226,7 @@ { $this->_init(); $path = '/statuses/public_timeline.xml'; - $response = $this->restGet($path); + $response = $this->_get($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -266,7 +273,7 @@ } } $path .= '.xml'; - $response = $this->restGet($path, $_params); + $response = $this->_get($path, $_params); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -311,7 +318,7 @@ } } $path .= '.xml'; - $response = $this->restGet($path, $_params); + $response = $this->_get($path, $_params); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -325,7 +332,7 @@ { $this->_init(); $path = '/statuses/show/' . $this->_validInteger($id) . '.xml'; - $response = $this->restGet($path); + $response = $this->_get($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -354,7 +361,7 @@ $data['in_reply_to_status_id'] = $in_reply_to_status_id; } //$this->status = $status; - $response = $this->restPost($path, $data); + $response = $this->_post($path, $data); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -388,7 +395,7 @@ break; } } - $response = $this->restGet($path, $_params); + $response = $this->_get($path, $_params); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -402,7 +409,7 @@ { $this->_init(); $path = '/statuses/destroy/' . $this->_validInteger($id) . '.xml'; - $response = $this->restPost($path); + $response = $this->_post($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -433,7 +440,7 @@ } } $path .= '.xml'; - $response = $this->restGet($path, $_params); + $response = $this->_get($path, $_params); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -450,7 +457,7 @@ if ($lite) { $this->lite = 'true'; } - $response = $this->restGet($path); + $response = $this->_get($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -463,7 +470,7 @@ { $this->_init(); $path = '/statuses/featured.xml'; - $response = $this->restGet($path); + $response = $this->_get($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -477,7 +484,7 @@ { $this->_init(); $path = '/users/show/' . $this->_validInteger($id) . '.xml'; - $response = $this->restGet($path); + $response = $this->_get($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -512,7 +519,7 @@ break; } } - $response = $this->restGet($path, $_params); + $response = $this->_get($path, $_params); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -547,7 +554,7 @@ break; } } - $response = $this->restGet($path, $_params); + $response = $this->_get($path, $_params); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -570,7 +577,7 @@ throw new Zend_Service_Twitter_Exception('Direct message must contain no more than 140 characters'); } $data = array('user' => $user , 'text' => $text); - $response = $this->restPost($path, $data); + $response = $this->_post($path, $data); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -584,7 +591,7 @@ { $this->_init(); $path = '/direct_messages/destroy/' . $this->_validInteger($id) . '.xml'; - $response = $this->restPost($path); + $response = $this->_post($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -598,7 +605,7 @@ { $this->_init(); $path = '/friendships/create/' . $this->_validInteger($id) . '.xml'; - $response = $this->restPost($path); + $response = $this->_post($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -612,7 +619,7 @@ { $this->_init(); $path = '/friendships/destroy/' . $this->_validInteger($id) . '.xml'; - $response = $this->restPost($path); + $response = $this->_post($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -627,7 +634,7 @@ $this->_init(); $path = '/friendships/exists.xml'; $data = array('user_a' => $this->getUsername() , 'user_b' => $this->_validInteger($id)); - $response = $this->restGet($path, $data); + $response = $this->_get($path, $data); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -639,7 +646,7 @@ public function accountVerifyCredentials () { $this->_init(); - $response = $this->restGet('/account/verify_credentials.xml'); + $response = $this->_get('/account/verify_credentials.xml'); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -651,7 +658,7 @@ public function accountEndSession () { $this->_init(); - $this->restGet('/account/end_session'); + $this->_get('/account/end_session'); return true; } /** @@ -663,7 +670,7 @@ public function accountRateLimitStatus () { $this->_init(); - $response = $this->restGet('/account/rate_limit_status.xml'); + $response = $this->_get('/account/rate_limit_status.xml'); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -695,7 +702,7 @@ } } $path .= '.xml'; - $response = $this->restGet($path, $_params); + $response = $this->_get($path, $_params); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -709,7 +716,7 @@ { $this->_init(); $path = '/favorites/create/' . $this->_validInteger($id) . '.xml'; - $response = $this->restPost($path); + $response = $this->_post($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -723,7 +730,7 @@ { $this->_init(); $path = '/favorites/destroy/' . $this->_validInteger($id) . '.xml'; - $response = $this->restPost($path); + $response = $this->_post($path); return new Zend_Rest_Client_Result($response->getBody()); } /** @@ -738,5 +745,87 @@ return $int; } return 0; - } + } + + /** + * Call a remote REST web service URI and return the Zend_Http_Response object + * + * @param string $path The path to append to the URI + * @throws Zend_Rest_Client_Exception + * @return void + */ + protected function _prepare($path) + { + // Get the URI object and configure it + if (!$this->_uri instanceof Zend_Uri_Http) { + require_once 'Zend/Rest/Client/Exception.php'; + throw new Zend_Rest_Client_Exception('URI object must be set before performing call'); + } + + $uri = $this->_uri->getUri(); + + if ($path[0] != '/' && $uri[strlen($uri)-1] != '/') { + $path = '/' . $path; + } + + $this->_uri->setPath($path); + + /** + * Get the HTTP client and configure it for the endpoint URI. Do this each time + * because the Zend_Http_Client instance is shared among all Zend_Service_Abstract subclasses. + */ + $this->_localHttpClient->resetParameters()->setUri($this->_uri); + } + + /** + * Performs an HTTP GET request to the $path. + * + * @param string $path + * @param array $query Array of GET parameters + * @throws Zend_Http_Client_Exception + * @return Zend_Http_Response + */ + protected function _get($path, array $query = null) + { + $this->_prepare($path); + $this->_localHttpClient->setParameterGet($query); + return $this->_localHttpClient->request('GET'); + } + + /** + * Performs an HTTP POST request to $path. + * + * @param string $path + * @param mixed $data Raw data to send + * @throws Zend_Http_Client_Exception + * @return Zend_Http_Response + */ + protected function _post($path, $data = null) + { + $this->_prepare($path); + return $this->_performPost('POST', $data); + } + + /** + * Perform a POST or PUT + * + * Performs a POST or PUT request. Any data provided is set in the HTTP + * client. String data is pushed in as raw POST data; array or object data + * is pushed in as POST parameters. + * + * @param mixed $method + * @param mixed $data + * @return Zend_Http_Response + */ + protected function _performPost($method, $data = null) + { + $client = $this->_localHttpClient; + if (is_string($data)) { + $client->setRawData($data); + } elseif (is_array($data) || is_object($data)) { + $client->setParameterPost((array) $data); + } + return $client->request($method); + } + }