Source for file object.php
Documentation is available at object.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
defined('JPATH_PLATFORM') or die();
* Twitter API object class for the Joomla Platform.
* @package Joomla.Platform
* @var JRegistry Options for the Twitter object.
* @var JHttp The HTTP client object to use in sending HTTP requests.
* @var JTwitterOAuth The OAuth client.
* @param JRegistry &$options Twitter options object.
* @param JHttp $client The HTTP client object.
* @param JTwitterOAuth $oauth The OAuth client.
public function __construct(JRegistry &$options =
null, JHttp $client =
null, JTwitterOAuth $oauth =
null)
* Method to check the rate limit for the requesting IP address
* @param string $resource A resource or a comma-separated list of resource families you want to know the current rate limit disposition for.
* @param string $action An action for the specified resource, if only one resource is specified.
* @throws RuntimeException
// Check the rate limit for remaining hits
$property =
'/' .
$resource;
$property .=
'/' .
$action;
if ($rate_limit->resources->$resource->$property->remaining ==
0)
// The IP has exceeded the Twitter API rate limit
throw
new RuntimeException('This server has exceed the Twitter API rate limit for the given period. The limit will reset at '
.
$rate_limit->resources->$resource->$property->reset
* Method to build and return a full request URL for the request. This method will
* add appropriate pagination details if necessary and also prepend the API url
* to have a complete URL for the request.
* @param string $path URL to inflect
* @param array $parameters The parameters passed in the URL.
* @return string The request URL.
public function fetchUrl($path, $parameters =
null)
foreach ($parameters as $key =>
$value)
if (strpos($path, '?') ===
false)
$path .=
'?' .
$key .
'=' .
$value;
$path .=
'&' .
$key .
'=' .
$value;
// Get a new JUri object fousing the api url and given path.
if (strpos($path, 'http://search.twitter.com/search.json') ===
false)
* Method to retrieve the rate limit for the requesting IP address
* @param string $resource A resource or a comma-separated list of resource families you want to know the current rate limit disposition for.
* @return array The JSON response decoded
// Build the request path.
$path =
'/application/rate_limit_status.json';
return $this->sendRequest($path, 'GET', array('resources' =>
$resource));
* Method to send the request.
* @param string $path The path of the request to make
* @param string $method The request method.
* @param mixed $data Either an associative array or a string to be sent with the post request.
* @param array $headers An array of name-value pairs to include in the header of the request
* @return array The decoded JSON response
* @throws RuntimeException
public function sendRequest($path, $method =
'GET', $data =
array(), $headers =
array())
$token =
$this->oauth->getToken();
$parameters['oauth_token'] =
$token['key'];
$response =
$this->oauth->oauthRequest($this->fetchUrl($path), $method, $parameters, $data, $headers);
if (strpos($path, 'update_with_media') !==
false)
// Check Media Rate Limit.
$response_headers =
$response->headers;
if ($response_headers['x-mediaratelimit-remaining'] ==
0)
// The IP has exceeded the Twitter API media rate limit
throw
new RuntimeException('This server has exceed the Twitter API media rate limit for the given period. The limit will reset in '
.
$response_headers['x-mediaratelimit-reset'] .
'seconds.'
if (strpos($response->body, 'redirected') !==
false)
return $response->headers['Location'];
* Get an option from the JTwitterObject instance.
* @param string $key The name of the option to get.
* @return mixed The option value.
* Set an option for the JTwitterObject instance.
* @param string $key The name of the option to set.
* @param mixed $value The option value to set.
* @return JTwitterObject This object for method chaining.
Documentation generated on Tue, 19 Nov 2013 15:09:42 +0100 by phpDocumentor 1.4.3