compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (1)

View Page History
{code}
{card}
{card:label=Zend_Service_Twitter_Search}
{code:php}
class Zend_Service_Twitter_Search extends Zend_Http_Client
{
/**
* Return Type
* @var String
*/
protected $_responseType = 'json';

/**
* Response Format Types
* @var array
*/
protected $_responseTypes = array(
'atom',
'json'
);

/**
* Uri Compoent
*
* @var Zend_Uri_Http
*/
protected $_uri;

/**
* Constructor
*
* @param string $returnType
* @return void
*/
public function __construct($responseType = 'json')
{
$this->setResponseType($responseType);
$this->_uri = Zend_Uri_Http::fromString("http://search.twitter.com");

$this->setHeaders('Accept-Charset', 'ISO-8859-1,utf-8');
}

/**
* set responseType
*
* @param string $responseType
* @throws Phly_Twitter_Exception
* @return Phly_Twitter_Search
*/
public function setResponseType($responseType = 'json')
{
if(!in_array($responseType, $this->_responseTypes, TRUE)) {
include_once 'Phly/Twitter/Exception.php';
throw new Phly_Twitter_Exception('Invalid Response Type');
}
$this->_responseType = $responseType;
return $this;
}

/**
* Retrieve responseType
*
* @return string
*/
public function getResponseType()
{
return $this->_responseType;
}

/**
* Get the current twitter trends. Currnetly only supports json as the return.
*
* @return array
*/
public function trends()
{
$this->_uri->setPath('/trends.json');
$this->setUri($this->_uri);
$response = $this->request();

return Zend_Json::decode($response->getBody());
}

public function search($query, array $params = array())
{

$this->_uri->setPath('/search.' . $this->_responseType);
$this->_uri->setQuery(null);

$_query = array();

$_query['q'] = $query;

foreach($params as $key=>$param) {
switch($key) {
case 'geocode':
case 'lang':
$_query[$key] = $param;
break;
case 'rpp':
case 'since_id':
case 'page':
$_query[$key] = intval($param);
break;
case 'show_user':
$_query[$key] = 'true';
}
}

$this->_uri->setQuery($_query);

$this->setUri($this->_uri);
$response = $this->request();

switch($this->_responseType) {
case 'json':
return Zend_Json::decode($response->getBody());
break;
case 'atom':
return Zend_Feed::importString($response->getBody());
break;
}

return ;
}
}
{code}
{card}
{deck}
{zone-data}