Permalink
Browse files

Fix autoloading by renaming to JOauthV2client.

  • Loading branch information...
1 parent e812949 commit 6a77274ac54f6c810cbe26626f56352c2f9a2067 @aaronschmitz aaronschmitz committed with LouisLandry Oct 10, 2012
@@ -8,7 +8,7 @@
*/
defined('JPATH_PLATFORM') or die;
-jimport('joomla.oauth.oauth2client');
+jimport('joomla.oauth.v2client');
/**
* Google OAuth authentication class
@@ -20,7 +20,7 @@
class JGoogleAuthOauth2 extends JGoogleAuth
{
/**
- * @var JOauth2client OAuth client for the Google authentication object.
+ * @var JOauthV2client OAuth client for the Google authentication object.
* @since 1234
*/
protected $client;
@@ -29,14 +29,14 @@ class JGoogleAuthOauth2 extends JGoogleAuth
* Constructor.
*
* @param JRegistry $options JGoogleAuth options object.
- * @param JOauth2client $client OAuth client for Google authentication.
+ * @param JOauthV2client $client OAuth client for Google authentication.
*
* @since 1234
*/
- public function __construct(JRegistry $options = null, JOauthOauth2client $client = null)
+ public function __construct(JRegistry $options = null, JOauthV2client $client = null)
{
$this->options = isset($options) ? $options : new JRegistry;
- $this->client = isset($client) ? $client : new JOauthOauth2client($this->options);
+ $this->client = isset($client) ? $client : new JOauthV2client($this->options);
}
/**
@@ -85,7 +85,7 @@ public function query($url, $data = null, $headers = null, $method = 'get')
/**
* Method to fill in Google-specific OAuth settings
*
- * @return JOauth2client Google-configured Oauth2 client.
+ * @return JOauthV2client Google-configured Oauth2 client.
*
* @since 1234
*/
@@ -236,19 +236,6 @@ public function getWidth()
}
/**
- * Method to get the time of the photo
- *
- * @return int Photo time
- *
- * @since 1234
- */
- public function getTime()
- {
- return (int) $this->xml->children('gphoto', true)->timestamp;
- return $this;
- }
-
- /**
* Method to set the title of the photo
*
* @param string $title New photo title
@@ -15,48 +15,41 @@
*
* @package Joomla.Platform
* @subpackage Oauth
- * @since 1234
+ * @since 12.2
*/
-class JOauthOauth2client
+class JOauthV2client
{
/**
- * @var JRegistry Options for the OAuth2Client object.
- * @since 1234
+ * @var JRegistry Options for the JOauthV2client object.
+ * @since 12.2
*/
protected $options;
/**
- * @var JHttpTransport The HTTP transport object to use in sending HTTP requests.
- * @since 1234
- */
- protected $client;
-
- /**
* @var JHttp The HTTP client object to use in sending HTTP requests.
- * @since 1234
+ * @since 12.2
*/
protected $http;
/**
* @var JInput The input object to use in retrieving GET/POST data.
- * @since 1234
+ * @since 12.2
*/
protected $input;
/**
* Constructor.
*
- * @param JRegistry $options OAuth2Client options object
- * @param JHttpTransport $client The HTTP client object
- * @param JInput $input The input object
+ * @param JRegistry $options JOauthV2client options object
+ * @param JOauthHttp $http The HTTP client object
+ * @param JInput $input The input object
*
- * @since 1234
+ * @since 12.2
*/
- public function __construct(JRegistry $options = null, JHttpTransport $client = null, JInput $input = null)
+ public function __construct(JRegistry $options = null, JOauthHttp $http = null, JInput $input = null)
{
$this->options = isset($options) ? $options : new JRegistry;
- $this->client = isset($client) ? $client : JHttpFactory::getAvailableDriver($this->options);
- $this->http = new JHttp($this->options, $this->client);
+ $this->http = isset($http) ? $http : new JHttp($this->options, $this->client);
$this->input = isset($input) ? $input : JFactory::getApplication()->input;
}
@@ -65,7 +58,7 @@ public function __construct(JRegistry $options = null, JHttpTransport $client =
*
* @return string The access token
*
- * @since 1234
+ * @since 12.2
*/
public function auth()
{
@@ -112,20 +105,32 @@ public function auth()
*
* @return bool Is authenticated
*
- * @since 1234
+ * @since 12.2
*/
public function isAuth()
{
$token = $this->getToken();
- return !empty($token);
+
+ if (!$token || !array_key_exists('access_token', $token))
+ {
+ return false;
+ }
+ elseif (array_key_exists('expires_in', $token) && $token['created'] + $token['expires_in'] < time() + 20)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
}
/**
* Create the URL for authentication.
*
* @return JHttpResponse The HTTP response
*
- * @since 1234
+ * @since 12.2
*/
public function createUrl()
{
@@ -185,7 +190,7 @@ public function createUrl()
*
* @return string The URL.
*
- * @since 1234
+ * @since 12.2
*/
public function query($url, $data = null, $headers = array(), $method = 'get', $timeout = null)
{
@@ -217,7 +222,22 @@ public function query($url, $data = null, $headers = array(), $method = 'get', $
$url .= '=' . $token['access_token'];
}
- $response = $this->client->request($method, new JURI($url), $data, $headers, $timeout);
+ switch ($method)
+ {
+ case 'head':
+ case 'get':
+ case 'delete':
+ case 'trace':
+ $response = $this->http->$method($url, $headers, $timeout);
+ break;
+ case 'post':
+ case 'put':
+ case 'patch':
+ $response = $this->http->$method($url, $data, $headers, $timeout);
+ break;
+ default:
+ throw new InvalidArgumentException('Unknown HTTP request method: ' . $method . '.');
+ }
if ($response->code < 200 || $response->code >= 400)
{
@@ -227,28 +247,28 @@ public function query($url, $data = null, $headers = array(), $method = 'get', $
}
/**
- * Get an option from the JOauth2client instance.
+ * Get an option from the JOauthV2client instance.
*
* @param string $key The name of the option to get
*
* @return mixed The option value
*
- * @since 1234
+ * @since 12.2
*/
public function getOption($key)
{
return $this->options->get($key);
}
/**
- * Set an option for the JOauth2client instance.
+ * Set an option for the JOauthV2client instance.
*
* @param string $key The name of the option to set
* @param mixed $value The option value to set
*
- * @return JOauth2client This object for method chaining
+ * @return JOauthV2client This object for method chaining
*
- * @since 1234
+ * @since 12.2
*/
public function setOption($key, $value)
{
@@ -257,25 +277,25 @@ public function setOption($key, $value)
}
/**
- * Get the access token from the JOauth2client instance.
+ * Get the access token from the JOauthV2client instance.
*
* @return array The access token
*
- * @since 1234
+ * @since 12.2
*/
public function getToken()
{
return $this->getOption('accesstoken');
}
/**
- * Set an option for the JOauth2client instance.
+ * Set an option for the JOauthV2client instance.
*
* @param array $value The access token
*
- * @return JOauth2client This object for method chaining
+ * @return JOauthV2client This object for method chaining
*
- * @since 1234
+ * @since 12.2
*/
public function setToken($value)
{
@@ -295,7 +315,7 @@ public function setToken($value)
*
* @return array The new access token
*
- * @since 1234
+ * @since 12.2
*/
public function refreshToken($token = null)
{
Oops, something went wrong. Retry.

0 comments on commit 6a77274

Please sign in to comment.