Class: Spoonacular::API
- Defined in:
- lib/spoonacular/api/base.rb,
lib/spoonacular/api/data.rb,
lib/spoonacular/api/search.rb,
lib/spoonacular/api/compute.rb,
lib/spoonacular/api/extract.rb
Instance Method Summary collapse
- #analyze_recipe_search(query) ⇒ Object
- #autocomplete_ingredient_search(ingredient) ⇒ Object
- #complex_recipe_search(options = {}) ⇒ Object
- #extract_recipe(url) ⇒ Object
- #find_by_ingredients(ingredients, options = {}) ⇒ Object
- #find_by_nutrients(options = {}) ⇒ Object
- #find_similar_recipes(id) ⇒ Object
- #get_product_information(id) ⇒ Object
- #get_recipe_information(id) ⇒ Object
-
#initialize(key) ⇒ API
constructor
A new instance of API.
- #match_recipes_to_calories(target_calories, time_frame) ⇒ Object
- #parse_ingredients(ingredient_list, servings) ⇒ Object
- #search_grocery_products(options = {}) ⇒ Object
- #search_recipes(options = {}) ⇒ Object
- #summarize_recipe(id) ⇒ Object
- #visualize_ingredients(options = {}) ⇒ Object
- #visualize_nutrition(options = {}) ⇒ Object
- #visualize_price_breakdown(options = {}) ⇒ Object
Constructor Details
#initialize(key) ⇒ API
Returns a new instance of API.
4 5 6 |
# File 'lib/spoonacular/api/base.rb', line 4 def initialize(key) @key ||= key end |
Instance Method Details
#analyze_recipe_search(query) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/spoonacular/api/extract.rb', line 4 def analyze_recipe_search(query) method = "/recipes/queries/analyze" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri, accept_json: true}) return response end |
#autocomplete_ingredient_search(ingredient) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/spoonacular/api/search.rb', line 4 def autocomplete_ingredient_search(ingredient) method = "/food/ingredients/autocomplete" query = "query=#{ingredient}" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri}) return response end |
#complex_recipe_search(options = {}) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/spoonacular/api/search.rb', line 12 def complex_recipe_search(={}) method = "/recipes/searchComplex" query = "#{.querify}" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri}) return response end |
#extract_recipe(url) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/spoonacular/api/extract.rb', line 11 def extract_recipe(url) method = "/recipes/extract" query = "forceExtraction=false&url=#{url}" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri}) return response end |
#find_by_ingredients(ingredients, options = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/spoonacular/api/search.rb', line 20 def find_by_ingredients(ingredients, ={}) method = "/recipes/findByIngredients" query = "ingredients=#{ingredients.querify}&#{.querify}" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri, accept_json: true}) return response end |
#find_by_nutrients(options = {}) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/spoonacular/api/search.rb', line 28 def find_by_nutrients(={}) method = "/recipes/findByNutrients" query = "#{.querify}" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri}) return response end |
#find_similar_recipes(id) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/spoonacular/api/search.rb', line 36 def find_similar_recipes(id) method = "/recipes/#{id}/similar" uri = Spoonacular.build_endpoint(method, "") response = Spoonacular.get({key: @key, uri: uri}) return response end |
#get_product_information(id) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/spoonacular/api/data.rb', line 4 def get_product_information(id) method = "/food/products/#{id}" uri = Spoonacular.build_endpoint(method, "") response = Spoonacular.get({key: @key, uri: uri}) return response end |
#get_recipe_information(id) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/spoonacular/api/data.rb', line 11 def get_recipe_information(id) method = "/recipes/#{id}/information" uri = Spoonacular.build_endpoint(method, "") response = Spoonacular.get({key: @key, uri: uri}) return response end |
#match_recipes_to_calories(target_calories, time_frame) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/spoonacular/api/compute.rb', line 4 def match_recipes_to_calories(target_calories, time_frame) method = "/recipes/mealplans/generate" query = "targetCalories=#{target_calories}&timeFrame=#{time_frame}" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri}) return response end |
#parse_ingredients(ingredient_list, servings) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/spoonacular/api/extract.rb', line 19 def parse_ingredients(ingredient_list, servings) method = "/recipes/parseIngredients" uri = Spoonacular.build_endpoint(method, "")[0..-2] params = {"ingredientList" => ingredient_list, "servings" => servings} response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params}) return response end |
#search_grocery_products(options = {}) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/spoonacular/api/search.rb', line 43 def search_grocery_products(={}) method = "/food/products/search" query = "#{.querify}" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri}) return response end |
#search_recipes(options = {}) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/spoonacular/api/search.rb', line 51 def search_recipes(={}) method = "/recipes/search" query = "#{.querify}" uri = Spoonacular.build_endpoint(method, query) response = Spoonacular.get({key: @key, uri: uri}) return response end |
#summarize_recipe(id) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/spoonacular/api/compute.rb', line 12 def summarize_recipe(id) method = "/recipes/#{id}/summary" uri = Spoonacular.build_endpoint(method, "") response = Spoonacular.get({key: @key, uri: uri}) return response end |
#visualize_ingredients(options = {}) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/spoonacular/api/compute.rb', line 19 def visualize_ingredients(={}) method = "/recipes/visualizeIngredients" uri = Spoonacular.build_endpoint(method, "")[0..-2] params = "#{.querify}" response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params}) return response end |
#visualize_nutrition(options = {}) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/spoonacular/api/compute.rb', line 27 def visualize_nutrition(={}) method = "/recipes/visualizeNutrition" uri = Spoonacular.build_endpoint(method, "")[0..-2] params = "#{.querify}" response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params}) return response end |
#visualize_price_breakdown(options = {}) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/spoonacular/api/compute.rb', line 35 def visualize_price_breakdown(={}) method = "/recipes/visualizePriceEstimator" uri = Spoonacular.build_endpoint(method, "")[0..-2] params = "#{.querify}" response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params}) return response end |