You are here

protected function JanrainCaptureApi::call in Janrain Registration 6

Same name and namespace in other branches
  1. 7.4 includes/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

3 calls to JanrainCaptureApi::call()
JanrainCaptureApi::loadUserEntity in ./janrain_capture.api.inc
Retrives the user entity from Capture
JanrainCaptureApi::newAccessToken in ./janrain_capture.api.inc
Perform the exchange to generate a new Access Token
JanrainCaptureApi::refreshAccessToken in ./janrain_capture.api.inc
Retrieves a new access_token/refresh_token set

File

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

Class

JanrainCaptureApi
@file 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',
  );
  if (isset($access_token)) {
    $headers['Authorization'] = "OAuth {$access_token}";
  }
  if (isset($arg_array)) {
    $arg_array = array_merge($arg_array, $this->args);
    $result = drupal_http_request($url, $headers, "POST", http_build_query($arg_array, '', '&'));
  }
  else {
    $result = drupal_http_request($url, $headers);
  }
  if (!isset($result->data) || $result->code != '200') {
    $this
      ->reportError($result);
    return FALSE;
  }
  $json_data = json_decode($result->data, TRUE);

  // 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'];
    $this
      ->reportError($error);
    return FALSE;
  }
  return $json_data;
}