diff --git a/EpiOAuth.php b/EpiOAuth.php index 6831b33..042fcee 100644 --- a/EpiOAuth.php +++ b/EpiOAuth.php @@ -266,10 +266,12 @@ protected function httpPost($url, $params = null, $isMultipart) curl_setopt($ch, CURLOPT_POST, 1); // php's curl extension automatically sets the content type // based on whether the params are in string or array form - if($isMultipart) + if($isMultipart) { + $params['request']['status'] = urldecode($params['request']['status']); curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']); - else + } else { curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request'])); + } $resp = $this->executeCurl($ch); $this->emptyHeaders(); diff --git a/EpiTwitter.php b/EpiTwitter.php index a5e9e94..c96c5b1 100644 --- a/EpiTwitter.php +++ b/EpiTwitter.php @@ -3,10 +3,10 @@ * Class to integrate with Twitter's API. * Authenticated calls are done using OAuth and require access tokens for a user. * API calls which do not require authentication do not require tokens (i.e. search/trends) - * + * * Full documentation available on github * http://wiki.github.com/jmathai/twitter-async - * + * * @author Jaisen Mathai */ class EpiTwitter extends EpiOAuth @@ -18,11 +18,10 @@ class EpiTwitter extends EpiOAuth protected $accessTokenUrl = 'https://api.twitter.com/oauth/access_token'; protected $authorizeUrl = 'https://api.twitter.com/oauth/authorize'; protected $authenticateUrl= 'https://api.twitter.com/oauth/authenticate'; - protected $apiUrl = 'http://api.twitter.com'; - protected $apiVersionedUrl= 'http://api.twitter.com'; - protected $searchUrl = 'http://search.twitter.com'; + protected $apiUrl = 'https://api.twitter.com/1.1'; + protected $apiVersionedUrl= 'https://api.twitter.com'; protected $userAgent = 'EpiTwitter (http://github.com/jmathai/twitter-async/tree/)'; - protected $apiVersion = '1'; + protected $apiVersion = '1.1'; protected $isAsynchronous = false; /* OAuth methods */ @@ -103,9 +102,7 @@ public function __call($name, $params = null/*, $username, $password*/) private function getApiUrl($endpoint) { - if(preg_match('@^/search[./]?(?=(json|daily|current|weekly))@', $endpoint)) - return "{$this->searchUrl}{$endpoint}"; - elseif(!empty($this->apiVersion)) + if(!empty($this->apiVersion)) return "{$this->apiVersionedUrl}/{$this->apiVersion}{$endpoint}"; else return "{$this->apiUrl}{$endpoint}"; @@ -180,28 +177,28 @@ public function count () { return count($this->response); } - + // Next four functions are to support ArrayAccess interface // 1 - public function offsetSet($offset, $value) + public function offsetSet($offset, $value) { $this->response[$offset] = $value; } // 2 - public function offsetExists($offset) + public function offsetExists($offset) { return isset($this->response[$offset]); } - + // 3 - public function offsetUnset($offset) + public function offsetUnset($offset) { unset($this->response[$offset]); } // 4 - public function offsetGet($offset) + public function offsetGet($offset) { return isset($this->response[$offset]) ? $this->response[$offset] : null; } @@ -242,7 +239,7 @@ public function __isset($name) } } -class EpiTwitterException extends Exception +class EpiTwitterException extends Exception { public static function raise($response, $debug) { diff --git a/tests/EpiTwitterTest.php b/tests/EpiTwitterTest.php index aebcdb7..87f530c 100644 --- a/tests/EpiTwitterTest.php +++ b/tests/EpiTwitterTest.php @@ -166,6 +166,15 @@ function testPostStatusUnicode() $this->assertEquals($resp->text, $statusText, 'The status was not updated correctly'); } + function testPostStatusWithMedia() + { + $file = dirname(__FILE__) . '/avatar_test_image.jpg'; + $statusText = 'Testing with image upload as media to status (time: ' . time() . ')'; + $resp = $this->twitterObj->post('/statuses/update_with_media.json', array('@media[]' => "@{$offerImage};type=$imageType;filename={$offerImage}", + 'status' => $statusText)); + $this->assertEquals($resp->text, str_replace(array('<','>'),array('<','>'),$statusText), 'The status was not updated correctly for __call'); + } + function testDirectMessage() { $resp = $this->twitterObj->post('/direct_messages/new.json', array ( 'user' => $this->screenName, 'text' => "@username that's dirt cheap man, good looking out. I shall buy soon.You still play Halo at all? " . rand(0,1000)));