コード例 #1
0
 public function testParseSearchTweets()
 {
     // Get sample response
     $sampleResponse = $this->sampleResponses['get-search-tweets.json'];
     $response = new Response($sampleResponse, 'json');
     // Get parser
     $parser = new TwitterParser($response);
     // Parse data
     $parser->parseSearchTweets();
     // Test output
     $posts = $parser->getPosts();
     $this->assertEquals(4, count($posts));
     // Test posts
     foreach ($posts as $post) {
         // Test post
         $this->assertInstanceOf('\\Evolution7\\SocialApi\\Entity\\Post', $post);
         // Test user
         $this->assertInstanceOf('\\Evolution7\\SocialApi\\Entity\\User', $post->getUser());
     }
 }
コード例 #2
0
ファイル: Twitter.php プロジェクト: jenalgit/social-api
 /**
  * {@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();
 }