Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sesser/Instaphp
Browse files Browse the repository at this point in the history
  • Loading branch information
ollietb committed Jan 2, 2015
2 parents ab2cfcc + f2f0d64 commit ec856c5
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Expand Up @@ -2,7 +2,10 @@ language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
branches:
only:
- master
- development
- development
19 changes: 19 additions & 0 deletions src/Instaphp/Instagram/Instagram.php
Expand Up @@ -235,6 +235,11 @@ private function prepare(array $params)
unset($params['client_id']);
$params['access_token'] = $this->access_token;
}

foreach ($params as $k => $v) {
$params[$k] = urlencode($v);
}

return $params;
}

Expand All @@ -257,6 +262,19 @@ protected function buildPath($path, $add_version = true)
return $path;
}

/**
* Works like sprintf, but urlencodes it's arguments
* @param string $path Path (in sprintf format)
* @param mixed... $args Arguments to be urlencoded and passed to sprintf
* @return string
*/
protected function formatPath($path) {
$args = func_get_args();
$path = array_shift($args);
$args = array_map('urlencode', $args);
return vsprintf($path, $args);
}

/**
* Parses both the {@link \Instaphp\Utils\Http\Response HTTP Response} and
* the {@link \Instaphp\Instagram\Response Instagram Response} and scans them
Expand Down Expand Up @@ -322,4 +340,5 @@ private function parseResponse(Response $response)
}
return $igresponse;
}

}
4 changes: 2 additions & 2 deletions src/Instaphp/Instagram/Locations.php
Expand Up @@ -49,7 +49,7 @@ class Locations extends Instagram
*/
public function Info($location_id)
{
return $this->Get('/locations/' . $location_id);
return $this->Get($this->formatPath('/locations/%s', $location_id));
}

