Ejemplo n.º 1
0
 /**
  * @param  \stdClass $obj
  * @param  array     $context
  * @return \Twitter\Object\Tweet
  */
 public function unserialize($obj, array $context = [])
 {
     Assertion::true($this->canUnserialize($obj), 'object is not unserializable');
     $createdAt = new \DateTimeImmutable($obj->created_at);
     Assertion::eq(new \DateTimeZone('UTC'), $createdAt->getTimezone());
     return Tweet::create(TwitterMessageId::create($obj->id), $this->userSerializer->unserialize($obj->user), $obj->text, $obj->lang, $createdAt, $obj->entities ? $this->twitterEntitiesSerializer->unserialize($obj->entities) : TwitterEntities::create(), $obj->coordinates ? $this->coordinatesSerializer->unserialize($obj->coordinates) : null, $obj->place ? $this->placeSerializer->unserialize($obj->place) : null, $obj->in_reply_to_status_id, $obj->in_reply_to_user_id, $obj->in_reply_to_screen_name, $obj->retweeted, $obj->retweet_count, $obj->favorited, $obj->favorite_count, $obj->truncated, $obj->source, isset($obj->retweeted_status) ? $this->unserialize($obj->retweeted_status) : null);
 }
 /**
  * @param  \stdClass $directMessage
  * @param  array     $context
  * @return TwitterDirectMessage
  */
 public function unserialize($directMessage, array $context = [])
 {
     Assertion::true($this->canUnserialize($directMessage), 'object is not unserializable');
     $dm = $directMessage->direct_message;
     $createdAt = new \DateTimeImmutable($dm->created_at);
     Assertion::eq(new \DateTimeZone('UTC'), $createdAt->getTimezone());
     return TwitterDirectMessage::create(TwitterMessageId::create($dm->id), $this->userSerializer->unserialize($dm->sender), $this->userSerializer->unserialize($dm->recipient), $dm->text, $createdAt, $this->twitterEntitiesSerializer->canUnserialize($dm->entities) ? $this->twitterEntitiesSerializer->unserialize($dm->entities) : TwitterEntities::create());
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function itShouldBuildTheObject()
 {
     $entities = TwitterEntities::create($this->hashtags, $this->userMentions, $this->urls, $this->media, $this->symbols, $this->extendedEntities);
     $this->assertEquals($this->hashtags, $entities->getHashtags());
     $this->assertEquals($this->symbols, $entities->getSymbols());
     $this->assertEquals($this->urls, $entities->getUrls());
     $this->assertEquals($this->userMentions, $entities->getUserMentions());
     $this->assertEquals($this->media, $entities->getMedia());
     $this->assertEquals($this->extendedEntities, $entities->getExtendedEntities());
 }
Ejemplo n.º 4
0
 /**
  * @param  \stdClass $obj
  * @param  array     $context
  * @return TwitterEntities
  */
 public function unserialize($obj, array $context = [])
 {
     Assertion::true($this->canUnserialize($obj), 'object is not unserializable');
     // Hashtags
     $hashtags = [];
     if (isset($obj->hashtags)) {
         foreach ($obj->hashtags as $hashtag) {
             $hashtags[] = $this->hashtagSerializer->unserialize($hashtag);
         }
     }
     // Symbols
     $symbols = [];
     if (isset($obj->symbols)) {
         foreach ($obj->symbols as $symbol) {
             $symbols[] = $this->symbolSerializer->unserialize($symbol);
         }
     }
     // URLs
     $urls = [];
     if (isset($obj->urls)) {
         foreach ($obj->urls as $url) {
             $urls[] = $this->urlSerializer->unserialize($url);
         }
     }
     // User mentions
     $userMentions = [];
     if (isset($obj->user_mentions)) {
         foreach ($obj->user_mentions as $userMention) {
             $userMentions[] = $this->userMentionSerializer->unserialize($userMention);
         }
     }
     // Media
     $media = [];
     if (isset($obj->media)) {
         foreach ($obj->media as $medium) {
             $media[] = $this->mediaSerializer->unserialize($medium);
         }
     }
     // Extended entities
     $extendedEntities = [];
     if (isset($obj->extended_entities)) {
         foreach ($obj->extended_entities as $extendedEntity) {
             $extendedEntities[] = $this->extendedEntitySerializer->unserialize($extendedEntity);
         }
     }
     return TwitterEntities::create($hashtags, $userMentions, $urls, $media, $symbols, $extendedEntities);
 }
Ejemplo n.º 5
0
 /**
  * @return TwitterEntities
  */
 private function getTwitterEntities()
 {
     $twitterEntities = TwitterEntities::create([$this->hashtag], [$this->userMention], [$this->url], [$this->medium], [$this->symbol], [$this->extendedEntity]);
     return $twitterEntities;
 }