From bb2d1d45ada4f203fe0abe941d4ec2cf1d7ceb44 Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Tue, 21 Sep 2021 14:42:00 +0200 Subject: [PATCH] Add more properties in hightlights folder --- .../Hydrator/StoryHighlightsHydrator.php | 9 +++- src/Instagram/Model/StoryHighlightsFolder.php | 42 +++++++++++++++++++ tests/StoriesTest.php | 2 + 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/Instagram/Hydrator/StoryHighlightsHydrator.php b/src/Instagram/Hydrator/StoryHighlightsHydrator.php index 5e6aeba..159641d 100644 --- a/src/Instagram/Hydrator/StoryHighlightsHydrator.php +++ b/src/Instagram/Hydrator/StoryHighlightsHydrator.php @@ -35,10 +35,17 @@ public function hydrateFolders(\StdClass $data): void foreach ($data->edges as $highLight) { $folder = new StoryHighlightsFolder(); + $url = 'https://www.instagram.com/s/' . base64_encode('highlight:' . $highLight->node->id); + $folder->setId((int) $highLight->node->id); + $folder->setUserId((int) $highLight->node->owner->id); $folder->setName($highLight->node->title); $folder->setCover($highLight->node->cover_media_cropped_thumbnail->url); - $folder->setUrl('https://www.instagram.com/s/' . base64_encode('highlight:' . $highLight->node->id)); + $folder->setUrl($url); + $folder->setSharableUrl( + $url . '?story_media_id=' . $highLight->node->id . '_' . $highLight->node->owner->id . + '&utm_medium=copy_link' + ); $this->highlights->addFolder($folder); } diff --git a/src/Instagram/Model/StoryHighlightsFolder.php b/src/Instagram/Model/StoryHighlightsFolder.php index 2f38518..b1545af 100644 --- a/src/Instagram/Model/StoryHighlightsFolder.php +++ b/src/Instagram/Model/StoryHighlightsFolder.php @@ -11,6 +11,11 @@ class StoryHighlightsFolder */ private $id; + /** + * @var int + */ + private $userId; + /** * @var string */ @@ -26,6 +31,11 @@ class StoryHighlightsFolder */ private $url; + /** + * @var string + */ + private $sharableUrl; + /** * @var array */ @@ -115,4 +125,36 @@ public function setUrl(string $url): void { $this->url = $url; } + + /** + * @return string + */ + public function getSharableUrl(): string + { + return $this->sharableUrl; + } + + /** + * @param string $sharableUrl + */ + public function setSharableUrl(string $sharableUrl): void + { + $this->sharableUrl = $sharableUrl; + } + + /** + * @return int + */ + public function getUserId(): int + { + return $this->userId; + } + + /** + * @param int $userId + */ + public function setUserId(int $userId): void + { + $this->userId = $userId; + } } diff --git a/tests/StoriesTest.php b/tests/StoriesTest.php index 63d01da..e671324 100644 --- a/tests/StoriesTest.php +++ b/tests/StoriesTest.php @@ -94,10 +94,12 @@ public function testHighlightsStoriesFetch() $folder = $api->getStoriesOfHighlightsFolder($storyHighlights->getFolders()[0]); $this->assertSame(18137590444014024, $folder->getId()); + $this->assertSame(5670185369, $folder->getUserId()); $this->assertSame('STORY', $folder->getName()); $this->assertSame('https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/s150x150/94263786_546583649377430_3277795491247917640_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_ohc=D6Img4muLocAX_bsIlI&oh=eeeec52698961ee00a070d3e210f532d&oe=5EF1ACCB', $folder->getCover()); $this->assertCount(33, $folder->getStories()); $this->assertSame('https://www.instagram.com/s/aGlnaGxpZ2h0OjE4MTM3NTkwNDQ0MDE0MDI0', $folder->getUrl()); + $this->assertSame('https://www.instagram.com/s/aGlnaGxpZ2h0OjE4MTM3NTkwNDQ0MDE0MDI0?story_media_id=18137590444014024_5670185369&utm_medium=copy_link', $folder->getSharableUrl()); $api->logout('username'); }