ConsultancyProject_2_ETL/dashboard/app/Api.php

116 lines
2.8 KiB
PHP
Raw Normal View History

2024-12-18 15:14:13 +01:00
<?php
namespace App;
2025-01-12 20:55:46 +01:00
use Illuminate\Support\Facades\Cache;
2024-12-18 15:14:13 +01:00
use Illuminate\Support\Facades\Http;
/*
* Class contains methods which make calls to the API.
* Successfull calls get cached.
*/
2024-12-18 15:14:13 +01:00
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);
2024-12-18 15:14:13 +01:00
// return result and cache it
2024-12-18 15:14:13 +01:00
if($get->successful()){
$result = $get->json();
Cache::put($request, $result);
return $result;
2024-12-18 15:14:13 +01:00
}
return null;
}
public static function propertiesGrowth(): mixed
2024-12-18 19:52:06 +01:00
{
return self::get('/properties/growth');
}
public static function propertiesGeo(): mixed
2024-12-18 19:52:06 +01:00
{
return self::get('/properties/geo');
}
public static function propertyExtractions(int $id): mixed
2024-12-18 15:14:13 +01:00
{
2024-12-18 19:52:06 +01:00
return self::get("/property/{$id}/extractions");
}
public static function propertyCapacities(int $id): mixed
{
return self::get("/property/{$id}/capacities");
}
2024-12-18 19:52:06 +01:00
public static function propertyBase(int $id): mixed
{
return self::get("/property/{$id}/base");
2024-12-18 15:14:13 +01:00
}
public static function propertyCapacitiesMonthly(int $id, string $date): mixed
2025-01-12 20:55:46 +01:00
{
return self::get("/property/{$id}/capacities/monthly/{$date}");
2025-01-12 20:55:46 +01:00
}
public static function propertyCapacitiesDaily(int $id, string $date): mixed
2024-12-20 21:46:54 +01:00
{
return self::get("/property/{$id}/capacities/daily/{$date}");
2024-12-20 21:46:54 +01:00
}
public static function propertyNeighbours(int $id): mixed
2025-01-13 22:50:03 +01:00
{
return self::get("/property/{$id}/neighbours");
2025-01-13 22:50:03 +01:00
}
public static function regions(): mixed
{
return self::get('/regions');
}
public static function regionBase(int $id): mixed
2025-01-13 22:50:03 +01:00
{
return self::get("/region/{$id}/base");
2025-01-13 22:50:03 +01:00
}
public static function regionPropertiesCapacities(int $id): mixed
{
return self::get("/region/{$id}/properties/capacities");
}
public static function regionCapacitiesMonthly(int $id, string $date): mixed
2025-01-09 18:34:20 +01:00
{
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}");
2025-01-09 18:34:20 +01:00
}
2024-12-18 15:14:13 +01:00
public static function regionCapacities(int $id): mixed
{
return self::get("/region/{$id}/capacities");
}
2024-12-18 15:14:13 +01:00
public static function regionMovingAverage(int $id, string $date): mixed
{
2025-01-18 17:31:31 +01:00
return self::get("/region/{$id}/moving-average/{$date}");
}
2024-12-18 15:14:13 +01:00
}