コード例 #1
0
ファイル: SearchTest.php プロジェクト: robertodormepoco/zf2
 public function testSetOptionsWithSearchOptionsByGetter()
 {
     $searchOptions = new Twitter\SearchOptions();
     $searchOptions->setLanguage('en');
     $searchOptions->setResultType('mixed');
     $searchOptions->setResultsPerPage(10);
     $searchOptions->setShowUser(true);
     $searchOptions->setIncludeEntities(false);
     $this->twitter->setOptions($searchOptions);
     $this->assertEquals('en', $this->twitter->getOptions()->getLanguage());
     $this->assertEquals('mixed', $this->twitter->getOptions()->getResultType());
     $response = $this->twitter->execute('zend');
     $this->assertTrue(isset($response['results'][0]) && !isset($response['results'][0]['entities']));
 }
コード例 #2
0
ファイル: Search.php プロジェクト: robertodormepoco/zf2
 /**
  * Performs a Twitter search query.
  *
  * @param  string                           $query   (optional)
  * @param  array|\Traversable|SearchOptions $options (optional)
  * @throws Exception\InvalidArgumentException If query is not defined neither $query nor $options or
  * If query is not a string.
  * @throws Http\Client\Exception\ExceptionInterface
  * @return mixed
  */
 public function execute($query = null, $options = null)
 {
     if (!$options) {
         $options = $this->getOptions();
     } elseif (!$options instanceof SearchOptions) {
         $options = new SearchOptions($options);
     }
     if (is_string($query)) {
         $options->setQuery($query);
     } else {
         if ($query) {
             throw new Exception\InvalidArgumentException('query must be a string');
         }
         if (!$options->getQuery()) {
             throw new Exception\InvalidArgumentException('No query defined');
         }
     }
     $response = $this->restGet('/search.' . $this->responseType, $options->toArray());
     switch ($this->responseType) {
         case 'json':
             return Json\Json::decode($response->getBody(), Json\Json::TYPE_ARRAY);
             break;
         case 'atom':
             return Feed\Reader\Reader::importString($response->getBody());
             break;
     }
     return null;
 }