You are here

function restclient_filemode_save_response in RESTClient 7.2

Function to save the response of the curl call to a file.

Parameters

$response: response from the service call

$url: url of the service call.

$variables: $type of function being called, GET, PUT etc.

1 call to restclient_filemode_save_response()
_restclient_request in ./restclient.module
Basic request with no body data.

File

./restclient.filemode.inc, line 62
Defines the restclient testing feature.

Code

function restclient_filemode_save_response($response, $url, $variables) {
  $file_name = _restclient_filemode_file_name($url, $variables);

  //Fetch the file if it exist.
  $realpath = _restclient_get_file_location();

  //Check if the restclient_testing file exist, if not create it.
  if (!file_exists($realpath)) {

    //Create it
    if (!drupal_mkdir($realpath)) {
      watchdog('restclient', 'Failed to create restclient_testing folder.', array(), WATCHDOG_ERROR);
      return;
    }
  }
  $file_url = $realpath . '/' . $file_name;

  //Check if the file exist if so overrite it, if not create it.
  $serialized = serialize($response);

  //File save data and replace if the file already exist.
  if (!file_unmanaged_save_data($serialized, $file_url, FILE_EXISTS_REPLACE)) {
    watchdog('restclient', 'Failed to save the contents of the file.', array(), WATCHDOG_ERROR);
  }
  return;
}