mirror of
https://github.com/kevin-DL/scraps.git
synced 2026-01-11 09:54:32 +00:00
Create spoonacular integration
- Find recipes by ingredients
This commit is contained in:
@@ -62,3 +62,6 @@ AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
|
||||
SPOONACULAR_BASE_API_URL=https://api.spoonacular.com
|
||||
SPOONACULAR_API_KEY=
|
||||
|
||||
26
app/Console/Commands/TestSpoonacularCommand.php
Normal file
26
app/Console/Commands/TestSpoonacularCommand.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\Integrations\Spoonacular\Requests\FindRecipesByIngredients;
|
||||
use App\Http\Integrations\Spoonacular\SpoonacularConnector;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class TestSpoonacularCommand extends Command
|
||||
{
|
||||
protected $signature = 'test:spoonacular';
|
||||
|
||||
protected $description = 'Command description';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$connector = new SpoonacularConnector();
|
||||
$request = new FindRecipesByIngredients(
|
||||
ingredients: ['salmon', 'cheese', 'tomato'],
|
||||
ranking: 2
|
||||
);
|
||||
|
||||
$response = $connector->send($request);
|
||||
dd($response->json());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Integrations\Spoonacular\Requests;
|
||||
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
|
||||
class FindRecipesByIngredients extends Request
|
||||
{
|
||||
/**
|
||||
* 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
49
app/Http/Integrations/Spoonacular/SpoonacularConnector.php
Normal file
49
app/Http/Integrations/Spoonacular/SpoonacularConnector.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Integrations\Spoonacular;
|
||||
|
||||
use Saloon\Http\Auth\QueryAuthenticator;
|
||||
use Saloon\Http\Connector;
|
||||
use Saloon\Traits\Plugins\AcceptsJson;
|
||||
|
||||
class SpoonacularConnector extends Connector
|
||||
{
|
||||
use AcceptsJson;
|
||||
|
||||
/**
|
||||
* The Base URL of the API
|
||||
*/
|
||||
public function resolveBaseUrl(): string
|
||||
{
|
||||
return config('services.spoonacular.api_url');
|
||||
}
|
||||
|
||||
/**
|
||||
* Default headers for every request
|
||||
*/
|
||||
protected function defaultHeaders(): array
|
||||
{
|
||||
return [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Default HTTP client options
|
||||
*/
|
||||
protected function defaultConfig(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function defaultQuery(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function defaultAuth(): QueryAuthenticator
|
||||
{
|
||||
return new QueryAuthenticator('apiKey', config('services.spoonacular.api_key'));
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
"laravel/framework": "^11.9",
|
||||
"laravel/sanctum": "^4.0",
|
||||
"laravel/tinker": "^2.9",
|
||||
"saloonphp/laravel-plugin": "^3.0",
|
||||
"saloonphp/saloon": "^3.0",
|
||||
"tightenco/ziggy": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
|
||||
151
composer.lock
generated
151
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "940a6dea4acc6e6662fc35b0a8bd0bf9",
|
||||
"content-hash": "81d14f9724514fae3a05d53d66d9ed8a",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@@ -3247,6 +3247,155 @@
|
||||
],
|
||||
"time": "2024-04-27T21:32:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "saloonphp/laravel-plugin",
|
||||
"version": "v3.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/saloonphp/laravel-plugin.git",
|
||||
"reference": "15be0d587e61f11076f93d6df30561b88ff837c1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/saloonphp/laravel-plugin/zipball/15be0d587e61f11076f93d6df30561b88ff837c1",
|
||||
"reference": "15be0d587e61f11076f93d6df30561b88ff837c1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/console": "^10.0 || ^11.0",
|
||||
"illuminate/support": "^10.0 || ^11.0",
|
||||
"php": "^8.1",
|
||||
"saloonphp/saloon": "^3.5",
|
||||
"symfony/finder": "^6.4 || ^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.48",
|
||||
"orchestra/testbench": "^8.21 || ^9.0",
|
||||
"pestphp/pest": "^2.32",
|
||||
"phpstan/phpstan": "^1.10.56"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"aliases": {
|
||||
"Saloon": "Saloon\\Laravel\\Facades\\Saloon"
|
||||
},
|
||||
"providers": [
|
||||
"Saloon\\Laravel\\SaloonServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Saloon\\Laravel\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sam Carré",
|
||||
"email": "29132017+Sammyjo20@users.noreply.github.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "The official Laravel plugin for Saloon",
|
||||
"homepage": "https://github.com/saloonphp/laravel-plugin",
|
||||
"keywords": [
|
||||
"api",
|
||||
"api-integrations",
|
||||
"saloon",
|
||||
"saloonphp",
|
||||
"sdk"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/saloonphp/laravel-plugin/tree/v3.5.0"
|
||||
},
|
||||
"time": "2024-03-13T18:48:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "saloonphp/saloon",
|
||||
"version": "v3.9.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/saloonphp/saloon.git",
|
||||
"reference": "ea50417e85aeaa4280b8ff8e916162a667603c99"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/saloonphp/saloon/zipball/ea50417e85aeaa4280b8ff8e916162a667603c99",
|
||||
"reference": "ea50417e85aeaa4280b8ff8e916162a667603c99",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^7.6",
|
||||
"guzzlehttp/promises": "^1.5 || ^2.0",
|
||||
"guzzlehttp/psr7": "^2.0",
|
||||
"php": "^8.1",
|
||||
"psr/http-factory": "^1.0",
|
||||
"psr/http-message": "^1.1 || ^2.0"
|
||||
},
|
||||
"conflict": {
|
||||
"sammyjo20/saloon": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-simplexml": "*",
|
||||
"friendsofphp/php-cs-fixer": "^3.5",
|
||||
"illuminate/collections": "^9.39 || ^10.0",
|
||||
"league/flysystem": "^3.0",
|
||||
"pestphp/pest": "^2.6",
|
||||
"phpstan/phpstan": "^1.11.4",
|
||||
"saloonphp/xml-wrangler": "^1.1",
|
||||
"spatie/ray": "^1.33",
|
||||
"symfony/dom-crawler": "^6.0 || ^7.0",
|
||||
"symfony/var-dumper": "^6.3 || ^7.0"
|
||||
},
|
||||
"suggest": {
|
||||
"illuminate/collections": "Required for the response collect() method.",
|
||||
"saloonphp/xml-wrangler": "Required for the response xmlReader() method.",
|
||||
"symfony/dom-crawler": "Required for the response dom() method.",
|
||||
"symfony/var-dumper": "Required for default debugging drivers."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Saloon\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sam Carré",
|
||||
"email": "29132017+Sammyjo20@users.noreply.github.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Build beautiful API integrations and SDKs with Saloon",
|
||||
"homepage": "https://github.com/saloonphp/saloon",
|
||||
"keywords": [
|
||||
"api",
|
||||
"api-integrations",
|
||||
"saloon",
|
||||
"sammyjo20",
|
||||
"sdk"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/saloonphp/saloon/issues",
|
||||
"source": "https://github.com/saloonphp/saloon/tree/v3.9.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sammyjo20",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-06-09T10:46:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/clock",
|
||||
"version": "v7.1.1",
|
||||
|
||||
38
config/saloon.php
Normal file
38
config/saloon.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Saloon\Http\Senders\GuzzleSender;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Saloon Sender
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value specifies the "sender" class that Saloon should use by
|
||||
| default on all connectors. You can change this sender if you
|
||||
| would like to use your own. You may also specify your own
|
||||
| sender on a per-connector basis.
|
||||
|
|
||||
*/
|
||||
|
||||
'default_sender' => GuzzleSender::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Integrations Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default, this package will create any classes within
|
||||
| `/app/Http/Integrations` directory. If you're using
|
||||
| a different design approach, then your classes
|
||||
| may be in a different place. You can change
|
||||
| that location so that the saloon:list
|
||||
| command will still find your files
|
||||
|
|
||||
*/
|
||||
|
||||
'integrations_path' => base_path('App/Http/Integrations'),
|
||||
];
|
||||
@@ -35,4 +35,9 @@ return [
|
||||
],
|
||||
],
|
||||
|
||||
'spoonacular' => [
|
||||
'api_url' => env('SPOONACULAR_BASE_API_URL'),
|
||||
'api_key' => env('SPOONACULAR_API_KEY'),
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user