Some changes to WX template layout and cache the API call out #61
This commit is contained in:
+17
-8
@@ -4,6 +4,7 @@ namespace App\Widgets;
|
|||||||
|
|
||||||
use App\Interfaces\Widget;
|
use App\Interfaces\Widget;
|
||||||
use App\Support\Http;
|
use App\Support\Http;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a widget for the 3rd party CheckWX service
|
* This is a widget for the 3rd party CheckWX service
|
||||||
@@ -23,15 +24,23 @@ class CheckWx extends Widget
|
|||||||
if (!config('checkwx.api_key')) {
|
if (!config('checkwx.api_key')) {
|
||||||
$data = null;
|
$data = null;
|
||||||
} else {
|
} else {
|
||||||
$url = config('checkwx.url').'/metar/'.$this->config['icao'].'/decoded';
|
// Cache the request so we don't need to repeatedly call out
|
||||||
$data = Http::get($url, [
|
$cache = config('cache.keys.WEATHER_LOOKUP');
|
||||||
'headers' => [
|
$key = $cache['key'].$this->config['icao'];
|
||||||
'X-API-Key' => config('checkwx.api_key'),
|
|
||||||
'content-type' => 'application/json',
|
$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) {
|
if($data->results === 1) {
|
||||||
$data = $data->data[0];
|
$data = $data->data[0];
|
||||||
|
|||||||
+7
-3
@@ -7,15 +7,19 @@ return [
|
|||||||
|
|
||||||
'keys' => [
|
'keys' => [
|
||||||
'AIRPORT_VACENTRAL_LOOKUP' => [
|
'AIRPORT_VACENTRAL_LOOKUP' => [
|
||||||
'key' => 'airports:lookup:',
|
'key' => 'airports.lookup:',
|
||||||
'time' => 60 * 30,
|
'time' => 60 * 30,
|
||||||
],
|
],
|
||||||
|
'WEATHER_LOOKUP' => [
|
||||||
|
'key' => 'airports.weather.', // append icao
|
||||||
|
'time' => 60 * 30, // Cache for 30 minutes
|
||||||
|
],
|
||||||
'RANKS_PILOT_LIST' => [
|
'RANKS_PILOT_LIST' => [
|
||||||
'key' => 'ranks:pilot_list',
|
'key' => 'ranks.pilot_list',
|
||||||
'time' => 60 * 10,
|
'time' => 60 * 10,
|
||||||
],
|
],
|
||||||
'USER_API_KEY' => [
|
'USER_API_KEY' => [
|
||||||
'key' => 'user:apikey',
|
'key' => 'user.apikey',
|
||||||
'time' => 60 * 5, // 5 min
|
'time' => 60 * 5, // 5 min
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
|
{{--
|
||||||
|
|
||||||
|
If you want to edit this, you can reference the CheckWX API docs:
|
||||||
|
https://api.checkwx.com/#metar-decoded
|
||||||
|
|
||||||
|
--}}
|
||||||
@if(!$data)
|
@if(!$data)
|
||||||
<p>METAR/TAF data could not be retrieved</p>
|
<p>METAR/TAF data could not be retrieved</p>
|
||||||
@else
|
@else
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
|
||||||
<td colspan="2">
|
|
||||||
<div style="line-height:1.5em;min-height: 3em;">
|
|
||||||
{{$data->raw_text}}
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan="2">Updated: {{$data->observed}}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Conditions</td>
|
<td>Conditions</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -21,14 +17,20 @@
|
|||||||
@else
|
@else
|
||||||
{{$data->temperature->celsius}}°C
|
{{$data->temperature->celsius}}°C
|
||||||
@endif
|
@endif
|
||||||
, visibility
|
|
||||||
@if($unit_dist === 'km')
|
@if($data->visibility->miles)
|
||||||
{{intval(str_replace(',', '', $data->visibility->meters)) / 1000}}
|
, visibility
|
||||||
@else
|
@if($unit_dist === 'km')
|
||||||
{{$data->visibility->miles}}
|
{{intval(str_replace(',', '', $data->visibility->meters)) / 1000}}
|
||||||
@endif
|
@else
|
||||||
|
{{$data->visibility->miles}}
|
||||||
|
@endif
|
||||||
|
|
||||||
{{$data->humidity_percent}}% humidity
|
@endif
|
||||||
|
|
||||||
|
@if($data->humidity_percent)
|
||||||
|
{{$data->humidity_percent}}% humidity
|
||||||
|
@endif
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -60,5 +62,17 @@
|
|||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Metar</td>
|
||||||
|
<td>
|
||||||
|
<div style="line-height:1.5em;min-height: 3em;">
|
||||||
|
{{$data->raw_text}}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Updated</td>
|
||||||
|
<td>{{$data->observed}}</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
Reference in New Issue
Block a user