Пример #1
0
 public function testParsePostArray()
 {
     // Get sample response
     $sampleResponse = $this->sampleResponses['post.json'];
     $response = new Response($sampleResponse, 'json');
     // Get parser
     $parser = new TwitterParser($response);
     // Parse data
     $post = $parser->parsePostArray($response->getArray());
     // Test post
     $this->assertInstanceOf('\\Evolution7\\SocialApi\\Entity\\Post', $post);
     $this->assertEquals('250075927172759552', $post->getId());
     $this->assertEquals('Aggressive Ponytail #freebandnames', $post->getBody());
     $this->assertNull($post->getMediaType());
     $this->assertNull($post->getMediaUrl());
     $dateTime = new \DateTime();
     $dateTime->setTimestamp(strtotime('Mon Sep 24 03:35:21 +0000 2012'));
     $this->assertEquals($dateTime, $post->getCreated());
     // Test user
     $user = $post->getUser();
     $this->assertInstanceOf('\\Evolution7\\SocialApi\\Entity\\User', $user);
     $this->assertEquals('137238150', $user->getId());
     $this->assertEquals('sean_cummings', $user->getHandle());
     $this->assertEquals('https://twitter.com/sean_cummings', $user->getUrl());
     $this->assertEquals('Sean Cummings', $user->getName());
     $this->assertEquals('//si0.twimg.com/profile_images/2359746665/1v6zfgqo8g0d3mk7ii5s_normal.jpeg', $user->getImageUrl());
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function search(QueryInterface $query)
 {
     // Get library service
     $libService = $this->getLibService();
     // Build search value
     $filters = array();
     if (!is_null($query->getHashtag())) {
         $filters[] = '#' . $query->getHashtag();
     }
     if (!is_null($query->getMedia())) {
         if (in_array('images', $query->getMedia())) {
             $filters[] = 'filter:images';
         }
         if (in_array('videos', $query->getMedia())) {
             $filters[] = 'filter:videos';
         }
     }
     // Build request params
     $requestParams = array('include_entities' => 'true');
     if (count($filters) > 0) {
         $requestParams['q'] = implode(' ', $filters);
     }
     if (!is_null($query->getFrom())) {
         $requestParams['since_id'] = $query->getFrom()->getId();
     }
     if (!is_null($query->getTo())) {
         $requestParams['max_id'] = $query->getTo()->getId();
     }
     if (!is_null($query->getNumResults())) {
         $requestParams['count'] = $query->getNumResults();
     } else {
         $requestParams['count'] = 100;
     }
     // Build request url
     $requestUrl = 'search/tweets.json?' . http_build_query($requestParams, null, '&', PHP_QUERY_RFC3986);
     // Search api
     try {
         $response = new Response($libService->request($requestUrl), 'json');
     } catch (\Exception $e) {
         $this->propogateException($e);
     }
     // Parse response
     $parser = new TwitterParser($response);
     $parser->parseSearchTweets();
     return $parser->getPosts();
 }