Cmfcmf\OpenWeatherMap::getRawWeatherHistory PHP Method

getRawWeatherHistory() public method

Directly returns the xml/json/html string returned by OpenWeatherMap for the weather history.
public getRawWeatherHistory ( array | integer | string $query, DateTime $start, DateTime | integer $endOrCount = 1, string $type = 'hour', string $units = 'imperial', string $lang = 'en', string $appid = '' ) : string
$query array | integer | string The place to get weather information for. For possible values see ::getWeather.
$start DateTime The \DateTime object of the date to get the first weather information from.
$endOrCount DateTime | integer Can be either a \DateTime object representing the end of the period to receive weather history data for or an integer counting the number of reports requested.
$type string The period of the weather history requested. Can be either be either "tick", "hour" or "day".
$units string Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
$lang string The language to use for descriptions, default is 'en'. For possible values see http://openweathermap.org/current#multi.
$appid string Your app id, default ''. See http://openweathermap.org/appid for more details.
return string Returns false on failure and the fetched data in the format you specified on success. Warning If an error occurred, OpenWeatherMap ALWAYS returns data in json format.
    public function getRawWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = 'imperial', $lang = 'en', $appid = '')
    {
        if (!in_array($type, array('tick', 'hour', 'day'))) {
            throw new \InvalidArgumentException('$type must be either "tick", "hour" or "day"');
        }
        $url = $this->buildUrl($query, $units, $lang, $appid, 'json', $this->weatherHistoryUrl);
        $url .= "&type={$type}&start={$start->format('U')}";
        if ($endOrCount instanceof \DateTime) {
            $url .= "&end={$endOrCount->format('U')}";
        } elseif (is_numeric($endOrCount) && $endOrCount > 0) {
            $url .= "&cnt={$endOrCount}";
        } else {
            throw new \InvalidArgumentException('$endOrCount must be either a \\DateTime or a positive integer.');
        }
        return $this->cacheOrFetchResult($url);
    }

Usage Example

 /**
  * Directly returns the xml/json/html string returned by OpenWeatherMap for the daily forecast.
  *
  * @param array|int|string $query           The place to get weather information for. For possible values see below.
  * @param \DateTime        $start           The \DateTime object of the date to get the first weather information from.
  * @param \DateTime|int    $endOrCount      Can be either a \DateTime object representing the end of the period to
  *                                          receive weather history data for or an integer counting the number of
  *                                          reports requested.
  * @param string           $type            The period of the weather history requested. Can be either be either "tick",
  *                                          "hour" or "day".
  * @param string           $units           Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
  * @param string           $lang            The language to use for descriptions, default is 'en'. For possible values see below.
  * @return string
  */
 public function getRawWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = null, $lang = null)
 {
     return $this->service->getRawWeatherHistory($query, $start, $endOrCount, $type, empty($units) ? $this->units : $units, empty($lang) ? $this->lang : $lang, $this->api_key);
 }