Skip to content

Commit

Permalink
Implement JsonSerializable
Browse files Browse the repository at this point in the history
  • Loading branch information
bissolli committed Jun 15, 2019
1 parent a7b98a9 commit bd140b1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
30 changes: 28 additions & 2 deletions src/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bissolli\TwitterScraper\Models;

class Account extends ModelAbstract
class Account extends ModelAbstract implements \JsonSerializable
{
/**
* Name
Expand Down Expand Up @@ -179,7 +179,7 @@ public function getFavoritesCount()
/**
* @return bool
*/
public function isVerified()
public function getIsVerified()
{
return $this->isVerified;
}
Expand Down Expand Up @@ -251,4 +251,30 @@ public function initProperties($value, $prop)
break;
}
}

/**
* Implements JsonSerializable
*
* @return array|mixed
*/
public function jsonSerialize()
{
return
[
'name' => $this->getName(),
'joined_at' => $this->getJoinedAt(),
'avatar_url' => $this->getAvatarUrl(),
'cover_url' => $this->getCoverUrl(),
'website' => $this->getWebsite(),
'locale' => $this->getLocale(),
'bio' => $this->getBio(),
'following_count' => $this->getFollowingCount(),
'followers_count' => $this->getFollowersCount(),
'tweets_count' => $this->getTweetsCount(),
'favorites_count' => $this->getFavoritesCount(),
'lists_count' => $this->getListsCount(),
'date_of_birth' => $this->getDateOfBirth(),
'is_verified' => $this->getIsVerified(),
];
}
}
22 changes: 21 additions & 1 deletion src/Models/Tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bissolli\TwitterScraper\Models;

class Tweet extends ModelAbstract
class Tweet extends ModelAbstract implements \JsonSerializable
{
/**
* Id
Expand Down Expand Up @@ -149,4 +149,24 @@ public function initProperties($value, $prop)
break;
}
}

/**
* Implements JsonSerializable
*
* @return array|mixed
*/
public function jsonSerialize()
{
return
[
'id' => $this->getId(),
'username' => $this->getUsername(),
'is_retweet' => $this->getisRetweet(),
'content' => $this->getContent(),
'created_at' => $this->getCreatedAt(),
'replies_count' => $this->getRepliesCount(),
'retweets_count' => $this->getRetweetsCount(),
'favorites_count' => $this->getFavoritesCount()
];
}
}

0 comments on commit bd140b1

Please sign in to comment.