Skip to content

Commit

Permalink
Add media count for feed
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrimaud committed Mar 1, 2019
1 parent c244939 commit 86ed7e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
},
"require": {
"ext-json": "*",
"guzzlehttp/guzzle": "^6.3"
},
"require-dev": {
Expand Down
5 changes: 3 additions & 2 deletions src/Instagram/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ public function setAccessToken($token)
}

/**
* @param null $mediaCount
* @return Hydrator\Feed
* @throws InstagramException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getFeed()
public function getFeed($mediaCount = null)
{
if (!$this->userId) {
throw new InstagramException('Missing userId');
Expand All @@ -81,7 +82,7 @@ public function getFeed()
$userDataFetched = $feed->fetchUserData($this->userId);
$hydrator->setUserData($userDataFetched);

$mediaDataFetched = $feed->fetchMediaData($this->userId, $this->maxId);
$mediaDataFetched = $feed->fetchMediaData($this->userId, $this->maxId, $mediaCount);
$hydrator->setMediaData($mediaDataFetched);

return $hydrator->getHydratedData();
Expand Down
8 changes: 4 additions & 4 deletions src/Instagram/Transport/JsonFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ public function fetchUserData($userId)
/**
* @param $userId
* @param null $maxId
* @param int|null $count
* @param int|null $mediaCount
* @return mixed
* @throws InstagramException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function fetchMediaData($userId, $maxId = null, $count = null)
public function fetchMediaData($userId, $maxId = null, $mediaCount = null)
{
$endpoint = self::INSTAGRAM_ENDPOINT . $userId . '/media/recent/?access_token=' . $this->accessToken;

if ($maxId) {
$endpoint .= '&max_id=' . $maxId;
}

if ($count) {
$endpoint .= '&count=' . (int)$count;
if ($mediaCount) {
$endpoint .= '&count=' . (int)$mediaCount;
}

$res = $this->clientMedia->request('GET', $endpoint);
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testValidFeedReturn()
$api->setUserId(1234);
$api->setAccessToken('123.123.1233');

$feed = $api->getFeed();
$feed = $api->getFeed(12);

$this->assertInstanceOf(Feed::class, $feed);
}
Expand Down

0 comments on commit 86ed7e5

Please sign in to comment.