package.xml0000664000076500000240000003156312535652765010143 0ustar Horde_Service_Twitter pear.horde.org Horde Twitter client Client libraries for the Twitter REST API. Michael J Rubinsky mrubinsk mrubinsk@horde.org yes 2015-06-09 2.1.5 2.1.0 stable stable BSD-2-Clause * [mjr] Remove obsolete end_session endpoint. 5.3.0 6.0.0alpha1 6.0.0alpha1 1.7.0 Horde_Controller pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Exception pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Http pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Oauth pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Url pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Util pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 1.0.0alpha1 1.0.0 alpha alpha 2011-03-08 BSD-2-Clause * First alpha release for Horde 4. 1.0.0beta1 1.0.0 beta beta 2011-03-16 BSD-2-Clause * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 BSD-2-Clause * First release candidate for Horde 4. 1.0.0RC2 1.0.0 beta beta 2011-03-29 BSD-2-Clause * Second release candidate for Horde 4. 1.0.0 1.0.0 stable stable 2011-04-06 BSD-2-Clause * First stable release for Horde 4. 1.1.0 1.1.0 stable stable 2011-05-06 BSD-2-Clause * [jan] Add CLI client example. * [jan] Add Horde_Services_Twitter::create() factory method. 1.1.1 1.1.0 stable stable 2011-10-06 BSD-2-Clause * [mjr] Fix oauth endpoints to reflect Twitter's new requirements for https requests. 1.1.2 1.1.0 stable stable 2011-10-11 BSD-2-Clause * [mjr] Fix generating OAuth request when multiple URL parameters are passed. 1.1.3 1.1.0 stable stable 2011-10-18 BSD-2-Clause * [gwr] Fixed posting tweets. 1.1.4 1.1.0 stable stable 2012-06-28 BSD-2-Clause * [mjr] Update API endpoints. 2.0.0alpha1 1.1.0 alpha stable 2012-07-05 BSD-2-Clause * First alpha release for Horde 5. * [mjr] Update API endpoints. 2.0.0beta1 1.1.0 beta stable 2012-07-19 BSD-2-Clause * First beta release for Horde 5. 2.0.0 1.1.0 stable stable 2012-10-30 BSD-2-Clause * First stable release for Horde 5. 2.0.1 1.1.0 stable stable 2012-11-22 BSD-2-Clause * [jan] Re-packaged 2.0.0 release. 2.0.2 1.1.0 stable stable 2013-03-05 BSD-2-Clause * [jan] Fix examples location. 2.0.3 1.1.0 stable stable 2013-03-05 BSD-2-Clause * [mjr] Fix initial authentication for recently changed Twitter API requirements (Bug #12165). 2.1.0 2.1.0 stable stable 2013-06-17 BSD-2-Clause * [mjr] Use API version 1.1 * [mjr] Add support for favorites. 2.1.1 2.1.0 stable stable 2013-07-07 BSD-2-Clause * [mjr] Fix fetching user mentions. 2.1.2 2.1.0 stable stable 2015-01-09 BSD-2-Clause * [jan] Add Composer definition. 2.1.3 2.1.0 stable stable 2015-03-04 BSD-2-Clause * [mjr] Fix fatal error when using pecl_http2. 2.1.4 2.1.0 stable stable 2015-04-28 BSD-2-Clause * [jan] Fix issues with certain locales like Turkish. 2.1.5 2.1.0 stable stable 2015-06-09 BSD-2-Clause * [mjr] Remove obsolete end_session endpoint. Horde_Service_Twitter-2.1.5/doc/Horde/Service/Twitter/examples/twitter_browser.php0000664000076500000240000000623612535652765025375 0ustar * @author Michael J. Rubinsky * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ require_once __DIR__ . '/../lib/base.php'; /* Keys - these are obtained when registering for the service */ $consumer_key = '********'; $consumer_secret = '*********'; /* Used to obtain an unprivileged request token */ $token_url = 'http://twitter.com/oauth/request_token'; /* Used for allowing the user to allow/deny access to the application */ // (User is redirected to this URL if needed). $auth_url = 'http://twitter.com/oauth/authorize'; // Used to obtain an access token after user authorizes the application $accessToken_url = 'http://twitter.com/oauth/access_token'; /* Parameters required for the Horde_Oauth_Consumer */ $params = array('key' => $consumer_key, 'secret' => $consumer_secret, 'requestTokenUrl' => $token_url, 'authorizeTokenUrl' => $auth_url, 'accessTokenUrl' => $accessToken_url, 'signatureMethod' => new Horde_Oauth_SignatureMethod_HmacSha1()); /* Create the Consumer */ $oauth = new Horde_Oauth_Consumer($params); /* Create the Twitter client */ $twitter = new Horde_Service_Twitter(array('oauth' => $oauth, 'request' => new Horde_Controller_Request_Http())); /* At this point we would check for an existing, valid authorization token */ // $auth_token should be a Horde_Oauth_Token object // $auth_token = getTokenFromStorage(); // Do we have a good auth token? Keep in mind this is example code, and in a true // callback page we probably wouldn't be doing anything if we already have a token, // but for testing purposes.... if (!empty($auth_token)) { /* Have a token, tell the Twitter client about it */ $twitter->auth->setToken($auth_token); // Do something cool.... // $twitter->statuses->update('Testing Horde/Twitter integration'); } elseif (!empty($_SESSION['twitter_request_secret'])) { /* No existing auth token, maybe we are in the process of getting it? */ $a_token = $twitter->auth->getAccessToken(new Horde_Controller_Request_Http(), $_SESSION['twitter_request_secret']); // Clear the request secret from the session now that we're done with it, // again, using _SESSION for simplicity for this example $_SESSION['twitter_request_secret'] = ''; if ($a_token === false || empty($a_token)) { // We had a request secret, but something went wrong. maybe navigated // back here between requests? echo 'error'; die; } else { // We have a good token, save it to DB etc.... var_dump($a_token); die; } } // No auth token, not in the process of getting one...ask user to verify $results = $twitter->auth->getRequestToken(); $_SESSION['twitter_request_secret'] = $results->secret; // Redirect to auth url Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false)->redirect(); Horde_Service_Twitter-2.1.5/doc/Horde/Service/Twitter/examples/twitter_cli.php0000775000076500000240000000206612535652765024461 0ustar #!/usr/bin/env php * @author Michael J. Rubinsky * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ /* Keys - these are obtained when registering for the service */ $keys = array( 'consumer_key' => '*****', 'consumer_secret' => '*****', 'access_token' => '*****-*****', 'access_token_secret' => '*****' ); /* Enable autoloading. */ require 'Horde/Autoloader/Default.php'; /* Create the Twitter client */ $twitter = Horde_Service_Twitter::create(array('oauth' => $keys)); /* Do something cool.... */ try { $result = $twitter->statuses->update('Testing Horde/Twitter integration 2'); print_r(Horde_Serialize::unserialize($result, Horde_Serialize::JSON)); } catch (Horde_Service_Twitter_Exception $e) { $error = Horde_Serialize::unserialize($e->getMessage(), Horde_Serialize::JSON); echo "$error->error\n"; } Horde_Service_Twitter-2.1.5/doc/Horde/Service/Twitter/COPYING0000664000076500000240000000243012535652765020624 0ustar Copyright 1999-2015 Horde LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HORDE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter/Auth/Oauth.php0000664000076500000240000000533612535652765022274 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ class Horde_Service_Twitter_Auth_Oauth extends Horde_Service_Twitter_Auth { /** * * @var Horde_OAuth_Token */ protected $_token; public function __construct(Horde_OAuth_Consumer $oauth) { $this->_config['oauth'] = $oauth; } /** * Obtain the URL used to get an authorization token. * * @param Horde_Oauth_Token $requestToken The request token * * @return string The Url */ public function getUserAuthorizationUrl($requestToken) { return $this->oauth->getUserAuthorizationUrl($requestToken); } /** * Set the access token * * @param Horde_OAuth_Token $token */ public function setToken(Horde_OAuth_Token $token) { $this->_token = $token; } /** * Obtain the access token. This is the token that should be persisted to * storage. * * @param Horde_Controller_Request_Http Http request object * @param string $requestSecret The token secret returned by * Twitter after the user authorizes * the application. * @return Horde_Oauth_Token * @throws Horde_Service_Twitter_Exception */ public function getAccessToken(Horde_Controller_Request_Http $request, $requestSecret = null) { if (!empty($this->_token)) { return $this->_token; } $params = $request->getGetVars(); if (empty($params['oauth_token'])) { return false; } $token = new Horde_Oauth_Token($params['oauth_token'], $requestSecret); try { return $this->oauth->getAccessToken($token, array('oauth_verifier' => $requestSecret)); } catch (Horde_Oauth_Exception $e) { throw new Horde_Service_Twitter_Exception($e->getMessage()); } } /** * Obtain the OAuth request token * * @param array $params * * @return Horde_OAuth_Token The request token * @throws Horde_Service_Twitter_Exception */ public function getRequestToken($params = array()) { try { return $this->oauth->getRequestToken($params); } catch (Horde_Oauth_Exception $e) { throw new Horde_Service_Twitter_Exception($e->getMessage()); } } } Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter/Request/Oauth.php0000664000076500000240000000642612535652765023024 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ class Horde_Service_Twitter_Request_Oauth extends Horde_Service_Twitter_Request { /** * Perform a GET request with OAuth authorization. * * @param mixed (string | Horde_Url) $url The url to request. * @param array $params URL parameters. * * @return string Call results. * @throws Horde_Service_Twitter_Exception */ public function get($url, array $params = array()) { $key = md5($url . 'get' . serialize($params) . serialize($this->_twitter->auth->getAccessToken($this->_request))); $cache = $this->_twitter->responseCache; if (!empty($cache) && $results = $cache->get($key, $this->_twitter->cacheLifetime)) { return $results; } $request = new Horde_Oauth_Request($url, $params, 'GET'); $request->sign($this->_twitter->auth->oauth->signatureMethod, $this->_twitter->auth->oauth, $this->_twitter->auth->getAccessToken($this->_request)); $url = ($url instanceof Horde_Url) ? $url : new Horde_Url($url); $url->add($params); try { $response = $this->_twitter->getHttpClient()->get((string)$url->setRaw(true), array('Authorization' => $request->buildAuthorizationHeader('Twitter API'))); } catch (Horde_Http_Exception $e) { throw new Horde_Service_Twitter_Exception($e); } // Looks like some of the http clients (like Fopen) will thrown an // exception if we try to read an empty stream. Ignore this. try { $body = $response->getBody(); if ($response->code >= 400 && $response->code <= 500) { throw new Horde_Service_Twitter_Exception($body); } } catch (Horde_Http_Exception $e) {} if (!empty($cache)) { $cache->set($key, $body); } return $body; } /** * Send a POST request to the twitter API. Purposely do not cache results * from these since POST requests alter data on the server. * * @see self::get */ public function post($url, array $params = array()) { $request = new Horde_Oauth_Request($url, $params); $request->sign($this->_twitter->auth->oauth->signatureMethod, $this->_twitter->auth->oauth, $this->_twitter->auth->getAccessToken($this->_request)); $url = ($url instanceof Horde_Url) ? $url : new Horde_Url($url); try { $response = $this->_twitter->getHttpClient()->post((string)$url->setRaw(true), $params, array('Authorization' => $request->buildAuthorizationHeader('Twitter API'))); } catch (Horde_Http_Exception $e) { throw new Horde_Service_Twitter_Exception($e); } if ($response->code >= 400 && $response->code <= 500) { throw new Horde_Service_Twitter_Exception($response->getBody()); } return $response->getBody(); } } Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter/Account.php0000664000076500000240000000516212535652765021704 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ class Horde_Service_Twitter_Account { /** * Twitter endpoint for account api calls * * @var string */ protected $_endpoint = 'https://api.twitter.com/1.1/account/'; /** * The request/response format to use, xml or json. * * @var string */ protected $_format = 'json'; /** * * @param Horde_Service_Twitter $twitter */ public function __construct($twitter) { $this->_twitter = $twitter; } /** * Used to verify current credentials, and obtain some basic profile * information about the current user. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0verify_credentials * * @return string JSON reprentation of profile. * @throws Horde_Service_Twitter_Exception */ public function verifyCredentials() { $url = $this->_endpoint . 'verify_credentials.' . $this->_format; return $this->_twitter->request->get($url); } /** * Obtain the current user's (if authenticated) or IP address' (if not * authenticated) remaining number of requests left for the hour. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0rate_limit_status * * @return string JSON representation of result object. */ public function rateLimitStatus() { $url = $this->_endpoint . 'rate_limit_status.' . $this->_format; return $this->_twitter->request->get($url); } /** * Ends the current session, invalidates the current auth token if using * OAuth. * * @return string */ public function endSession() { // NOOP - no longer part of the Twitter API, no replacement. } /** * Update/reset where twitter sends automatic updates to * (im/sms etc...) * * @TODO * @param string $device * * @return void */ public function updateDeliveryDevice($device = '') { } /** * Update user's profile data. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0update_profile * * @TODO * @param array $profile Profile data see API docs for key-values * * @return string JSON representation of user's updated profile data */ public function updateProfile($profile) { } } Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter/Auth.php0000664000076500000240000000211712535652765021206 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ abstract class Horde_Service_Twitter_Auth { /** * * @var Horde_Service_Twitter */ protected $_twitter; /** * Configuration parameters * * @param array */ protected $_config; public function setTwitter(Horde_Service_Twitter $twitter) { $this->_twitter = $twitter; } /** * Getter * * @param string $value * * @return mixed The value of the requested property. * @throws Horde_Service_Twitter_Exception */ public function __get($value) { if (!empty($this->_config[$value])) { return $this->_config[$value]; } throw new Horde_Service_Twitter_Exception(sprintf("The property %s does not exist", $value)); } } Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter/Exception.php0000664000076500000240000000045512535652765022246 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ class Horde_Service_Twitter_Exception extends Horde_Exception_Wrapped { } Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter/Favorites.php0000664000076500000240000000320012535652765022241 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ class Horde_Service_Twitter_Favorites { /** * Endpoint for status api requests * * @var string */ private $_endpoint = 'https://api.twitter.com/1.1/favorites/'; /** * Format to use json or xml * * @var string */ private $_format = 'json'; /** * Constructor * * @param Horde_Service_Twitter $twitter */ public function __construct($twitter) { $this->_twitter = $twitter; } /** * Obtain the requested status * * @return string The method call results. */ public function get() { $url = $this->_endpoint . 'list.' . $this->_format; return $this->_twitter->request->post($url); } /** * Destroy the specified favorite. * * @param string $id The status id * * @return string */ public function destroy($id) { $url = $this->_endpoint . 'destroy.' . $this->_format; return $this->_twitter->request->post($url, array('id' => $id)); } /** * Add a new favorite * * @param string $id The status id * * @return string The favorited tweet. */ public function create($id) { $url = $this->_endpoint . 'create.' . $this->_format; return $this->_twitter->request->post($url, array('id' => $id)); } }Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter/Request.php0000664000076500000240000000166212535652765021741 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ abstract class Horde_Service_Twitter_Request { /** * * @var Horde_Service_Twitter */ protected $_twitter; /** * * @var Horde_Controller_Request_Http */ protected $_request; public function __construct(Horde_Controller_Request_Http $request) { $this->_request = $request; } public function setTwitter(Horde_Service_Twitter $twitter) { $this->_twitter = $twitter; } abstract public function get($url, array $params = array()); abstract public function post($url, array $params = array()); } Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter/Statuses.php0000664000076500000240000002745212535652765022131 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ class Horde_Service_Twitter_Statuses { /** * Endpoint for status api requests * * @var string */ private $_endpoint = 'https://api.twitter.com/1.1/statuses/'; /** * Format to use json or xml * * @var string */ private $_format = 'json'; /** * Constructor * * @param Horde_Service_Twitter $twitter */ public function __construct($twitter) { $this->_twitter = $twitter; } /** * Obtain the requested status * * @return string The method call results. */ public function show($id) { $url = $this->_endpoint . 'show.' . $this->_format; return $this->_twitter->request->post($url, array('id' => $id)); } /** * Destroy the specified status update, obviously only if the current user * is the author of the update. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0destroy * * @param string $id The status id * * @return string */ public function destroy($id) { $url = $this->_endpoint . 'destroy.' . $this->_format; return $this->_twitter->request->post($url, array('id' => $id)); } /** * Update the current user's status. * * @param string $status The new status text. * @param array $params Any additional parameters. *
     *     in_reply_to_status_id  - the status id this tweet is in response to.
     *   
