You are here

function PMPAPIDrupal::auth in Public Media Platform API Integration 7

Gets an AuthClient object (either fresh, or from cache).

Return value

The AuthClient of this object

1 call to PMPAPIDrupal::auth()
PMPAPIDrupal::__construct in classes/PMPAPIDrupal.php
Initializes a PMPAPIDrupal object.

File

classes/PMPAPIDrupal.php, line 50
Defines a class for PMP creation/transmission and retreival/parsing

Class

PMPAPIDrupal
@file

Code

function auth() {

  // See if this is already stored in cache
  // Note: auth stuff caching is not configurable
  $cached_auth_client = cache_get('pmpapi_auth_client');
  if ($cached_auth_client) {
    $this->auth_client = $cached_auth_client->data;
  }
  else {
    try {
      $auth_client = new \Pmp\Sdk\AuthClient($this->base, $this->client_id, $this->client_secret);
      $this->auth_client = $auth_client;
      cache_set('pmpapi_auth_client', $auth_client);
    } catch (Exception $e) {
      $message = t('Error getting authentication for PMP, query aborted. Message: @exception', array(
        '@exception' => $e
          ->getMessage(),
      ));
      drupal_set_message($message, 'warning');
      $this->errors['auth'][] = $e
        ->getMessage();
    }
  }
  return $this->auth_client;
}