public function Client::request in Flickr API Integration 8
Flickr request.
Parameters
string $method: Method to call.
array $args: Args to request.
bool $cacheable: Is it cachable.
Return value
bool|array Either an array or false.
File
- src/
Service/ Client.php, line 131
Class
- Client
- Class Client.
Namespace
Drupal\flickr_api\ServiceCode
public function request($method, array $args, $cacheable = TRUE) {
// Build the arg_hash.
$args = $this
->buildArgs($args, $method);
$argHash = $this
->buildArgHash($args);
// $response = &drupal_static(__FUNCTION__);
// // Can be replaced with the `__METHOD__`.
$cid = 'flickr_api:' . md5($argHash);
// Check cache.
if ($cache = $this->cacheBackend
->get($cid)) {
$response = $cache->data;
// Return result from cache if found.
return $response;
}
else {
// If we've got a secret, sign the arguments.
if ($secret = $this->apiSecret) {
$args['api_sig'] = md5($secret . $argHash);
}
// TODO Implement try catch.
$response = $this
->doRequest('', $args);
if ($response) {
// Cache the response if we got one.
if ($this->apiCacheMaximumAge != 0 && $cacheable == TRUE) {
$this->cacheBackend
->set($cid, $response, time() + $this->apiCacheMaximumAge);
}
// Return result from source if found.
return $response;
}
}
// Tough luck, no results mate.
return FALSE;
}