* * @return string */ public function update($status, $params = array()) { $url = $this->_endpoint . 'update.' . $this->_format; $params['status'] = $status; return $this->_twitter->request->post($url, $params); } /** * Obtain the friendsTimeline. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-friends_timeline * * NOTE: According to the API docs, this method is deprecated and will be * going away in a future version of the API. This is to be replaced by * home_timeline. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-home_timeline * * @param array $params Parameters for the friends_timeline call *
     *     since_id         - Only tweets more recent the indicated tweet id
     *     max_id           - Only tweets older then the indeicated tweet id
     *     count            - Only return this many tweets (twitter limit = 200)
     *     page             - The page number to return (note there are
     *                        pagination limits)
     *     include_rts      - Include retweets
     *     include_entities - Include twitter entities (will be mandatory in
     *                        future twitter api release).
     *   
* * @return string */ public function friendsTimeline($params = array()) { $url = $this->_endpoint . 'friends_timeline.' . $this->_format; return $this->_twitter->request->get($url, $params); } /** * Returns the 20 most recent statuses, including retweets, posted by the * authenticating user and that user's friends. This is the equivalent of * /timeline/home on the Web. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-home_timeline * * @param array $params Parameters for the friends_timeline call *
     *     since_id   - Only tweets more recent the indicated tweet id
     *     max_id     - Only tweets older then the indeicated tweet id
     *     count      - Only return this many tweets (twitter limit = 200)
     *     page       - The page number to return (note there are pagination limits)
     *   
* * @return string */ public function homeTimeline($params = array()) { $url = $this->_endpoint . 'home_timeline.' . $this->_format; return $this->_twitter->request->get($url, $params); } /** * Returns the 20 most recent retweets posted by the authenticating user. * * @param array $params Parameters for the friends_timeline call *
     *     since_id   - Only tweets more recent the indicated tweet id
     *     max_id     - Only tweets older then the indeicated tweet id
     *     count      - Only return this many tweets (twitter limit = 200)
     *     page       - The page number to return (note there are pagination limits)
     *   
* * @return string */ public function retweetedByMe($params = array()) { $url = $this->_endpoint . 'retweeted_by_me.' . $this->_format; return $this->_twitter->request->get($url, $params); } /** * Returns the 20 most recent retweets posted by the authenticating user's * friends. * * @param array $params Parameters for the friends_timeline call *
     *     since_id   - Only tweets more recent the indicated tweet id
     *     max_id     - Only tweets older then the indeicated tweet id
     *     count      - Only return this many tweets (twitter limit = 200)
     *     page       - The page number to return (note there are pagination limits)
     *   
* * @return string */ public function retweetedToMe($params = array()) { $url = $this->_endpoint . 'retweetedToMe.' . $this->_format; return $this->_twitter->request->get($url, $params); } /** * Returns the 20 most recent tweets of the authenticated user that have * been retweeted by others. * * @param array $params Parameters for the friends_timeline call *
     *     since_id   - Only tweets more recent the indicated tweet id
     *     max_id     - Only tweets older then the indeicated tweet id
     *     count      - Only return this many tweets (twitter limit = 200)
     *     page       - The page number to return (note there are pagination limits)
     *   
* * @return string */ public function retweetsOfMe($params = array()) { $url = $this->_endpoint . 'retweets_of_me.' . $this->_format; return $this->_twitter->request->get($url, $params); } /** * Retweets a tweet. Requires the id parameter of the tweet you are * retweeting. Request must be a POST or PUT. * Returns the original tweet with retweet details embedded. * * @params string id The id for the tweet that is being retweeted. * * @return string */ public function retweet($id) { $url = $this->_endpoint . 'retweet/' . $id . '.' . $this->_format; return $this->_twitter->request->post($url, array()); } /** * Obtain the last 20 tweets from the public timeline. This is cached every * 60 seconds on Twitter's servers so we should eventually ensure this is * only actually requested every 60 seconds or greater. * * @return string */ public function publicTimeline() { $url = $this->_endpoint . 'public_timeline.' . $this->_format; return $this->_twitter->request->get($url); } /** * Obtain the friendsTimeline. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline * * @param array $params Parameters for the friends_timeline call *
     *     id         - For this user id or screen name.
     *                  Current user if left out.
     *     user_id    - Specfies the ID of the user for whom to return the
     *                  user_timeline. Helpful for disambiguating when a valid
     *                  user ID is also a valid screen name.
     *     screen_id  - Specfies the screen name of the user for whom to return
     *                  the user_timeline. Helpful for disambiguating when a
     *                  valid screen name is also a user ID.
     *     since_id   - Only tweets more recent the indicated tweet id
     *     max_id     - Only tweets older then the indeicated tweet id
     *     count      - Only return this many tweets (twitter limit = 200)
     *     page       - The page number to return (note there are pagination limits)
     *   
* * @return string */ public function userTimeline($params = array()) { $url = $this->_endpoint . 'user_timeline.' . $this->_format; return $this->_twitter->request->get($url, $params); } /** * Obtain most recent 'mentions' for the current user. (i.e. all messages * that contain @username in the text). * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-mentions * * @param array $params Parameters for the friends_timeline call *
     *     since_id   - Only tweets more recent the indicated tweet id
     *     max_id     - Only tweets older then the indeicated tweet id
     *     count      - Only return this many tweets (twitter limit = 200)
     *     page       - The page number to return (note there are pagination limits)
     *   
* * @return string */ public function mentions($params = array()) { $url = $this->_endpoint . 'mentions_timeline.' . $this->_format; return $this->_twitter->request->get($url, $params); } /** * Returns a user's friends, each with current status inline. They are * ordered by the order in which they were added as friends, 100 at a time. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0friends * * @param array $params Parameters for the friends_timeline call *
     *     id         - For this user id or screen name.
     *                  Current user if left out.
     *     user_id    - Specfies the ID of the user for whom to return the
     *                  user_timeline. Helpful for disambiguating when a valid
     *                  user ID is also a valid screen name.
     *     screen_id  - Specfies the screen name of the user for whom to return
     *                  the user_timeline. Helpful for disambiguating when a
     *                  valid screen name is also a user ID.
     *     page       - The page number to return (note there are pagination limits)
     *   
* @return unknown_type */ public function friends($params = array()) { $url = $this->_endpoint . 'friends.' . $this->_format; return $this->_twitter->request->get($url, $params); } /** * Returns a user's followers, each with current status inline. They are * ordered by the order in which they were added as friends, 100 at a time. * * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0friends * * @param array $params Parameters for the friends_timeline call *
     *     id         - For this user id or screen name.
     *                  Current user if left out.
     *     user_id    - Specfies the ID of the user for whom to return the
     *                  user_timeline. Helpful for disambiguating when a valid
     *                  user ID is also a valid screen name.
     *     screen_id  - Specfies the screen name of the user for whom to return
     *                  the user_timeline. Helpful for disambiguating when a
     *                  valid screen name is also a user ID.
     *     page       - The page number to return (note there are pagination limits)
     *   
* @return unknown_type */ public function followers($params = array()) { $url = $this->_endpoint . 'followers.' . $this->_format; return $this->_twitter->request->get($url, $params); } } Horde_Service_Twitter-2.1.5/lib/Horde/Service/Twitter.php0000664000076500000240000001617512535652765020316 0ustar * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ /** * Horde_Service_Twitter class abstracts communication with Twitter's * rest interface. * * @property-read Horde_Service_Twitter_Account $account * The twitter account object for calling account methods. * @property-read Horde_Service_Twitter_Statuses $statuses * The twitter status object for updating and retrieving user * statuses. * @property-read Horde_Service_Twitter_Auth $auth * The twitter authentication object. * @property-read Horde_Service_Twitter_Request $request * The twitter request object that wraps sending requests to * Twitter's REST API. * @property-read Horde_Cache $responseCache * The cache object. * @property-read integer $cacheLifetime * The default cache lifetime. * * @author Michael J. Rubinsky * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ class Horde_Service_Twitter { /* Constants */ const REQUEST_TOKEN_URL = 'https://api.twitter.com/oauth/request_token'; const USER_AUTHORIZE_URL = 'https://api.twitter.com/oauth/authorize'; const ACCESS_TOKEN_URL = 'https://api.twitter.com/oauth/access_token'; /** * Cache for the various objects we lazy load in __get() * * @var hash of Horde_Service_Twitter_* objects */ protected $_objCache = array(); /** * (Optional) Cache object. * * @var Horde_Cache */ protected $_responseCache; /** * Default cache lifetime. * * @var integer */ protected $_cacheLifetime = 300; /** * Optional logger. * * @var Horde_Log_Logger */ protected $_logger; /** * Can't lazy load the auth or request class since we need to know early if * we are OAuth or Basic * * @var Horde_Service_Twitter_Auth */ protected $_auth; /** * The twitter request object. * * @var Horde_Service_Twitter_Request */ protected $_request; /** * The http client. * * @var Horde_Http_Client */ protected $_httpClient; /** * Constructor. * * @param Horde_Service_Twitter_Auth $auth An authentication object * @param Horde_Service_Twitter_Request $request A request object. */ public function __construct(Horde_Service_Twitter_Auth $auth, Horde_Service_Twitter_Request $request) { $this->_auth = $auth; $this->_auth->setTwitter($this); $this->_request = $request; $this->_request->setTwitter($this); } /** * Factory method to easily build a working Twitter client object. * * @param array $params Configuration parameters, with the following keys: * - 'oauth' (required): * - 'consumer_key' (required): The application's * consumer key * - 'consumer_secret' (required): The application's * consumer secret * - 'access_token' (optional): The user's access * token * - 'access_token_secret' (optional): The user's * access token secret. * - 'http' (optional): any configuration parameters * for Horde_Http_Client, e.g. proxy settings. * * @return Horde_Service_Twitter A twitter object that can be used * immediately to update and receive * statuses etc. */ public static function create($params) { if (!isset($params['oauth'])) { throw new Horde_Service_Twitter_Exception('Only OAuth authentication is supported.'); } /* Parameters required for the Horde_Oauth_Consumer */ $consumer_params = array( 'key' => $params['oauth']['consumer_key'], 'secret' => $params['oauth']['consumer_secret'], 'requestTokenUrl' => self::REQUEST_TOKEN_URL, 'authorizeTokenUrl' => self::USER_AUTHORIZE_URL, 'accessTokenUrl' => self::ACCESS_TOKEN_URL, 'signatureMethod' => new Horde_Oauth_SignatureMethod_HmacSha1()); /* Create the Consumer */ $oauth = new Horde_Oauth_Consumer($consumer_params); /* Create the Twitter client */ $twitter = new Horde_Service_Twitter( new Horde_Service_Twitter_Auth_Oauth($oauth), new Horde_Service_Twitter_Request_Oauth( new Horde_Controller_Request_Http())); /* Create HTTP client. */ $http_params = isset($params['http']) ? $params['http'] : array(); $twitter->setHttpClient(new Horde_Http_Client($http_params)); /* Check for an existing token */ if (!empty($params['oauth']['access_token']) && !empty($params['oauth']['access_token_secret'])) { $auth_token = new Horde_Oauth_Token( $params['oauth']['access_token'], $params['oauth']['access_token_secret']); $twitter->auth->setToken($auth_token); } return $twitter; } public function setCache(Horde_Cache $cache) { $this->_responseCache = $cache; } public function setLogger(Horde_Log_Logger $logger) { $this->_logger = $logger; } /** * Set the http client. * * @param Horde_Http_Client $client The http client */ public function setHttpClient(Horde_Http_Client $client) { $this->_httpClient = $client; } /** * Get the http client. * * @return Horde_Http_Client */ public function getHttpClient() { return $this->_httpClient; } /** * Lazy load the twitter classes. * * @param string $value The lowercase representation of the subclass. * * @throws Horde_Service_Twitter_Exception * @return Horde_Service_Twitter_* object. */ public function __get($value) { // First, see if it's an allowed protected value. switch ($value) { case 'auth': return $this->_auth; case 'request': return $this->_request; case 'responseCache': return $this->_responseCache; case 'cacheLifetime': return $this->_cacheLifetime; } // If not, assume it's a method/action class... $class = 'Horde_Service_Twitter_' . Horde_String::ucfirst($value); if (!empty($this->_objCache[$class])) { return $this->_objCache[$class]; } if (!class_exists($class)) { throw new Horde_Service_Twitter_Exception(sprintf("%s class not found", $class)); } $this->_objCache[$class] = new $class($this); return $this->_objCache[$class]; } }