116 lines
2.8 KiB
PHP
116 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
/*
|
|
* Class contains methods which make calls to the API.
|
|
* Successfull calls get cached.
|
|
*/
|
|
|
|
class Api
|
|
{
|
|
|
|
public static function get(string $path, string $query = ''): ?array
|
|
{
|
|
|
|
$endpoint = env('FASTAPI_URI');
|
|
$request = $endpoint.$path;
|
|
|
|
// load from cache if available
|
|
if (Cache::has($request)) {
|
|
return Cache::get($request);
|
|
}
|
|
|
|
// Set timeout to .5h
|
|
$get = Http::timeout(1800)->get($request);
|
|
|
|
// return result and cache it
|
|
if($get->successful()){
|
|
$result = $get->json();
|
|
Cache::put($request, $result);
|
|
return $result;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function propertiesGrowth(): mixed
|
|
{
|
|
return self::get('/properties/growth');
|
|
}
|
|
|
|
public static function propertiesGeo(): mixed
|
|
{
|
|
return self::get('/properties/geo');
|
|
}
|
|
|
|
public static function propertyExtractions(int $id): mixed
|
|
{
|
|
return self::get("/property/{$id}/extractions");
|
|
}
|
|
|
|
public static function propertyCapacities(int $id): mixed
|
|
{
|
|
return self::get("/property/{$id}/capacities");
|
|
}
|
|
|
|
public static function propertyBase(int $id): mixed
|
|
{
|
|
return self::get("/property/{$id}/base");
|
|
}
|
|
|
|
public static function propertyCapacitiesMonthly(int $id, string $date): mixed
|
|
{
|
|
return self::get("/property/{$id}/capacities/monthly/{$date}");
|
|
}
|
|
|
|
public static function propertyCapacitiesDaily(int $id, string $date): mixed
|
|
{
|
|
return self::get("/property/{$id}/capacities/daily/{$date}");
|
|
}
|
|
|
|
public static function propertyNeighbours(int $id): mixed
|
|
{
|
|
return self::get("/property/{$id}/neighbours");
|
|
}
|
|
|
|
public static function regions(): mixed
|
|
{
|
|
return self::get('/regions');
|
|
}
|
|
|
|
public static function regionBase(int $id): mixed
|
|
{
|
|
return self::get("/region/{$id}/base");
|
|
}
|
|
|
|
public static function regionPropertiesCapacities(int $id): mixed
|
|
{
|
|
return self::get("/region/{$id}/properties/capacities");
|
|
}
|
|
|
|
public static function regionCapacitiesMonthly(int $id, string $date): mixed
|
|
{
|
|
return self::get("/region/{$id}/capacities/monthly/{$date}");
|
|
}
|
|
|
|
public static function regionCapacitiesDaily(int $id, string $date): mixed
|
|
{
|
|
return self::get("/region/{$id}/capacities/daily/{$date}");
|
|
}
|
|
|
|
public static function regionCapacities(int $id): mixed
|
|
{
|
|
return self::get("/region/{$id}/capacities");
|
|
}
|
|
|
|
public static function regionMovingAverage(int $id, string $date): mixed
|
|
{
|
|
return self::get("/region/{$id}/moving-average/{$date}");
|
|
}
|
|
|
|
}
|