You are here

public function WardenAPI::request in Warden 7

Same name and namespace in other branches
  1. 6 warden_api.inc \WardenAPI::request()

Send a message to warden

Parameters

string $path: The query path including the leading slash (e.g. '/public-key')

string $content: The body of the request. If this is not empty, the request is a post.

Return value

object The response object

Throws

Exception If the response status was not 200

2 calls to WardenAPI::request()
WardenAPI::getPublicKey in ./warden_api.inc
Get the public key.
WardenAPI::postSiteData in ./warden_api.inc
Send the site data to Warden.

File

./warden_api.inc, line 177
The API for communicating with the Warden server application.

Class

WardenAPI
@file The API for communicating with the Warden server application.

Code

public function request($path, $content = '') {
  $url = $this->wardenUrl . $path;
  $options = array();
  if (!empty($this->username)) {
    $options['headers']['Authorization'] = 'Basic ' . base64_encode($this->username . ':' . $this->password);
  }
  if (!empty($content)) {
    $options['data'] = $content;
    $options['method'] = 'POST';
  }
  $warden_context_options = variable_get('warden_context_options', array());
  if (!empty($warden_context_options)) {
    $options['context'] = stream_context_create($warden_context_options);
  }
  $result = drupal_http_request($url, $options);
  if ($result->code != 200) {
    watchdog('warden', '@url : @code : @message', array(
      '@url' => $url,
      '@code' => $result->code,
      '@message' => $result->error,
    ), WATCHDOG_ERROR);
    throw new Exception('Unable to communicate with Warden');
  }
  return $result;
}