Skip to content
This repository was archived by the owner on Dec 4, 2018. It is now read-only.
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
28 changes: 20 additions & 8 deletions EpiTwitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ class EpiTwitter extends EpiOAuth
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 $mediaUrl = 'https://upload.twitter.com';
protected $userAgent = 'EpiTwitter (http://github.com/jmathai/twitter-async/tree/)';
protected $apiVersion = '1';
protected $isAsynchronous = false;
/**
* The Twitter API version 1.0 search URL.
* @var string
*/
protected $searchUrl = 'http://search.twitter.com';

/* OAuth methods */
public function delete($endpoint, $params = null)
Expand Down Expand Up @@ -57,6 +61,11 @@ public function post_basic($endpoint, $params = null, $username = null, $passwor
return $this->request_basic('POST', $endpoint, $params, $username, $password);
}

public function useApiUrl($url = '')
{
$this->apiUrl = rtrim( $url, '/' );
}

public function useApiVersion($version = null)
{
$this->apiVersion = $version;
Expand Down Expand Up @@ -103,12 +112,15 @@ 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))
return "{$this->apiVersionedUrl}/{$this->apiVersion}{$endpoint}";
else
return "{$this->apiUrl}{$endpoint}";
if($this->apiVersion === '1')
{
if(strpos($endpoint,"with_media") > 0)
return "{$this->mediaUrl}/{$this->apiVersion}{$endpoint}";
elseif(preg_match('@^/search[./]?(?=(json|daily|current|weekly))@', $endpoint))
return $this->searchUrl.$endpoint;
}

return $this->apiUrl.'/'.$this->apiVersion.$endpoint;
}

private function request($method, $endpoint, $params = null)
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