stubbing out weather gov service to fetch current conditions
This commit is contained in:
@@ -2,25 +2,48 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class WeatherGovService
|
class WeatherGovService
|
||||||
{
|
{
|
||||||
public function fetchOfficesList($weatherOffice, $gridX, $gridY): array
|
private string $apiBaseUrl = "https://api.weather.gov";
|
||||||
|
|
||||||
|
private function fetchFromRemoteApi(string $url): ?array
|
||||||
{
|
{
|
||||||
//
|
$response = Http::retry(3, 60000, throw: false)->acceptJson()->get($url);
|
||||||
|
return $response->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchHourlyReport($weatherOffice, $gridX, $gridY): array
|
public function fetchOffice($latitude, $longitude): array
|
||||||
{
|
{
|
||||||
//
|
$apiUrl = "{$this->apiBaseUrl}/points/{$latitude}/{$longitude}";
|
||||||
|
return Cache::remember('lookup.offices', 86400, function () use ($apiUrl) {
|
||||||
|
return $this->fetchFromRemoteApi($apiUrl);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchDailyReport($weatherOffice, $gridX, $gridY): array
|
public function fetchHourlyReport(string $weatherOffice, int $gridX, int $gridY): array
|
||||||
{
|
{
|
||||||
//
|
$apiUrl = "{$this->apiBaseUrl}/gridpoints/{$weatherOffice}/{$gridX}/{$gridY}/forecast/hourly";
|
||||||
|
return Cache::remember('lookup.offices', 900, function () use ($apiUrl) {
|
||||||
|
return $this->fetchFromRemoteApi($apiUrl);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchWeeklyReport($weatherOffice, $gridX, $gridY): array
|
public function fetchDailyReport(string $weatherOffice, int $gridX, int $gridY): array
|
||||||
{
|
{
|
||||||
//
|
$apiUrl = "{$this->apiBaseUrl}/gridpoints/{$weatherOffice}/{$gridX}/{$gridY}/";
|
||||||
|
return Cache::remember('lookup.offices', 3600, function () use ($apiUrl) {
|
||||||
|
return $this->fetchFromRemoteApi($apiUrl);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchWeeklyReport(string $weatherOffice, int $gridX, int $gridY): array
|
||||||
|
{
|
||||||
|
$apiUrl = "{$this->apiBaseUrl}/gridpoints/{$weatherOffice}/{$gridX}/{$gridY}/forecast";
|
||||||
|
return Cache::remember('lookup.offices', 86400, function () use ($apiUrl) {
|
||||||
|
return $this->fetchFromRemoteApi($apiUrl);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user