Skip to content

Commit

Permalink
Rename cursor to endCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrimaud committed Apr 9, 2018
1 parent 3412aab commit 6e47c1e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ $endCursor = $feed->getEndCursor();
$api = new Api();
$api->setUserId(184263228);
$api->retrieveMediaData(true);
$api->setCursor($endCursor);
$api->setEndCursor($endCursor);

$feed = $api->getFeed();

Expand Down
14 changes: 7 additions & 7 deletions src/Instagram/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Api
private $userId = null;

/**
* @var integer
* @var string
*/
private $cursor = false;
private $endCursor = false;

/**
* @var bool
Expand Down Expand Up @@ -69,11 +69,11 @@ public function setUserName($userName)
}

/**
* @param string $cursor
* @param string $endCursor
*/
public function setCursor($cursor)
public function setEndCursor($endCursor)
{
$this->cursor = $cursor;
$this->endCursor = $endCursor;
}

/**
Expand All @@ -99,7 +99,7 @@ public function getFeed()
throw new InstagramException('You must specify a userName to retrieve userData');
}

if (($this->retrieveMediaData || $this->cursor) && !$this->userId) {
if (($this->retrieveMediaData || $this->endCursor) && !$this->userId) {
throw new InstagramException('You must specify a userId to retrieve mediaData');
}

Expand All @@ -112,7 +112,7 @@ public function getFeed()
}

if ($this->retrieveMediaData) {
$mediaDataFetched = $feed->fetchMediaData($this->userId, $this->cursor);
$mediaDataFetched = $feed->fetchMediaData($this->userId, $this->endCursor);
$hydrator->setMediaData($mediaDataFetched);
}

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 @@ -67,18 +67,18 @@ private function getQueryHash()

/**
* @param $userId
* @param null $cursor
* @param null $endCursor
* @return mixed
* @throws InstagramException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function fetchMediaData($userId, $cursor = null)
public function fetchMediaData($userId, $endCursor = null)
{
$endpoint = self::INSTAGRAM_ENDPOINT . 'graphql/query/?query_hash=' . $this->getQueryHash() . '&variables={"id":"' . $userId . '","first":"12"';


if ($cursor) {
$endpoint .= ',"after":"' . $cursor . '"';
if ($endCursor) {
$endpoint .= ',"after":"' . $endCursor . '"';
}

$endpoint .= '}';
Expand Down
6 changes: 4 additions & 2 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testEmptyUserIdAndCursor()
$this->expectException(InstagramException::class);

$api = new Api($this->validUserClient, $this->validMediaClient);
$api->setCursor(123);
$api->setEndCursor(123);
$api->setUserName('pgrimaud');
$api->retrieveUserData(true);
$api->retrieveMediaData(true);
Expand Down Expand Up @@ -165,7 +165,7 @@ public function testValidFeedWithCursorReturn()
$api = new Api($this->validUserClient, $this->validMediaClient);
$api->setUserName('pgrimaud');
$api->setUserId(12345);
$api->setCursor(1);
$api->setEndCursor('xxxxx');

$api->retrieveMediaData(true);
$feed = $api->getFeed();
Expand Down Expand Up @@ -223,6 +223,8 @@ public function testFeedContent()
$this->assertSame(30, $feed->getMediaCount());

$this->assertCount(12, $feed->getMedias());

$this->assertSame('AQDt7mwufgiNOm233ZFUKmdUv5AqQ3SDYAM9UgY1wC1bjteFPQxRuhm0A6pTEZNRZaYlJIb0bmEQAEtLvwHd6COidVHtBo4Ehx8n7K5n5dJ3dw', $feed->getEndCursor());
}

/**
Expand Down

0 comments on commit 6e47c1e

Please sign in to comment.