1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class extends Horde_Service_Twitter_Request
14: {
15: 16: 17: 18: 19: 20: 21: 22: 23:
24: public function get($url, array $params = array())
25: {
26: $key = md5($url . 'get' . serialize($params) . serialize($this->_twitter->auth->getAccessToken($this->_request)));
27: $cache = $this->_twitter->responseCache;
28: if (!empty($cache) && $results = $cache->get($key, $this->_twitter->cacheLifetime)) {
29: return $results;
30: }
31: $request = new Horde_Oauth_Request($url, $params, 'GET');
32: $request->sign($this->_twitter->auth->oauth->signatureMethod,
33: $this->_twitter->auth->oauth,
34: $this->_twitter->auth->getAccessToken($this->_request));
35: $url = ($url instanceof Horde_Url) ? $url : new Horde_Url($url);
36: $url->add($params);
37: try {
38: $response = $this->_twitter->getHttpClient()->get($url->setRaw(true), array('Authorization' => $request->buildAuthorizationHeader('Twitter API')));
39: } catch (Horde_Http_Exception $e) {
40: throw new Horde_Service_Twitter_Exception($e);
41: }
42:
43:
44:
45: try {
46: $body = $response->getBody();
47: if ($response->code >= 400 && $response->code <= 500) {
48: throw new Horde_Service_Twitter_Exception($body);
49: }
50: } catch (Horde_Http_Exception $e) {}
51:
52: if (!empty($cache)) {
53: $cache->set($key, $body);
54: }
55:
56: return $body;
57: }
58:
59: 60: 61: 62: 63: 64:
65: public function post($url, array $params = array())
66: {
67: $request = new Horde_Oauth_Request($url, $params);
68: $request->sign($this->_twitter->auth->oauth->signatureMethod,
69: $this->_twitter->auth->oauth,
70: $this->_twitter->auth->getAccessToken($this->_request));
71: $url = ($url instanceof Horde_Url) ? $url : new Horde_Url($url);
72: try {
73: $response = $this->_twitter->getHttpClient()->post($url->setRaw(true), $params, array('Authorization' => $request->buildAuthorizationHeader('Twitter API')));
74: } catch (Horde_Http_Exception $e) {
75: throw new Horde_Service_Twitter_Exception($e);
76: }
77:
78: if ($response->code >= 400 && $response->code <= 500) {
79: throw new Horde_Service_Twitter_Exception($response->getBody());
80: }
81: return $response->getBody();
82: }
83:
84: }
85: