86 lines
1.5 KiB
PHP
86 lines
1.5 KiB
PHP
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
|
|
|
/**
|
|
* OAuth API
|
|
*
|
|
* @package OAuth
|
|
* @category Classes
|
|
* @author Deon George
|
|
* @copyright (c) 2009-2013 Deon George
|
|
* @license http://dev.leenooks.net/license.html
|
|
*/
|
|
abstract class Kohana_OAuth_API {
|
|
/**
|
|
* @var string profile data
|
|
*/
|
|
protected $profile;
|
|
|
|
/**
|
|
* Create a new API object.
|
|
*
|
|
* $API = OAuth_API::factory($name);
|
|
*
|
|
* @param string API type
|
|
* @param array API options
|
|
* @return OAuth_API
|
|
*/
|
|
public static function factory(OAuth_Provider $provider, $name, array $options = NULL)
|
|
{
|
|
$class = 'OAuth_API_'.ucfirst($name).'_'.ucfirst($provider->name);
|
|
|
|
return new $class($options);
|
|
}
|
|
|
|
/**
|
|
* @var string required parameters
|
|
*/
|
|
protected $required = array(
|
|
'profile',
|
|
);
|
|
|
|
/**
|
|
* Sets the API data.
|
|
*
|
|
* @param array API options
|
|
* @return void
|
|
*/
|
|
public function __construct(array $options = NULL)
|
|
{
|
|
foreach ($this->required as $key)
|
|
{
|
|
if ( ! isset($options[$key]))
|
|
{
|
|
throw new Kohana_OAuth_Exception('Required option not passed: :option',
|
|
array(':option' => $key));
|
|
}
|
|
|
|
$this->$key = $options[$key];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Return the value of any protected class variable.
|
|
*
|
|
* // Get the API details
|
|
* $secret = $api->id;
|
|
*
|
|
* @param string variable name
|
|
* @return mixed
|
|
*/
|
|
public function __get($key)
|
|
{
|
|
return $this->$key;
|
|
}
|
|
|
|
/**
|
|
* Returns the API key.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function __toString()
|
|
{
|
|
return (string) $this->profile;
|
|
}
|
|
|
|
} // End OAuth_API
|