Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Service/Twitter/Search.php
Go to the documentation of this file.
00001 <?php
00026 require_once 'Zend/Rest/Client.php';
00027 
00031 require_once 'Zend/Json.php';
00032 
00036 require_once 'Zend/Feed.php';
00037 
00046 class Zend_Service_Twitter_Search extends Zend_Rest_Client
00047 {
00052     protected $_responseType = 'json';
00053 
00058     protected $_responseTypes = array(
00059         'atom',
00060         'json'
00061     );
00062 
00068     protected $_uri;
00069 
00076     public function __construct($responseType = 'json')
00077     {
00078         $this->setResponseType($responseType);
00079         $this->setUri("http://search.twitter.com");
00080 
00081         $this->setHeaders('Accept-Charset', 'ISO-8859-1,utf-8');
00082     }
00083 
00091     public function setResponseType($responseType = 'json')
00092     {
00093         if(!in_array($responseType, $this->_responseTypes, TRUE)) {
00094             require_once 'Zend/Service/Twitter/Exception.php';
00095             throw new Zend_Service_Twitter_Exception('Invalid Response Type');
00096         }
00097         $this->_responseType = $responseType;
00098         return $this;
00099     }
00100 
00106     public function getResponseType()
00107     {
00108         return $this->_responseType;
00109     }
00110 
00117     public function trends()
00118     {
00119         $response     = $this->restGet('/trends.json');
00120 
00121         return Zend_Json::decode($response->getBody());
00122     }
00123 
00129     public function search($query, array $params = array())
00130     {
00131 
00132         $_query = array();
00133 
00134         $_query['q'] = $query;
00135 
00136         foreach($params as $key=>$param) {
00137             switch($key) {
00138                 case 'geocode':
00139                 case 'lang':
00140                 case 'since_id':
00141                     $_query[$key] = $param;
00142                     break;
00143                 case 'rpp':
00144                     $_query[$key] = (intval($param) > 100) ? 100 : intval($param);
00145                     break;
00146                 case 'page':
00147                     $_query[$key] = intval($param);
00148                     break;
00149                 case 'show_user':
00150                     $_query[$key] = 'true';
00151             }
00152         }
00153 
00154         $response = $this->restGet('/search.' . $this->_responseType, $_query);
00155 
00156         switch($this->_responseType) {
00157             case 'json':
00158                 return Zend_Json::decode($response->getBody());
00159                 break;
00160             case 'atom':
00161                 return Zend_Feed::importString($response->getBody());
00162                 break;
00163         }
00164 
00165         return ;
00166     }
00167 }
 All Data Structures Namespaces Files Functions Variables Enumerations