Permalink
Browse files

Multipart calls working for udpating profile image.

All unit tests passing.
closes gh-4
closes gh-8
  • Loading branch information...
1 parent 5fc33a5 commit ccb2ab5c3f14886607e11f904622a43f11060a5c @jmathai committed Jun 9, 2009
Showing with 46 additions and 21 deletions.
  1. +22 −19 EpiOAuth.php
  2. +0 −1 EpiTwitter.php
  3. +24 −1 tests/EpiTwitterTest.php
  4. BIN tests/avatar_test_image.png
View
@@ -89,6 +89,15 @@ protected function addOAuthHeaders(&$ch, $url, $oauthHeaders)
curl_setopt($ch, CURLOPT_HTTPHEADER, $_h);
}
+ protected function buildHttpQueryRaw($params)
+ {
+ $retval = '';
+ foreach((array)$params as $key => $value)
+ $retval .= "{$key}={$value}&";
+ $retval = substr($retval, 0, -1);
+ return $retval;
+ }
+
protected function curlInit($url)
{
$ch = curl_init($url);
@@ -114,19 +123,15 @@ protected function generateNonce()
return md5(uniqid(rand(), true));
}
+ // parameters should already have been passed through prepareParameters
+ // no need to double encode
protected function generateSignature($method = null, $url = null, $params = null)
{
if(empty($method) || empty($url))
return false;
- // concatenating
- $concatenatedParams = '';
- foreach($params as $k => $v)
- {
- $v = $this->encode_rfc3986($v);
- $concatenatedParams .= "{$k}={$v}&";
- }
- $concatenatedParams = $this->encode_rfc3986(substr($concatenatedParams, 0, -1));
+ // concatenating and encode
+ $concatenatedParams = $this->encode_rfc3986($this->buildHttpQueryRaw($params));
// normalize url
$normalizedUrl = $this->encode_rfc3986($this->normalizeUrl($url));
@@ -164,7 +169,7 @@ protected function httpPost($url, $params = null, $isMultipart)
if($isMultipart)
curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']);
else
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params['request']));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request']));
$resp = $this->curl->addCurl($ch);
return $resp;
}
@@ -202,22 +207,20 @@ protected function prepareParameters($method = null, $url = null, $params = null
$oauth['oauth_signature_method'] = $this->signatureMethod;
$oauth['oauth_version'] = $this->version;
// encode all oauth values
-// foreach($oauth as $k => $v)
-// $oauth[$k] = $this->encode_rfc3986($v);
-// // encode all non '@' params
-// // keep sigParams for signature generation (exclude '@' params)
-// // rename '@key' to 'key'
-// $sigParams = array();
+ foreach($oauth as $k => $v)
+ $oauth[$k] = $this->encode_rfc3986($v);
+ // encode all non '@' params
+ // keep sigParams for signature generation (exclude '@' params)
+ // rename '@key' to 'key'
+ $sigParams = array();
if(is_array($params))
{
foreach($params as $k => $v)
{
if(strncmp('@',$k,1) !== 0)
{
-// $sigParams[$k] = $this->encode_rfc3986($v);
-// $params[$k] = $this->encode_rfc3986($v);
- $sigParams[$k] = ($v);
- $params[$k] = ($v);
+ $sigParams[$k] = $this->encode_rfc3986($v);
+ $params[$k] = $this->encode_rfc3986($v);
}
else
{
View
@@ -32,7 +32,6 @@ public function __call($name, $params = null)
// calls which do not have a consumerKey are assumed to not require authentication
if(empty($this->consumerKey))
{
- echo 'do basic';
$query = isset($args) ? http_build_query($args) : '';
$url = "{$this->searchUrl}{$path}?{$query}";
$ch = curl_init($url);
View
@@ -53,6 +53,10 @@ function testGetFollowers()
function testPostStatus()
{
+ $statusText = 'Testing really weird chars "~!@#$%^&*()-+\[]{}:\'>?<≈ç∂´ß©ƒ˙˙∫√√ƒƒ∂∂†¥∆∆∆ (time: ' . time() . ')';
+ $resp = $this->twitterObj->post_statusesUpdate(array('status' => $statusText));
+ $this->assertEquals($resp->text, str_replace(array('<','>'),array('&lt;','&gt;'),$statusText), 'The status was not updated correctly');
+
$statusText = 'Testing a random status (time: ' . time() . ')';
$resp = $this->twitterObj->post_statusesUpdate(array('status' => $statusText));
$this->assertEquals($resp->text, $statusText, 'The status was not updated correctly');
@@ -118,7 +122,7 @@ function testTrends()
$this->assertTrue(is_array($resp->response['trends']), "trends is empty");
$this->assertTrue(!empty($resp->trends[0]->name), "current trends is not an array " . $resp->trends[0]->name);
- $resp = $this->twitterObj->get_trendsCurrent();
+ $resp = $this->twitterObjBasic->get_trendsCurrent();
$this->assertTrue(is_array($resp->response['trends']), "current trends is empty");
}
@@ -141,11 +145,30 @@ function testCount()
$resp = $this->twitterObj->$method(array('page' => 100));
$this->assertTrue(count($resp) == 0, "Page 100 should return a count of 0");
}
+
function testUpdateAvatar()
{
$file = dirname(__FILE__) . '/avatar_test_image.jpg';
$resp = $this->twitterObj->post_accountUpdate_profile_image(array('@image' => "@{$file}"));
// api seems to be a bit behind and doesn't respond with the new image url - use code instead for now
$this->assertEquals($resp->code, 200, 'Response code was not 200');
+
+ $file = dirname(__FILE__) . '/avatar_test_image.png';
+ $resp = $this->twitterObj->post_accountUpdate_profile_image(array('@image' => "@{$file}"));
+ // api seems to be a bit behind and doesn't respond with the new image url - use code instead for now
+ $this->assertEquals($resp->code, 200, 'Response code was not 200');
+ }
+
+ function testUpdateBackground()
+ {
+ $file = dirname(__FILE__) . '/avatar_test_image.jpg';
+ $resp = $this->twitterObj->post_accountUpdate_profile_background_image(array('@image' => "@{$file}"));
+ // api seems to be a bit behind and doesn't respond with the new image url - use code instead for now
+ $this->assertEquals($resp->code, 200, 'Response code was not 200');
+
+ $file = dirname(__FILE__) . '/avatar_test_image.png';
+ $resp = $this->twitterObj->post_accountUpdate_profile_background_image(array('@image' => "@{$file}"));
+ // api seems to be a bit behind and doesn't respond with the new image url - use code instead for now
+ $this->assertEquals($resp->code, 200, 'Response code was not 200');
}
}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ccb2ab5

Please sign in to comment.