You are here

protected function JanrainCaptureApi::call in Janrain Registration 7.4

Same name and namespace in other branches
  1. 6 janrain_capture.api.inc \JanrainCaptureApi::call()
  2. 7 janrain_capture.api.inc \JanrainCaptureApi::call()
  3. 7.2 includes/janrain_capture.api.inc \JanrainCaptureApi::call()
  4. 7.3 includes/janrain_capture.api.inc \JanrainCaptureApi::call()

Performs the HTTP request.

Parameters

string $command: The Capture command to perform

array $arg_array: The data set to pass via POST

string $access_token: The client access token to use when performing user-specific calls

Return value

mixed The HTTP request result data

4 calls to JanrainCaptureApi::call()
JanrainCaptureApi::getShareProviders in includes/janrain_capture.api.inc
Retrieves a list of Social Sharing providers for Engage
JanrainCaptureApi::loadUserEntity in includes/janrain_capture.api.inc
Retrives the user entity from Capture
JanrainCaptureApi::newAccessToken in includes/janrain_capture.api.inc
Perform the exchange to generate a new Access Token
JanrainCaptureApi::refreshAccessToken in includes/janrain_capture.api.inc
Retrieves a new access_token/refresh_token set

File

includes/janrain_capture.api.inc, line 53
An API Client for making calls to the Janrain Capture web service.

Class

JanrainCaptureApi
@file An API Client for making calls to the Janrain Capture web service.

Code

protected function call($command, $arg_array = NULL, $access_token = NULL) {
  $url = "https://" . $this->captureAddr . "/{$command}";
  $headers = array(
    'Content-Type' => 'application/x-www-form-urlencoded',
    'User-Agent' => 'Drupal/janrain_capture-' . JANRAIN_CAPTURE_MODULE_VERSION,
  );
  if (isset($access_token)) {
    $headers['Authorization'] = "OAuth {$access_token}";
  }
  $options = array(
    'headers' => $headers,
  );
  if ($arg_array) {
    $arg_array = array_merge($arg_array, $this->args);
  }
  else {
    $arg_array = $this->args;
  }
  $options['method'] = 'POST';
  $options['data'] = http_build_query($arg_array, '', '&');
  $result = drupal_http_request($url, $options);
  $json_data = $this
    ->decodeData($result);

  // NULL decoded value indicates a parse error.
  if (!isset($json_data)) {
    $json_data['stat'] = 'error';
    $json_data['code'] = '0';
    $json_data['error'] = 'JSON parse error for: ' . $result->data;
  }
  if ($json_data['stat'] == 'error') {
    $error = new stdClass();
    $error->code = $json_data['code'];
    $error->error = $json_data['error'] . ": " . $json_data['error_description'];
    $this
      ->reportError($error);
    return FALSE;
  }
  return $json_data;
}