You are here

function restclient_filemode_fetch_response in RESTClient 7.2

Function to fetch a response from a file.

Parameters

$url: The url path to fetch a response from.

$variables: Variable to be used with the "rest" call

Return value

Return an response loaded from the file.

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

File

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

Code

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

  //Fetch the file if it exist.
  $return = '';
  $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 (file_exists($file_url)) {

    //Fetch the file.
    $data = file_get_contents($file_url);
    $return = unserialize($data);
  }
  else {
    watchdog('restclient', 'Corresponding file does not exist for !url', array(
      '!url' => $url,
    ), WATCHDOG_ERROR);
    return;
  }
  return $return;
}