From 6e47c1e8278544c7f817fed129139506cb723555 Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Mon, 9 Apr 2018 12:03:42 +0200 Subject: [PATCH] Rename cursor to endCursor --- README.md | 2 +- src/Instagram/Api.php | 14 +++++++------- src/Instagram/Transport/JsonFeed.php | 8 ++++---- tests/ApiTest.php | 6 ++++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f8fb028..31bae59 100644 --- a/README.md +++ b/README.md @@ -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(); diff --git a/src/Instagram/Api.php b/src/Instagram/Api.php index e3aa56b..89e47df 100644 --- a/src/Instagram/Api.php +++ b/src/Instagram/Api.php @@ -28,9 +28,9 @@ class Api private $userId = null; /** - * @var integer + * @var string */ - private $cursor = false; + private $endCursor = false; /** * @var bool @@ -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; } /** @@ -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'); } @@ -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); } diff --git a/src/Instagram/Transport/JsonFeed.php b/src/Instagram/Transport/JsonFeed.php index 16e12d2..42fa069 100644 --- a/src/Instagram/Transport/JsonFeed.php +++ b/src/Instagram/Transport/JsonFeed.php @@ -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 .= '}'; diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 98e1d7d..caf7ed8 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -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); @@ -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(); @@ -223,6 +223,8 @@ public function testFeedContent() $this->assertSame(30, $feed->getMediaCount()); $this->assertCount(12, $feed->getMedias()); + + $this->assertSame('AQDt7mwufgiNOm233ZFUKmdUv5AqQ3SDYAM9UgY1wC1bjteFPQxRuhm0A6pTEZNRZaYlJIb0bmEQAEtLvwHd6COidVHtBo4Ehx8n7K5n5dJ3dw', $feed->getEndCursor()); } /**