Class: Spoonacular::API

Inherits:
Object show all
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

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(options={})
	method = "/recipes/searchComplex"
	query = "#{options.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, options={})
	method = "/recipes/findByIngredients"
	query = "ingredients=#{ingredients.querify}&#{options.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(options={})
	method = "/recipes/findByNutrients"
	query = "#{options.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(options={})
	method = "/food/products/search"
	query = "#{options.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(options={})
	method = "/recipes/search"
	query = "#{options.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(options={})
	method = "/recipes/visualizeIngredients"
	uri = Spoonacular.build_endpoint(method, "")[0..-2]
	params = "#{options.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(options={})
	method = "/recipes/visualizeNutrition"
	uri = Spoonacular.build_endpoint(method, "")[0..-2]
	params = "#{options.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(options={})
	method = "/recipes/visualizePriceEstimator"
	uri = Spoonacular.build_endpoint(method, "")[0..-2]
	params = "#{options.querify}"
	response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params})
	return response
end