spoon_acular 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/spoonacular.rb +11 -0
- data/lib/spoonacular/api/base.rb +9 -0
- data/lib/spoonacular/api/compute.rb +44 -0
- data/lib/spoonacular/api/data.rb +25 -0
- data/lib/spoonacular/api/extract.rb +28 -0
- data/lib/spoonacular/api/search.rb +60 -0
- data/lib/spoonacular/querify.rb +26 -0
- data/lib/spoonacular/request.rb +26 -0
- data/lib/spoonacular/version.rb +5 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98deb317e508f99c5cb91b6a964afdbb228f3123f0d24f8e6e4a7293c7563e38
|
4
|
+
data.tar.gz: 61aa33a1bcda494c5882bfa87d20d17719bfd7e00fe2da73dc94bc922eed923a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48b35031c89ba98601a5b365de0b7bcf6f9991fd4342ea3dfadd39ef2fabf89b368790a11212e5c9d2dae762d96b08955988c65dbbec71cd4f8a3cd9634ec94d
|
7
|
+
data.tar.gz: 9a39b6f69936350adad702a1bfbc9001b7db0b08fea2c39b1fec75840a9a709953f2a0ae0766a2be3a61884bdd00353de71a4cafd869d94c8eb91d23ac5a1b35
|
data/lib/spoonacular.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'unirest'
|
2
|
+
|
3
|
+
require 'spoonacular/version'
|
4
|
+
require 'spoonacular/request'
|
5
|
+
require 'spoonacular/querify'
|
6
|
+
|
7
|
+
require 'spoonacular/api/base'
|
8
|
+
require 'spoonacular/api/compute'
|
9
|
+
require 'spoonacular/api/data'
|
10
|
+
require 'spoonacular/api/extract'
|
11
|
+
require 'spoonacular/api/search'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Spoonacular
|
2
|
+
|
3
|
+
class API
|
4
|
+
def match_recipes_to_calories(target_calories, time_frame)
|
5
|
+
method = "/recipes/mealplans/generate"
|
6
|
+
query = "targetCalories=#{target_calories}&timeFrame=#{time_frame}"
|
7
|
+
uri = Spoonacular.build_endpoint(method, query)
|
8
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
9
|
+
return response
|
10
|
+
end
|
11
|
+
|
12
|
+
def summarize_recipe(id)
|
13
|
+
method = "/recipes/#{id}/summary"
|
14
|
+
uri = Spoonacular.build_endpoint(method, "")
|
15
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
16
|
+
return response
|
17
|
+
end
|
18
|
+
|
19
|
+
def visualize_ingredients(options={})
|
20
|
+
method = "/recipes/visualizeIngredients"
|
21
|
+
uri = Spoonacular.build_endpoint(method, "")[0..-2]
|
22
|
+
params = "#{options.querify}"
|
23
|
+
response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params})
|
24
|
+
return response
|
25
|
+
end
|
26
|
+
|
27
|
+
def visualize_nutrition(options={})
|
28
|
+
method = "/recipes/visualizeNutrition"
|
29
|
+
uri = Spoonacular.build_endpoint(method, "")[0..-2]
|
30
|
+
params = "#{options.querify}"
|
31
|
+
response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params})
|
32
|
+
return response
|
33
|
+
end
|
34
|
+
|
35
|
+
def visualize_price_breakdown(options={})
|
36
|
+
method = "/recipes/visualizePriceEstimator"
|
37
|
+
uri = Spoonacular.build_endpoint(method, "")[0..-2]
|
38
|
+
params = "#{options.querify}"
|
39
|
+
response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params})
|
40
|
+
return response
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Spoonacular
|
2
|
+
|
3
|
+
class API
|
4
|
+
def get_product_information(id)
|
5
|
+
method = "/food/products/#{id}"
|
6
|
+
uri = Spoonacular.build_endpoint(method, "")
|
7
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
8
|
+
return response
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_recipe_information(id)
|
12
|
+
method = "/recipes/#{id}/information"
|
13
|
+
uri = Spoonacular.build_endpoint(method, "")
|
14
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
15
|
+
return response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_food_information(id, amount, unit)
|
20
|
+
method = "/food/ingredients/#{id}/information?amount=#{amount}, unit=#{unit}"
|
21
|
+
uri = Spoonacular.build_endpoint(method, "")
|
22
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Spoonacular
|
2
|
+
|
3
|
+
class API
|
4
|
+
def analyze_recipe_search(query)
|
5
|
+
method = "/recipes/queries/analyze"
|
6
|
+
uri = Spoonacular.build_endpoint(method, query)
|
7
|
+
response = Spoonacular.get({key: @key, uri: uri, accept_json: true})
|
8
|
+
return response
|
9
|
+
end
|
10
|
+
|
11
|
+
def extract_recipe(url)
|
12
|
+
method = "/recipes/extract"
|
13
|
+
query = "forceExtraction=false&url=#{url}"
|
14
|
+
uri = Spoonacular.build_endpoint(method, query)
|
15
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
16
|
+
return response
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_ingredients(ingredient_list, servings)
|
20
|
+
method = "/recipes/parseIngredients"
|
21
|
+
uri = Spoonacular.build_endpoint(method, "")[0..-2]
|
22
|
+
params = {"ingredientList" => ingredient_list, "servings" => servings}
|
23
|
+
response = Spoonacular.post({key: @key, uri: uri, content_form: true, params: params})
|
24
|
+
return response
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Spoonacular
|
2
|
+
|
3
|
+
class API
|
4
|
+
def autocomplete_ingredient_search(ingredient)
|
5
|
+
method = "/food/ingredients/autocomplete"
|
6
|
+
query = "query=#{ingredient}"
|
7
|
+
uri = Spoonacular.build_endpoint(method, query)
|
8
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
9
|
+
return response
|
10
|
+
end
|
11
|
+
|
12
|
+
def complex_recipe_search(options={})
|
13
|
+
method = "/recipes/searchComplex"
|
14
|
+
query = "#{options.querify}"
|
15
|
+
uri = Spoonacular.build_endpoint(method, query)
|
16
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
17
|
+
return response
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_by_ingredients(ingredients, options={})
|
21
|
+
method = "/recipes/findByIngredients"
|
22
|
+
query = "ingredients=#{ingredients.querify}&#{options.querify}"
|
23
|
+
uri = Spoonacular.build_endpoint(method, query)
|
24
|
+
response = Spoonacular.get({key: @key, uri: uri, accept_json: true})
|
25
|
+
return response
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_by_nutrients(options={})
|
29
|
+
method = "/recipes/findByNutrients"
|
30
|
+
query = "#{options.querify}"
|
31
|
+
uri = Spoonacular.build_endpoint(method, query)
|
32
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
33
|
+
return response
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_similar_recipes(id)
|
37
|
+
method = "/recipes/#{id}/similar"
|
38
|
+
uri = Spoonacular.build_endpoint(method, "")
|
39
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
40
|
+
return response
|
41
|
+
end
|
42
|
+
|
43
|
+
def search_grocery_products(options={})
|
44
|
+
method = "/food/products/search"
|
45
|
+
query = "#{options.querify}"
|
46
|
+
uri = Spoonacular.build_endpoint(method, query)
|
47
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
48
|
+
return response
|
49
|
+
end
|
50
|
+
|
51
|
+
def search_recipes(options={})
|
52
|
+
method = "/recipes/search"
|
53
|
+
query = "#{options.querify}"
|
54
|
+
uri = Spoonacular.build_endpoint(method, query)
|
55
|
+
response = Spoonacular.get({key: @key, uri: uri})
|
56
|
+
return response
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Object
|
2
|
+
|
3
|
+
def querify
|
4
|
+
if self.is_a? String
|
5
|
+
return self.gsub(/,\s?/, "%2C").gsub(" ", "+")
|
6
|
+
elsif self.is_a? Array
|
7
|
+
return self.join("%2C").gsub(" ", "+")
|
8
|
+
elsif self.is_a? Hash
|
9
|
+
result = []
|
10
|
+
self.each do |key, value|
|
11
|
+
result << "#{key.to_s.to_camel_case}=#{value.querify}"
|
12
|
+
end
|
13
|
+
return result.join("&")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_camel_case
|
18
|
+
self.chars.length.times do |i|
|
19
|
+
if self[i] == "_"
|
20
|
+
self[i+1] = self[i+1].upcase
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return self.delete "_"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Spoonacular
|
2
|
+
|
3
|
+
BASE_PATH = "https://spoonacular-recipe-food-nutrition-v1.p.mashape.com"
|
4
|
+
|
5
|
+
def self.build_endpoint(method, query)
|
6
|
+
return "#{BASE_PATH}#{method}?#{query}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.get(options)
|
10
|
+
headers = {"X-Mashape-Key" => options[:key]}
|
11
|
+
headers["Accept"] = "application/json" if options[:accept_json]
|
12
|
+
response = Unirest.get options[:uri], headers: headers
|
13
|
+
return response
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.post(options)
|
17
|
+
headers = {"X-Mashape-Key" => options[:key]}
|
18
|
+
headers["Accept"] = "application/json" if options[:accept_json]
|
19
|
+
headers["Content-Type"] = "application/json" if options[:content_json]
|
20
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded" if options[:content_form]
|
21
|
+
params = options[:params]
|
22
|
+
response = Unirest.post options[:uri], headers: headers, parameters: params
|
23
|
+
return response
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spoon_acular
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rahul Baxi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: unirest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.2
|
33
|
+
description: gem for the Spoonacular API
|
34
|
+
email: rahul.baxi@gmail.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- lib/spoonacular.rb
|
40
|
+
- lib/spoonacular/api/base.rb
|
41
|
+
- lib/spoonacular/api/compute.rb
|
42
|
+
- lib/spoonacular/api/data.rb
|
43
|
+
- lib/spoonacular/api/extract.rb
|
44
|
+
- lib/spoonacular/api/search.rb
|
45
|
+
- lib/spoonacular/querify.rb
|
46
|
+
- lib/spoonacular/request.rb
|
47
|
+
- lib/spoonacular/version.rb
|
48
|
+
homepage: http://rubygems.org/gems/spoon_acular
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.7.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: spoon_acular-gem
|
72
|
+
test_files: []
|