Skip to content

Commit

Permalink
Add mentions retrieval on stories #153
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrimaud committed Nov 5, 2020
1 parent 8dff555 commit dfc1139
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Instagram/Hydrator/AbstractStoryHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ protected function hydrateStory(\StdClass $item): StoryMedia
}

$hashtags = [];
$mentions = [];

// extract tags (tappable_objects)
// tappable objects
foreach ($item->tappable_objects as $object) {
if ($object->__typename === 'GraphTappableHashtag') {
$hashtags[] = $object->name;
switch ($object->__typename) {
case 'GraphTappableHashtag':
$hashtags[] = $object->name;
break;
case 'GraphTappableMention':
$mentions[] = $object->username;
break;
}
}

$story->setHashtags($hashtags);
$story->setMentions($mentions);

return $story;
}
Expand Down
21 changes: 21 additions & 0 deletions src/Instagram/Model/StoryMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class StoryMedia
*/
private $hashtags;

/**
* @var array
*/
private $mentions;

/**
* @return int
*/
Expand Down Expand Up @@ -278,4 +283,20 @@ public function getHashtags(): array
{
return $this->hashtags;
}

/**
* @param array $mentions
*/
public function setMentions(array $mentions): void
{
$this->mentions = $mentions;
}

/**
* @return array
*/
public function getMentions(): array
{
return $this->mentions;
}
}
1 change: 1 addition & 0 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public function testValidStoriesFetch()
$this->assertCount(3, $story->getDisplayResources());
$this->assertTrue($story->isAudio());
$this->assertCount(1, $story->getHashtags());
$this->assertCount(1, $story->getMentions());
}

$api->logout('username');
Expand Down

0 comments on commit dfc1139

Please sign in to comment.