Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

A Laravel wrapper for Spoonacular API, gets data about many recipes, foods and other options.

License

Notifications You must be signed in to change notification settings

joslmt/spoonacular-laravel-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A Laravel wrapper for Spoonacular API, gets data about many recipes, foods and other options.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages