You are here

public function DeployRemoteCcServiceRestJSON::httpRequest in Deploy - Content Staging 7.3

Make a HTTP request.

Parameters

string $url: The URL to use for the request.

string $method: The method of request, 'GET', 'POST' or 'PUT'.

null|array $data: The data to send with the request.

Return value

mixed The data retrieved from the request.

Throws

\DeployServiceException Will throw a DeployServiceException if there are any issues with the http request.

Overrides DeployServiceRest::httpRequest

1 call to DeployRemoteCcServiceRestJSON::httpRequest()
DeployRemoteCcServiceRestJSON::deploy in modules/deploy_remote_cc/plugins/DeployRemoteCcServiceRestJSON.inc
Deploy all entities in the $iterator. This method should only move entities over to the endpoint and create unpublished revisions (if supported). The 'publish' method is responsible for publishing all successfully deployed entities.

File

modules/deploy_remote_cc/plugins/DeployRemoteCcServiceRestJSON.inc, line 70

Class

DeployRemoteCcServiceRestJSON
Class for calling Rest Service.

Code

public function httpRequest($url, $method, $data = NULL) {
  $this->config['headers']['Content-Type'] = 'application/json';
  $options = array(
    'method' => $method,
    'headers' => $this->config['headers'],
    'data' => $data,
    'context' => $this->config['context'],
    'timeout' => (double) $this->config['timeout'],
  );
  if ($this->config['debug']) {
    watchdog('deploy', 'Service request: %url <pre>@options</pre>', array(
      '%url' => $url,
      '@options' => print_r($options, TRUE),
    ), WATCHDOG_DEBUG);
  }
  $response = drupal_http_request($url, $options);
  if ($this->config['debug']) {
    watchdog('deploy', 'Service response: <pre>@response</pre>', array(
      '@response' => print_r($response, TRUE),
    ), WATCHDOG_DEBUG);
  }
  if (isset($response->error) || !in_array($response->code, array(
    200,
    304,
  ))) {
    throw new \DeployServiceException(t('Service error: @code @error', array(
      '@code' => $response->code,
      '@error' => $response->error,
    )));
  }
  return drupal_json_decode($response->data);
}