/**
Expand All @@ -65,7 +65,7 @@ public function Info($location_id)
*/
public function Recent($location_id, array $params = [])
{
return $this->Get(sprintf('/locations/%s/media/recent', $location_id), $params);
return $this->Get($this->formatPath('/locations/%s/media/recent', $location_id), $params);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Instaphp/Instagram/Media.php
Expand Up @@ -63,7 +63,7 @@ public function Popular(array $params = [])
*/
public function Info($media_id, array $params = [])
{
return $this->Get('/media/' . $media_id, $params);
return $this->Get($this->formatPath('/media/%s', $media_id), $params);
}

/**
Expand Down Expand Up @@ -95,7 +95,7 @@ public function Like($media_id)
{
if (empty($this->access_token))
throw new \Instaphp\Exceptions\OAuthParameterException("A valid access_token is required for this endpoint");
return $this->Post(sprintf('/media/%s/likes', $media_id));
return $this->Post($this->formatPath('/media/%s/likes', $media_id));
}

/**
Expand All @@ -105,7 +105,7 @@ public function Like($media_id)
*/
public function Likes($media_id)
{
return $this->Get(sprintf('/media/%s/likes', $media_id));
return $this->Get($this->formatPath('/media/%s/likes', $media_id));
}

/**
Expand All @@ -119,7 +119,7 @@ public function Unlike($media_id)
if (empty($this->access_token))
throw new \Instaphp\Exceptions\OAuthParameterException("A valid access_token is required for this endpoint");

return $this->Delete(sprintf('/media/%s/likes', $media_id));
return $this->Delete($this->formatPath('/media/%s/likes', $media_id));
}

/**
Expand All @@ -134,7 +134,7 @@ public function Comment($media_id, $comment)
if (empty($this->access_token))
throw new \Instaphp\Exceptions\OAuthParameterException("A valid access_token is required for this endpoint");

return $this->Post(sprintf('/media/%s/comments', $media_id), ['text' => $comment]);
return $this->Post($this->formatPath('/media/%s/comments', $media_id), ['text' => $comment]);
}

/**
Expand All @@ -144,7 +144,7 @@ public function Comment($media_id, $comment)
*/
public function Comments($media_id)
{
return $this->Get(sprintf('/media/%s/comments', $media_id));
return $this->Get($this->formatPath('/media/%s/comments', $media_id));
}

/**
Expand All @@ -159,7 +159,7 @@ public function Uncomment($media_id, $comment_id)
if (empty($this->access_token))
throw new \Instaphp\Exceptions\OAuthParameterException("A valid access_token is required for this endpoint");

return $this->Delete(sprintf('/media/%s/comments/%s', $media_id, $comment_id));
return $this->Delete($this->formatPath('/media/%s/comments/%s', $media_id, $comment_id));
}
}

4 changes: 2 additions & 2 deletions src/Instaphp/Instagram/Tags.php
Expand Up @@ -47,7 +47,7 @@ class Tags extends Instagram
*/
public function Info($tag)
{
return $this->Get('/tags/'. $tag);
return $this->Get($this->formatPath('/tags/%s', $tag));
}

/**
Expand All @@ -66,7 +66,7 @@ public function Info($tag)
*/
public function Recent($tag, array $params = [])
{
return $this->Get(sprintf('/tags/%s/media/recent', $tag), $params);
return $this->Get($this->formatPath('/tags/%s/media/recent', $tag), $params);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Instaphp/Instagram/Users.php
Expand Up @@ -91,7 +91,7 @@ public function FindId($username)
*/
public function Info($user_id)
{
return $this->Get('/users/' . $user_id);
return $this->Get($this->formatPath('/users/%s', $user_id));
}

/**
Expand All @@ -115,7 +115,7 @@ public function Feed(array $params = [])
*/
public function Recent($user_id, array $params = [])
{
return $this->Get(sprintf('/users/%s/media/recent', $user_id), $params);
return $this->Get($this->formatPath('/users/%s/media/recent', $user_id), $params);
}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public function Search($username, array $params = [])
*/
public function Follows($user_id, array $params = [])
{
return $this->Get(sprintf('/users/%s/follows', $user_id), $params);
return $this->Get($this->formatPath('/users/%s/follows', $user_id), $params);
}

/**
Expand All @@ -163,7 +163,7 @@ public function Follows($user_id, array $params = [])
*/
public function FollowedBy($user_id, array $params = [])
{
return $this->Get(sprintf('/users/%s/followed-by', $user_id), $params);
return $this->Get($this->formatPath('/users/%s/followed-by', $user_id), $params);
}

/**
Expand All @@ -190,7 +190,7 @@ public function Relationship($user_id)
if (empty($this->access_token))
throw new \Instaphp\Exceptions\OAuthParameterException("A valid access_token is requred to call this endpoint");

return $this->Get(sprintf('/users/%s/relationship', $user_id));
return $this->Get($this->formatPath('/users/%s/relationship', $user_id));
}

/**
Expand Down Expand Up @@ -271,6 +271,6 @@ private function setRelationship($user_id, $action)
if (empty($this->access_token))
throw new \Instaphp\Exceptions\OAuthParameterException("A valid access_token is requred to call this endpoint");

return $this->Post(sprintf('/users/%s/relationship', $user_id), ['action' => $action]);
return $this->Post($this->formatPath('/users/%s/relationship', $user_id), ['action' => $action]);
}
}
3 changes: 2 additions & 1 deletion tests/src/Instaphp/Instagram/InstagramTest.php
Expand Up @@ -33,7 +33,8 @@ class InstagramTest extends \PHPUnit_Framework_TestCase
'log_level' => \Monolog\Logger::DEBUG,
'log_path' => './instagram_test.log',
'client_ip' => '127.0.0.1',
'debug' => TRUE
'debug' => TRUE,
'verify' => TRUE,
];

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/src/Instaphp/Instagram/TagsTest.php
Expand Up @@ -51,6 +51,14 @@ public function testInfo()
$this->assertNotEmpty($res->data);
}

public function testInfoNonLatin()
{
$res = $this->object->Info('футбол');
$this->assertInstanceOf('\Instaphp\Instagram\Response', $res);
$this->assertNotEmpty($res->data);

}

/**
* @covers Instaphp\Instagram\Tags::Recent
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Instaphp/InstaphpTest.php
Expand Up @@ -29,7 +29,8 @@ class InstaphpTest extends \PHPUnit_Framework_TestCase
'log_level' => \Monolog\Logger::DEBUG,
'log_path' => './instagram_test.log',
'client_ip' => '127.0.0.1',
'debug' => TRUE
'debug' => TRUE,
'verify' => TRUE,
];

/**
Expand Down

0 comments on commit ec856c5

Please sign in to comment.