Files
scraps/app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php
2024-06-23 17:02:50 +01:00

57 lines
1.2 KiB
PHP

<?php
namespace App\Http\Integrations\Spoonacular\Requests;
use Illuminate\Support\Facades\Cache;
use Saloon\CachePlugin\Contracts\Cacheable;
use Saloon\CachePlugin\Contracts\Driver;
use Saloon\CachePlugin\Drivers\LaravelCacheDriver;
use Saloon\CachePlugin\Traits\HasCaching;
use Saloon\Enums\Method;
use Saloon\Http\Request;
class FindRecipesByIngredients extends Request implements Cacheable
{
use HasCaching;
/**
* The HTTP method of the request
*/
protected Method $method = Method::GET;
public function __construct(
protected array $ingredients,
protected int $ranking = 1,
protected int $number = 10
)
{
}
/**
* The endpoint for the request
*/
public function resolveEndpoint(): string
{
return '/recipes/findByIngredients';
}
public function defaultQuery(): array
{
return [
'ingredients' => join(",", $this->ingredients),
'ranking' => $this->ranking,
'number' => $this->number,
];
}
public function resolveCacheDriver(): Driver
{
return new LaravelCacheDriver(Cache::store('redis'));
}
public function cacheExpiryInSeconds(): int
{
return 3600;
}
}