You are here

function wunderground_weather_http_request in Wunderground weather 7

Make a new http request.

Parameters

array $options: Array to build the request uri.

Return value

array Array of returned data or FALSE if something went wrong.

2 calls to wunderground_weather_http_request()
wunderground_weather_get_current_data in ./wunderground_weather.module
Get current weather from Wunderground.
wunderground_weather_get_forecast_data in ./wunderground_weather.module
Get weather forecast from Wunderground.

File

./wunderground_weather.module, line 671
Wunderground weather module to display weather forecasts and current weather conditions in blocks.

Code

function wunderground_weather_http_request($options, $path) {
  $request_url = 'http://api.wunderground.com/api';
  foreach ($options as $argument) {
    $request_url .= '/' . $argument;
  }
  $request_url .= '.json';

  // Get data from wunderground.
  $response = drupal_http_request($request_url);
  if ($response->code == 200) {
    $data = drupal_json_decode($response->data);
    if (isset($data['response']['error'])) {
      $variables = array(
        '%message' => $data['response']['error']['description'],
        '%location' => $path,
      );
      watchdog('wunderground_weather', '%message: %location', $variables, WATCHDOG_WARNING);
      return FALSE;
    }
    else {

      // Return data from Wunderground.
      return $data;
    }
  }
  else {
    $message = 'Something went wrong while making a http request to Wunderground: %error';
    watchdog('wunderground_weather', $message, array(
      '%error' => 'Error ' . $response->code,
    ), WATCHDOG_ERROR);
    return FALSE;
  }
}