Skip to content

Commit

Permalink
Fix hydrate & serialize reels (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmle authored Aug 18, 2022
1 parent e72571c commit 7e9e250
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/Instagram/Hydrator/ReelsHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ public function reelsBaseHydrator(\StdClass $node): Reels
}, $node->video_versions));

if (property_exists($node, 'caption')) {
$reels->setCaption($node->caption->text);
$reels->setHashtags(InstagramHelper::buildHashtags($node->caption->text));
}

if (property_exists($node, 'caption')) {
if (property_exists($node->caption, 'text')) {
if (!empty($node->caption)) {
$reels->setCaption($node->caption->text);
$reels->setHashtags(InstagramHelper::buildHashtags($node->caption->text));
}
}

Expand Down
43 changes: 43 additions & 0 deletions src/Instagram/Model/Reels.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,47 @@ public function getUser(): User
{
return $this->user;
}

/**
* @return array
*/
public function toArray(): array
{
return [
"id" => $this->getId(),
"shortCode" => $this->getShortCode(),
"link" => $this->getLink(),
"likes" => $this->getLikes(),
"isLiked" => $this->isLiked(),
"comments" => $this->getComments(),
"views" => $this->getViews(),
"plays" => $this->getPlays(),
"duration" => $this->getDuration(),
"height" => $this->getHeight(),
"width" => $this->getWidth(),
"hasAudio" => $this->getHasAudio(),
"images" => array_map(function ($image) {
return (array) $image;
}, $this->getImages()),
"videos" => array_map(function ($video) {
return (array) $video;
}, $this->getVideos()),
"caption" => $this->getCaption(),
"location" => $this->getLocation(),
"date" => $this->getDate(),
"hashtags" => $this->getHashtags(),
"userTags" => array_map(function ($user) {
return $user->toArray();
}, $this->getUserTags()),
"user" => $this->getUser()->toArray()
];
}

/**
* @return array
*/
public function __serialize(): array
{
return $this->toArray();
}
}
22 changes: 22 additions & 0 deletions src/Instagram/Model/ReelsFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,26 @@ public function hasMaxId(): bool
{
return $this->getMaxId() !== null;
}

/**
* @return array
*/
public function toArray(): array
{
return [
"reels" => array_map(function ($reels) {
return $reels->toArray();
}, $this->getReels()),
"hasMaxId" => $this->hasMaxId(),
"maxId" => $this->getMaxId(),
];
}

/**
* @return array
*/
public function __serialize(): array
{
return $this->toArray();
}
}

0 comments on commit 7e9e250

Please sign in to comment.