You are here

class PMPAPIDrupalUpdate in Public Media Platform API Integration 7

Hierarchy

Expanded class hierarchy of PMPAPIDrupalUpdate

File

pmpapi_update/classes/PMPAPIDrupalUpdate.php, line 12
Contains PMPAPIDrupalUpdates.

View source
class PMPAPIDrupalUpdate extends PMPAPIDrupal {

  /**
   * Initializes a PMPAPIDrupalUpdate object.
   */
  function __construct($topic_uri, $mode) {
    parent::__construct();
    $this->verify_token = hash('sha256', REQUEST_TIME);
    $this->topic_uri = $topic_uri;
    $this->mode = $mode;
  }

  /**
   * Sends an HTTP subscribe/unsubscribe request to the API.
   */
  function sendRequestToHub() {
    $token = $this
      ->auth()
      ->getToken()->access_token;

    // Hacky, but this will have to do until we have a more hypermedia-y
    // solution
    $base = variable_get('pmpapi_base_url');
    if ($base == 'https://api.pmp.io') {
      $uri = 'https://publish.pmp.io/notifications';
    }
    else {
      $uri = 'https://publish-sandbox.pmp.io/notifications';
    }
    $secret = sha1(sha1(variable_get('site_name') . REQUEST_TIME));
    variable_set('pmpapi_update_secret', $secret);
    $data = array(
      'hub.callback' => url('pmpapi_notifications', array(
        'absolute' => TRUE,
      )),
      'hub.mode' => $this->mode,
      'hub.topic' => $this->topic_uri,
      'hub.verify' => 'sync',
      'hub.secret' => $secret,
      'hub.verify_token' => $this->verify_token,
    );
    $options['data'] = drupal_http_build_query($data);
    $options['method'] = 'POST';
    $options['headers'] = array(
      'Content-Type' => 'application/x-www-form-urlencoded',
      'Authorization' => 'Bearer ' . $token,
    );
    $this->response = drupal_http_request($uri, $options);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PMPAPIDrupal::auth function Gets an AuthClient object (either fresh, or from cache).
PMPAPIDrupal::cacheClear function Clears a cache value.
PMPAPIDrupal::cacheClearAll function Clears all cache values.
PMPAPIDrupal::cacheClearAuthClient function Clears the saved auth client.
PMPAPIDrupal::cacheGet function Gets a cache value.
PMPAPIDrupal::cacheKey function Generates a unique cache key.
PMPAPIDrupal::cacheSet function Sets a cache value.
PMPAPIDrupal::createDoc function Creates a doc to be pushed to the PMP.
PMPAPIDrupal::date function Generates an ISO 8601 time from a timestamp
PMPAPIDrupal::delete function Deletes a doc from the PMP
PMPAPIDrupal::flattenNavLinks function
PMPAPIDrupal::getDoc function Gets a doc from the PMP.
PMPAPIDrupal::guid function Generates a GUID
PMPAPIDrupal::pull function Pulls from the PMP.
PMPAPIDrupal::push function Takes node, creates Hypermedia doc, sends it to PMP API.
PMPAPIDrupal::report function Generates a basic report of PMP object.
PMPAPIDrupal::sdkInclude function Includes a file from the SDK
PMPAPIDrupalUpdate::sendRequestToHub function Sends an HTTP subscribe/unsubscribe request to the API.
PMPAPIDrupalUpdate::__construct function Initializes a PMPAPIDrupalUpdate object. Overrides PMPAPIDrupal::__construct