*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Service / Twitter / Search.php
bloba1c93d6a056c8c5316c0e953a231492fd8639b19
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Service
17 * @subpackage Twitter
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Search.php 16971 2009-07-22 18:05:45Z mikaelkael $
23 /**
24 * @see Zend_Http_Client
26 require_once 'Zend/Http/Client.php';
28 /**
29 * @see Zend_Uri_Http
31 require_once 'Zend/Uri/Http.php';
33 /**
34 * @see Zend_Json
36 require_once 'Zend/Json.php';
38 /**
39 * @see Zend_Feed
41 require_once 'Zend/Feed.php';
43 /**
44 * @category Zend
45 * @package Zend_Service
46 * @subpackage Twitter
47 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
48 * @license http://framework.zend.com/license/new-bsd New BSD License
51 class Zend_Service_Twitter_Search extends Zend_Http_Client
53 /**
54 * Return Type
55 * @var String
57 protected $_responseType = 'json';
59 /**
60 * Response Format Types
61 * @var array
63 protected $_responseTypes = array(
64 'atom',
65 'json'
68 /**
69 * Uri Compoent
71 * @var Zend_Uri_Http
73 protected $_uri;
75 /**
76 * Constructor
78 * @param string $returnType
79 * @return void
81 public function __construct($responseType = 'json')
83 $this->setResponseType($responseType);
84 $this->_uri = Zend_Uri_Http::fromString("http://search.twitter.com");
86 $this->setHeaders('Accept-Charset', 'ISO-8859-1,utf-8');
89 /**
90 * set responseType
92 * @param string $responseType
93 * @throws Zend_Service_Twitter_Exception
94 * @return Zend_Service_Twitter_Search
96 public function setResponseType($responseType = 'json')
98 if(!in_array($responseType, $this->_responseTypes, TRUE)) {
99 require_once 'Zend/Service/Twitter/Exception.php';
100 throw new Zend_Service_Twitter_Exception('Invalid Response Type');
102 $this->_responseType = $responseType;
103 return $this;
107 * Retrieve responseType
109 * @return string
111 public function getResponseType()
113 return $this->_responseType;
117 * Get the current twitter trends. Currnetly only supports json as the return.
119 * @return array
121 public function trends()
123 $this->_uri->setPath('/trends.json');
124 $this->setUri($this->_uri);
125 $response = $this->request();
127 return Zend_Json::decode($response->getBody());
130 public function search($query, array $params = array())
133 $this->_uri->setPath('/search.' . $this->_responseType);
134 $this->_uri->setQuery(null);
136 $_query = array();
138 $_query['q'] = $query;
140 foreach($params as $key=>$param) {
141 switch($key) {
142 case 'geocode':
143 case 'lang':
144 case 'since_id':
145 $_query[$key] = $param;
146 break;
147 case 'rpp':
148 $_query[$key] = (intval($param) > 100) ? 100 : intval($param);
149 break;
150 case 'page':
151 $_query[$key] = intval($param);
152 break;
153 case 'show_user':
154 $_query[$key] = 'true';
158 $this->_uri->setQuery($_query);
160 $this->setUri($this->_uri);
161 $response = $this->request();
163 switch($this->_responseType) {
164 case 'json':
165 return Zend_Json::decode($response->getBody());
166 break;
167 case 'atom':
168 return Zend_Feed::importString($response->getBody());
169 break;
172 return ;