You are here

function rec_transfer_check_service in Recommender API 6.3

Same name and namespace in other branches
  1. 7.4 rec_transfer/rec_transfer.module \rec_transfer_check_service()
  2. 7.5 rec_transfer/rec_transfer.module \rec_transfer_check_service()
3 calls to rec_transfer_check_service()
rec_transfer_download in rec_transfer/rec_transfer.module
rec_transfer_handle_commands in rec_transfer/rec_transfer.module
rec_transfer_upload in rec_transfer/rec_transfer.module

File

rec_transfer/rec_transfer.module, line 154
This is the module file for Recommender Data Transfer

Code

function rec_transfer_check_service($what, $options = array()) {

  // since we are using CURL anyway, we'll use CURL instead of drupal_http_request
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_USERAGENT, "Drupal (Recommender)");
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_URL, variable_get('rec_transfer_endpoint', '') . '/check');
  $post = array(
    'apikey' => variable_get('rec_transfer_apikey', ''),
    'what' => $what,
  ) + $options;
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  $response = curl_exec($ch);

  //var_dump($response);
  $data = json_decode($response, TRUE);
  $results = array(
    'success' => $response && curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200,
    'http_code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
    'response' => $response,
    'data' => $data,
    'message' => '',
  );
  if ($response == FALSE) {
    $results['message'] = 'Cannot connect to the service.';
  }
  else {
    if (isset($data['status'])) {
      $results['status'] = $data['status'];
    }
    $results['message'] = $data['message'];
  }
  curl_close($ch);
  return $results;
}