You are here

public function GatherContentCurl::get in GatherContent 7.2

Call GatherContent API function.

4 calls to GatherContentCurl::get()
GatherContentCurl::getFiles in includes/curl.inc
Get file array for a specific page.
GatherContentCurl::getPages in includes/curl.inc
List pages for the selected project.
GatherContentCurl::getProjects in includes/curl.inc
Get project list.
GatherContentCurl::getStates in includes/curl.inc
Get list of workflow states.

File

includes/curl.inc, line 738
Contains functions used to process and retrieve data from GatherContent.

Class

GatherContentCurl
@file Contains functions used to process and retrieve data from GatherContent.

Code

public function get($command = '', $postfields = array(), $api_url = '', $api_key = '') {
  $api_url = $api_url == '' ? variable_get('gathercontent_api_url') : $api_url;
  $api_key = $api_key == '' ? variable_get('gathercontent_api_key') : $api_key;
  $api_url = 'https://' . $api_url . '.gathercontent.com/api/0.4/' . $command;
  $curl_opts = array(
    CURLOPT_HTTPAUTH => CURLAUTH_DIGEST,
    CURLOPT_HTTPHEADER => array(
      'Accept: application/json',
      'Content-Type: application/x-www-form-urlencoded',
    ),
    CURLOPT_USERPWD => $api_key . ":x",
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => http_build_query($postfields),
  );
  extract($this
    ->curl($api_url, $curl_opts));
  try {
    $resp = json_decode($response);
    if (isset($resp->success) && $resp->success === TRUE) {
      return $resp;
    }
    elseif (isset($resp->error)) {
      $error = $resp->error;
      if ($command == 'get_files_by_page' && $error == 'Files not found.') {
        return FALSE;
      }
      else {
        if ($error == 'You have to log in.') {
          if ($this->apiErrorShown) {
            return FALSE;
          }
          $error = $this
            ->authError();
        }
        drupal_set_message(t($error), 'error');
      }
    }
    else {
      if (!$this->apiErrorShown) {
        drupal_set_message($this
          ->authError(), 'error');
      }
    }
  } catch (Exception $e) {
    drupal_set_message(t('There was a problem contacting the API. Please check your server allows it.'), 'error');
  }
  return FALSE;
}