From fadb1bc00a2541aada1c5daeb36c5b6856497be7 Mon Sep 17 00:00:00 2001 From: kevin-DL Date: Sat, 22 Jun 2024 11:13:14 +0100 Subject: [PATCH] Create spoonacular integration - Find recipes by ingredients --- .env.example | 3 + .../Commands/TestSpoonacularCommand.php | 26 +++ .../Requests/FindRecipesByIngredients.php | 39 +++++ .../Spoonacular/SpoonacularConnector.php | 49 ++++++ composer.json | 2 + composer.lock | 151 +++++++++++++++++- config/saloon.php | 38 +++++ config/services.php | 5 + 8 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/TestSpoonacularCommand.php create mode 100644 app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php create mode 100644 app/Http/Integrations/Spoonacular/SpoonacularConnector.php create mode 100644 config/saloon.php diff --git a/.env.example b/.env.example index 7b49625..06bdfe8 100644 --- a/.env.example +++ b/.env.example @@ -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= diff --git a/app/Console/Commands/TestSpoonacularCommand.php b/app/Console/Commands/TestSpoonacularCommand.php new file mode 100644 index 0000000..35c1492 --- /dev/null +++ b/app/Console/Commands/TestSpoonacularCommand.php @@ -0,0 +1,26 @@ +send($request); + dd($response->json()); + } +} diff --git a/app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php b/app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php new file mode 100644 index 0000000..a27fc1f --- /dev/null +++ b/app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php @@ -0,0 +1,39 @@ + join(",", $this->ingredients), + 'ranking' => $this->ranking, + 'number' => $this->number, + ]; + } +} diff --git a/app/Http/Integrations/Spoonacular/SpoonacularConnector.php b/app/Http/Integrations/Spoonacular/SpoonacularConnector.php new file mode 100644 index 0000000..9002555 --- /dev/null +++ b/app/Http/Integrations/Spoonacular/SpoonacularConnector.php @@ -0,0 +1,49 @@ + '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')); + } +} diff --git a/composer.json b/composer.json index 0495b3b..65d27b9 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index c84fcd7..20ed736 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/config/saloon.php b/config/saloon.php new file mode 100644 index 0000000..c9b9e3a --- /dev/null +++ b/config/saloon.php @@ -0,0 +1,38 @@ + 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'), +]; diff --git a/config/services.php b/config/services.php index 27a3617..dbcae27 100644 --- a/config/services.php +++ b/config/services.php @@ -35,4 +35,9 @@ return [ ], ], + 'spoonacular' => [ + 'api_url' => env('SPOONACULAR_BASE_API_URL'), + 'api_key' => env('SPOONACULAR_API_KEY'), + ] + ];