spoonacular 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a2724db661b4178218c568e493c9797a6fffbd6
4
+ data.tar.gz: d84371caaa8c3cf45ae043626b4475cfe866b299
5
+ SHA512:
6
+ metadata.gz: 55c496cc0c46bc8d0617b0373a87613704d5696efaf490745e75dd181d80d21bb03a3f8fd8996df7e842b47b1938fb2b4e5075b889af489a668975058117b44d
7
+ data.tar.gz: 416bf959be946ba04e54a7d89bcdaf5ba456b4e0dd047406e78659682eaf9dfc7bb0ae147095e91572fa3542fc500f7c1df418fb7e815d7b38441c934f4d2bff
@@ -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,9 @@
1
+ module Spoonacular
2
+
3
+ class API
4
+ def initialize(key)
5
+ @key ||= key
6
+ end
7
+ end
8
+
9
+ end
@@ -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 = "#{querify(options)}"
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 = "#{querify(options)}"
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 = "#{querify(options)}"
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,19 @@
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
+ 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 = "#{querify(options)}"
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=#{querify(ingredients)}&#{querify(options)}"
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 = "#{querify(options)}"
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 = "#{querify(options)}"
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 = "#{querify(options)}"
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,22 @@
1
+ def querify(object)
2
+ if object.is_a? String
3
+ return object.gsub(/,\s?/, "%2C").gsub(" ", "+")
4
+ elsif object.is_a? Array
5
+ return object.join("%2C").gsub(" ", "+")
6
+ elsif object.is_a? Hash
7
+ result = []
8
+ object.each do |key, value|
9
+ result << "#{to_camel_case(key.to_s)}=#{querify(value)}"
10
+ end
11
+ return result.join("&")
12
+ end
13
+ end
14
+
15
+ def to_camel_case(string)
16
+ string.chars.length.times do |i|
17
+ if string[i] == "_"
18
+ string[i+1] = string[i+1].upcase
19
+ end
20
+ end
21
+ return string.delete "_"
22
+ 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
@@ -0,0 +1,5 @@
1
+ module Spoonacular
2
+
3
+ VERSION = "0.0.2"
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spoonacular
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Woznicki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-16 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: daniel.woznicki@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: https://github.com/dwoznicki/spoonacular
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.4.5
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Spoonacular-gem
72
+ test_files: []