class clients_connection_flickr in Web Service Clients 7
Hierarchy
- class \clients_connection_base
- class \clients_connection_flickr
Expanded class hierarchy of clients_connection_flickr
File
- backends/
clients_flickr/ clients_flickr.inc, line 11 - Defines Flickr services and calls
View source
class clients_connection_flickr extends clients_connection_base {
/**
* Use for testing
*/
public static function connect($connection) {
$session = drupal_http_request($connection->endpoint . '?method=flickr.test.echo');
if ($session === FALSE) {
drupal_set_message('Error connecting');
}
return $session;
}
/**
* Prepares a hashed token for the service, based on current time,
* the required service and config values; serviceKey and serviceDomain
*
* @param $serviceConfig
* stdClass: A service configuration as returned by Clients::load()
* @param $serviceMethod
* string: Name of service method to access
*
* @return
* array: a valid token
*/
public static function getToken($connection, $serviceMethod) {
// @todo - http://www.flickr.com/services/api/auth.howto.web.html
$timestamp = (string) time();
$nonce = uniqid();
$hashParameters = array(
$timestamp,
$connection->configuration['domain'],
$nonce,
$serviceMethod,
);
$hash = hash_hmac("sha256", implode(';', $hashParameters), $connection->configuration['servicekey']);
return array(
'hash' => $hash,
'domain' => $connection->configuration['domain'],
'timestamp' => $timestamp,
'nonce' => $nonce,
);
}
/**
* Connects to Drupal Services and logs in the user provided in the config.
* Returns a session for the user.
* @todo needs error catching in case service is down
*
* @return
* array
*/
public static function getUser($connection) {
$session = self::connect($connection);
$userToken = self::getToken($connection, 'user.login');
$user = xmlrpc($connection->baseurl, 'user.login', $userToken['hash'], $userToken['domain'], $userToken['timestamp'], $userToken['nonce'], $session['sessid'], $connection->configuration['username'], $connection->configuration['password']);
if ($user === FALSE) {
return xmlrpc_error();
}
return $user;
}
/**
* Executes call and processes data
*/
public static function call($serviceConfig, $serviceOptions) {
if ($serviceOptions->configuration['options']['method'] == 'flickr.photos.search') {
// gets raw result
$cache_id = md5($serviceConfig->name . implode($serviceOptions->configuration['options']));
$fetch_url = $serviceConfig->endpoint . '?method=' . $serviceOptions->configuration['options']['method'] . '&api_key=' . $serviceConfig->configuration['api_key'] . '&text=' . $serviceOptions->configuration['options']['text'] . '&page=' . $serviceOptions->configuration['options']['page'] . '&per_page=' . $serviceOptions->configuration['options']['per_page'];
// etc http://www.flickr.com/services/api/flickr.photos.search.html
$result = parent::doCall('rest', $cache_id, $fetch_url);
return $result;
}
// else method not supported yet
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
clients_connection_base:: |
public | property | ||
clients_connection_base:: |
public | property | ||
clients_connection_base:: |
public | property | ||
clients_connection_base:: |
public | property | ||
clients_connection_base:: |
static | function | Submit handler for saving/updating connections of this class. | 1 |
clients_connection_base:: |
protected static | function | Takes variable number of params after cacheid. | |
clients_connection_base:: |
function | Provide buttons for the connection testing page. | 1 | |
clients_connection_base:: |
function | Constructor method. | 1 | |
clients_connection_flickr:: |
public static | function |
Executes call and processes data Overrides clients_connection_base:: |
|
clients_connection_flickr:: |
public static | function | Use for testing | |
clients_connection_flickr:: |
public static | function | Prepares a hashed token for the service, based on current time, the required service and config values; serviceKey and serviceDomain | |
clients_connection_flickr:: |
public static | function | Connects to Drupal Services and logs in the user provided in the config. Returns a session for the user. @todo needs error catching in case service is down |