josmlt/spoonacular-laravel-wrapper

This package is abandoned and no longer maintained. No replacement package was suggested.

A Laravel wrapper for Spoonacular API

v2.0.0 2021-08-29 13:58 UTC

This package is auto-updated.

Last update: 2022-10-29 03:20:53 UTC


README

laravel-logolockup-cmyk-red.svg 68747470733a2f2f73706f6f6e6163756c61722e636f6d2f696d616765732f73706f6f6e6163756c61722d6c6f676f2d622e737667

Spoonacular Laravel Wrapper

What is 📝

It's a package that uses Facades to request resources from Spoonacular API, like recipes, random recipes, nutrients and offers different sort options like for calories, intolerances etc.

Purpose

It was made to learn how Facades and Laravel packages works.

Steps to installation ℹ️

It's necessary register in Spoonacular and get an api key.

Package Locally Development ℹ️

We need to create a folder, within it we create a Laravel project and clone the repository. Structure similar to this :

-- foo
    -- laravel_project
    -- package_laravel

After that, open composer.json file in our main Laravel project, add the next properties :

 "require": {
     [. . .]
        "josmlt/spoonacular-laravel-wrapper": "dev-master",
    }
"repositories": [
      {
          "type": "path",
          "url": "../spoon-wrapper"
      }
    ],

Next step is require the package to our project, execute :

composer require josmlt/spoonacular-laravel-wrapper

We'll see the message: Installing josmlt/spoonacular-laravel-wrapper (dev-master): Junctioning from ../spoon-wrapper

Then execute the follow command, it publishes the config file :

php artisan vendor:publish --tag=spoonacular

Finally we have two options, first we could have a default value of SPOONACULAR_API_KEY, within config/spoonacular.php or as well we can add in our .env a new environment variable like SPOONACULAR_API_KEY = ""

From Packagist ℹ️

We need to pull the package from packagist to our Laravel project.

composer require josmlt/spoonacular-laravel-wrapper

After a correct installation, we need to publish a custom config file, execute:

php artisan vendor:publish

Finally, we move into :

config/spoonacular.php

And add our api key from Spoonacular, or alternative you can create a new environment variable named like SPOONACULAR_API_KEY.

How to use it ❓

👉 If we want to get recipes with tomato, for example, we just need to search recipes with this keyword, type:

Spoonacular::searchRecipes('tomato');

👉 But what else? If you need a complex search, because for example you're intolerant with eggs or you want order the results for amount of calories ... Type :

Spoonacular::searchRecipes(
    [
        'query' => 'tomato',
        'intolerances' => 'egg',
        'sort' => 'calories'
    ]
);

👉 Or get random recipes :

Spoonacular::getRandomRecipes();

Testing ✔️

This package provides a few tests, the objective is to get more confident using the package and check if it's possible add a new feature without broke nothing valuable.

Within the package, execute the follow : vendor/bin/phpunit tests/Unit/SpoonacularFacadeTest.php

Don't forget execute composer install after download or clone the project, also get a valid APIKEY.