Some changes to WX template layout and cache the API call out #61

This commit is contained in:
Nabeel Shahzad
2018-04-02 07:06:00 -05:00
parent f84ff8de92
commit c000034cab
3 changed files with 55 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Widgets;
use App\Interfaces\Widget;
use App\Support\Http;
use Illuminate\Support\Facades\Cache;
/**
* This is a widget for the 3rd party CheckWX service
@@ -23,15 +24,23 @@ class CheckWx extends Widget
if (!config('checkwx.api_key')) {
$data = null;
} else {
$url = config('checkwx.url').'/metar/'.$this->config['icao'].'/decoded';
$data = Http::get($url, [
'headers' => [
'X-API-Key' => config('checkwx.api_key'),
'content-type' => 'application/json',
]
]);
// Cache the request so we don't need to repeatedly call out
$cache = config('cache.keys.WEATHER_LOOKUP');
$key = $cache['key'].$this->config['icao'];
$data = Cache::remember($key, $cache['time'], function () {
$url = config('checkwx.url').'/metar/'.$this->config['icao'].'/decoded';
$data = Http::get($url, [
'headers' => [
'X-API-Key' => config('checkwx.api_key'),
'content-type' => 'application/json',
]
]);
$data = json_decode($data);
return $data;
});
$data = json_decode($data);
if($data->results === 1) {
$data = $data->data[0];