class ClientsServicesFlickr in Web Service Clients 6
Hierarchy
- class \ClientsServicesBase
- class \ClientsServicesFlickr
Expanded class hierarchy of ClientsServicesFlickr
File
- backends/
clients_flickr/ clients_flickr.inc, line 12 - Defines Flickr services and calls
View source
class ClientsServicesFlickr extends ClientsServicesBase {
/**
* 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 |
---|---|---|---|---|
ClientsServicesBase:: |
protected static | function | Takes variable number of params after cacheid. | |
ClientsServicesFlickr:: |
public static | function |
Executes call and processes data Overrides ClientsServicesBase:: |
|
ClientsServicesFlickr:: |
public static | function | Use for testing | |
ClientsServicesFlickr:: |
public static | function | Prepares a hashed token for the service, based on current time, the required service and config values; serviceKey and serviceDomain | |
ClientsServicesFlickr:: |
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 |