7
const API_ENDPOINT = 'https://api.forecast.io/forecast/';
10
public function __construct($api_key)
12
$this->api_key = $api_key;
15
private function request($latitude, $longitude, $time = null, $options = array())
17
$request_url = self::API_ENDPOINT
23
. ((is_null($time)) ? '' : ','. $time);
25
if (!empty($options)) {
26
$request_url .= '?'. http_build_query($options);
29
\Xibo\Helper\Log::debug('Calling API with: ' . $request_url);
31
$request_url = str_replace('[APIKEY]', $this->api_key, $request_url);
34
CURLOPT_TIMEOUT => 20,
35
CURLOPT_SSL_VERIFYPEER => true,
36
CURLOPT_USERAGENT => 'Xibo Digital Signage',
37
CURLOPT_HEADER => false,
38
CURLINFO_HEADER_OUT => true,
39
CURLOPT_RETURNTRANSFER => true,
40
CURLOPT_URL => $request_url
44
if (\Xibo\Helper\Config::GetSetting('PROXY_HOST') != '' && !\Xibo\Helper\Config::isProxyException($request_url)) {
45
$httpOptions[CURLOPT_PROXY] = \Xibo\Helper\Config::GetSetting('PROXY_HOST');
46
$httpOptions[CURLOPT_PROXYPORT] = \Xibo\Helper\Config::GetSetting('PROXY_PORT');
48
if (\Xibo\Helper\Config::GetSetting('PROXY_AUTH') != '')
49
$httpOptions[CURLOPT_PROXYUSERPWD] = \Xibo\Helper\Config::GetSetting('PROXY_AUTH');
53
curl_setopt_array($curl, $httpOptions);
54
$result = curl_exec($curl);
56
// Get the response headers
57
$outHeaders = curl_getinfo($curl);
59
if ($outHeaders['http_code'] == 0) {
61
\Xibo\Helper\Log::error('Unable to reach Forecast API. No Host Found (HTTP Code 0). Curl Error = ' . curl_error($curl));
64
else if ($outHeaders['http_code'] != 200) {
65
\Xibo\Helper\Log::error('ForecastIO API returned ' . $outHeaders['http_code'] . ' status. Unable to proceed. Headers = ' . var_export($outHeaders, true));
67
// See if we can parse the error.
68
$body = json_decode($result);
70
\Xibo\Helper\Log::error('ForecastIO Error: ' . ((isset($body->errors[0])) ? $body->errors[0]->message : 'Unknown Error'));
75
// Parse out header and body
76
$body = json_decode($result);
81
public function get($latitude, $longitude, $time = null, $options = array())
83
return $this->request($latitude, $longitude, $time, $options);
b'\\ No newline at end of file'