refactoring; more consistent naming for API endpoint and variables.
This commit is contained in:
1 parent
e0c8b3eb1b
commit
e4e05b4788
16 files changed
+325
-238
No files matched your search
+35
-29
@@ -5,6 +5,11 @@ 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
|
||||
{
|
||||
|
||||
@@ -14,12 +19,15 @@ class Api
|
||||
$endpoint = env('FASTAPI_URI');
|
||||
$request = $endpoint.$path;
|
||||
|
||||
// load from cache if available
|
||||
if (Cache::has($request)) {
|
||||
// return Cache::get($request);
|
||||
//return Cache::get($request);
|
||||
}
|
||||
|
||||
$get = Http::timeout(1600)->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);
|
||||
@@ -29,27 +37,22 @@ class Api
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function propertiesPerRegion()
|
||||
{
|
||||
return self::get('/region/properties');
|
||||
}
|
||||
|
||||
public static function propertiesGrowth()
|
||||
public static function propertiesGrowth(): mixed
|
||||
{
|
||||
return self::get('/properties/growth');
|
||||
}
|
||||
|
||||
public static function propertiesGeo()
|
||||
public static function propertiesGeo(): mixed
|
||||
{
|
||||
return self::get('/properties/geo');
|
||||
}
|
||||
|
||||
public static function propertyExtractions(int $id)
|
||||
public static function propertyExtractions(int $id): mixed
|
||||
{
|
||||
return self::get("/property/{$id}/extractions");
|
||||
}
|
||||
|
||||
public static function propertyCapacities(int $id)
|
||||
public static function propertyCapacities(int $id): mixed
|
||||
{
|
||||
return self::get("/property/{$id}/capacities");
|
||||
}
|
||||
@@ -59,6 +62,26 @@ class Api
|
||||
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");
|
||||
@@ -74,24 +97,9 @@ class Api
|
||||
return self::get("/region/{$id}/capacities/monthly/{$date}");
|
||||
}
|
||||
|
||||
public static function propertyCapacitiesMonthly(int $id, string $date): mixed
|
||||
{
|
||||
return self::get("/property/{$id}/capacities/monthly/{$date}");
|
||||
}
|
||||
|
||||
public static function regionCapacitiesDaily(int $id, string $date): mixed
|
||||
{
|
||||
return self::get("/region/{$id}/capacities/weekdays/{$date}");
|
||||
}
|
||||
|
||||
public static function propertyCapacitiesDaily(int $id, string $date): mixed
|
||||
{
|
||||
return self::get("/property/{$id}/capacities/weekdays/{$date}");
|
||||
}
|
||||
|
||||
public static function propertyNeighbours(int $id): mixed
|
||||
{
|
||||
return self::get("/property/{$id}/neighbours");
|
||||
return self::get("/region/{$id}/capacities/daily/{$date}");
|
||||
}
|
||||
|
||||
public static function regionCapacities(int $id): mixed
|
||||
@@ -103,7 +111,5 @@ class Api
|
||||
{
|
||||
return self::get("/region/{$id}/movingAverage/{$date}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user