Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Adding support post status with media #148

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions EpiOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
29 changes: 13 additions & 16 deletions EpiTwitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
class EpiTwitter extends EpiOAuth
Expand All @@ -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 */
Expand Down Expand Up @@ -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}";
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -242,7 +239,7 @@ public function __isset($name)
}
}

class EpiTwitterException extends Exception
class EpiTwitterException extends Exception
{
public static function raise($response, $debug)
{
Expand Down
9 changes: 9 additions & 0 deletions tests/EpiTwitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('&lt;','&gt;'),$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)));
Expand Down