Skip to content

Commit

Permalink
Fix stories and profile without external url
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrimaud committed May 27, 2020
1 parent 70dc228 commit 76832ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
23 changes: 13 additions & 10 deletions src/Instagram/Hydrator/StoriesHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Instagram\Hydrator;

use Instagram\Model\ProfileStory;
use Instagram\Model\StoryMedia;

class StoriesHydrator extends AbstractStoryHydrator
{
Expand All @@ -27,17 +26,21 @@ public function __construct()
*/
public function hydrateStories(\StdClass $data): void
{
$this->stories->setOwner($data->owner);
$this->stories->setAllowedToReply($data->can_reply);
$this->stories->setReshareable($data->can_reshare);
if (count($data->reels_media)) {
$medias = current($data->reels_media);

$expiringDate = new \DateTime();
$expiringDate->setTimestamp($data->expiring_at);
$this->stories->setExpiringDate($expiringDate);
$this->stories->setOwner($medias->owner);
$this->stories->setAllowedToReply($medias->can_reply);
$this->stories->setReshareable($medias->can_reshare);

foreach ($data->items as $item) {
$story = $this->hydrateStory($item);
$this->stories->addStory($story);
$expiringDate = new \DateTime();
$expiringDate->setTimestamp($medias->expiring_at);
$this->stories->setExpiringDate($expiringDate);

foreach ($medias->items as $item) {
$story = $this->hydrateStory($item);
$this->stories->addStory($story);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Instagram/Model/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ public function setProfilePicture(string $profilePicture): void
/**
* @return string
*/
public function getExternalUrl(): string
public function getExternalUrl(): ?string
{
return $this->externalUrl;
}

/**
* @param string $externalUrl
*/
public function setExternalUrl(string $externalUrl): void
public function setExternalUrl(?string $externalUrl): void
{
$this->externalUrl = $externalUrl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Instagram/Transport/JsonStoriesDataFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public function fetchData(int $int): \StdClass

$data = $this->fetchJsonDataFeed($endpoint);

return $data->data->reels_media[0];
return $data->data;
}
}

0 comments on commit 76832ed

Please sign in to comment.