yummly 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -2
- data/lib/yummly/api.rb +26 -23
- data/lib/yummly/configuration.rb +18 -16
- data/lib/yummly/connection.rb +42 -20
- data/lib/yummly/flavor.rb +17 -15
- data/lib/yummly/image.rb +14 -12
- data/lib/yummly/nutrition_estimate.rb +17 -15
- data/lib/yummly/recipe.rb +79 -77
- data/lib/yummly/source.rb +14 -12
- data/lib/yummly/unit.rb +17 -15
- data/lib/yummly/version.rb +1 -1
- data/lib/yummly.rb +4 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -51,8 +51,8 @@ The find command returns a single Yummly::Recipe object:
|
|
51
51
|
## The Recipe object
|
52
52
|
|
53
53
|
The Yummly ruby wrapper returns all results as recipe objects. These objects normalize the API responses to make it
|
54
|
-
easier for developers to interact with recipes from ruby. All Yummly recipe attributes have been directly mapped
|
55
|
-
|
54
|
+
easier for developers to interact with recipes from ruby. All Yummly recipe attributes have been directly mapped.
|
55
|
+
In cases where the JSON response returned an array for a specific attribute, an array of appropriate objects are returned
|
56
56
|
from the ruby Recipe object.
|
57
57
|
|
58
58
|
For example, to access the thumbnail image for a recipe:
|
@@ -60,6 +60,8 @@ For example, to access the thumbnail image for a recipe:
|
|
60
60
|
recipe = Yummly.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')
|
61
61
|
recipe.images.first.small_url
|
62
62
|
|
63
|
+
(Shhhh, there's also a Recipe#thumbnail convenience method!)
|
64
|
+
|
63
65
|
Explore the Yummly::Recipe class to see the full range of available attributes.
|
64
66
|
|
65
67
|
## Contributing
|
data/lib/yummly/api.rb
CHANGED
@@ -6,30 +6,33 @@
|
|
6
6
|
# Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')
|
7
7
|
# @example
|
8
8
|
# Yummly::Api.search('Onion soup')
|
9
|
-
class Yummly::Api
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
# @param [String] id The yummly recipe identifier.
|
14
|
-
# @return [Yummly::Recipe] a instance of a recipe object
|
15
|
-
# @example
|
16
|
-
# recipe = Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')
|
17
|
-
def self.find(id)
|
18
|
-
recipe_json = Yummly::Connection.get("recipe/#{id}")
|
19
|
-
Yummly::Recipe.new(recipe_json)
|
20
|
-
end
|
10
|
+
module Yummly
|
11
|
+
class Api
|
21
12
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
result["matches"].collect { |recipe_json| Yummly::Recipe.new(recipe_json) }
|
33
|
-
end
|
13
|
+
# Retrieves a single recipe.
|
14
|
+
#
|
15
|
+
# @param [String] id The yummly recipe identifier.
|
16
|
+
# @return [Yummly::Recipe] a instance of a recipe object
|
17
|
+
# @example
|
18
|
+
# recipe = Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')
|
19
|
+
def self.find(id)
|
20
|
+
recipe_json = Yummly::Connection.get("recipe/#{id}")
|
21
|
+
Yummly::Recipe.new(recipe_json)
|
22
|
+
end
|
34
23
|
|
24
|
+
# Searches for recipes that match the supplied search terms.
|
25
|
+
#
|
26
|
+
# @param [String] terms A string of terms used to search API
|
27
|
+
# @param [Hash] params Additional options to pass to the search API
|
28
|
+
# @return [Array] a collection of recipe objects
|
29
|
+
# @example
|
30
|
+
# recipes = Yummly::Api.search('Onion soup')
|
31
|
+
def self.search(terms, params = {})
|
32
|
+
params[:q] = terms unless params.has_key?(:q)
|
33
|
+
result = Yummly::Connection.get(:recipes, params)
|
34
|
+
result["matches"].collect { |recipe_json| Yummly::Recipe.new(recipe_json) }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
35
38
|
end
|
data/lib/yummly/configuration.rb
CHANGED
@@ -13,24 +13,26 @@
|
|
13
13
|
# config.app_id = "12345"
|
14
14
|
# config.app_key = "XXXXXXXXXXXXXXXXXXXXXXXX"
|
15
15
|
# end
|
16
|
-
|
16
|
+
module Yummly
|
17
|
+
class Configuration
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
attr_accessor :app_key,
|
20
|
+
:app_id,
|
21
|
+
:use_ssl
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# Creates a configuration object, defaulting use_ssl to false.
|
24
|
+
def initialize
|
25
|
+
@use_ssl = false
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
# Returns true if API calls to Yummly should use SSL.
|
29
|
+
#
|
30
|
+
# @return [Boolean] true if API calls to Yummly should use SSL
|
31
|
+
# @example
|
32
|
+
# Yummly.configuration.use_ssl?
|
33
|
+
def use_ssl?
|
34
|
+
use_ssl
|
35
|
+
end
|
35
36
|
|
37
|
+
end
|
36
38
|
end
|
data/lib/yummly/connection.rb
CHANGED
@@ -1,29 +1,51 @@
|
|
1
1
|
# This class handles the HTTP interactions with the Yummly API calls.
|
2
|
-
|
2
|
+
module Yummly
|
3
|
+
class Connection
|
3
4
|
|
4
|
-
|
5
|
+
attr_accessor :connection
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
JSON.parse(response.body)
|
11
|
-
end
|
7
|
+
def self.get(command, params = {})
|
8
|
+
response = self.api_connection.get(build_uri(command, params))
|
9
|
+
self.parse_response(response)
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def self.api_connection
|
13
|
+
Faraday.new(:url => "#{self.protocol}://api.yummly.com") do |faraday|
|
14
|
+
faraday.request :url_encoded # form-encode POST params
|
15
|
+
faraday.response :logger # log requests to STDOUT
|
16
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
17
|
+
end
|
18
18
|
end
|
19
|
-
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def self.parse_response(response)
|
21
|
+
case response.status
|
22
|
+
when 409 then
|
23
|
+
raise Yummly::PermissionError, response.body
|
24
|
+
when 404 then
|
25
|
+
nil
|
26
|
+
when 200 then
|
27
|
+
JSON.parse(response.body)
|
28
|
+
end
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
31
|
+
def build_uri(command, params)
|
32
|
+
query_string = build_params_query_string(params)
|
33
|
+
"/#{self.api_version}/api/#{command}?#{query_string}"
|
34
|
+
end
|
28
35
|
|
36
|
+
def self.build_params_query_string(params)
|
37
|
+
params['_app_id'] = Yummly.configuration.app_id
|
38
|
+
params['_app_key'] = Yummly.configuration.app_key
|
39
|
+
Rack::Utils.build_query(params)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.protocol
|
43
|
+
Yummly.configuration.use_ssl? ? 'https' : 'http'
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.api_version
|
47
|
+
Yummly::API_VERSION
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
29
51
|
end
|
data/lib/yummly/flavor.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
# Contains the flavor scores for a recipe, each on a range from 0 to 1.
|
2
|
-
|
2
|
+
module Yummly
|
3
|
+
class Flavor
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
attr_accessor :spiciness,
|
6
|
+
:bitterness,
|
7
|
+
:sweetness,
|
8
|
+
:savoriness,
|
9
|
+
:saltiness,
|
10
|
+
:sourness
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
def initialize(values)
|
13
|
+
@spiciness = values["Piquant"]
|
14
|
+
@bitterness = values["Bitter"]
|
15
|
+
@sweetness = values["Sweet"]
|
16
|
+
@savoriness = values["Meaty"]
|
17
|
+
@sourness = values["Sour"]
|
18
|
+
@saltiness = values["Salty"]
|
19
|
+
end
|
19
20
|
|
21
|
+
end
|
20
22
|
end
|
data/lib/yummly/image.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
# The image that should be displayed along with the recipe if images are available. Comes in 3 different sizes.
|
2
|
-
|
2
|
+
module Yummly
|
3
|
+
class Image
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
# small (90×60)
|
6
|
+
attr_accessor :small_url
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
# medium (180×120)
|
9
|
+
attr_accessor :medium_url
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
# large (360×240)
|
12
|
+
attr_accessor :large_url
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def initialize(values)
|
15
|
+
@large_url = values["hostedLargeUrl"]
|
16
|
+
@medium_url = values["hostedMediumUrl"]
|
17
|
+
@small_url = values["hostedSmallUrl"]
|
18
|
+
end
|
18
19
|
|
20
|
+
end
|
19
21
|
end
|
@@ -1,25 +1,27 @@
|
|
1
1
|
# The nutritional composition of the recipe, in the form of a list of nutrients and their amounts, per serving. Yummly
|
2
2
|
# will return nutrition estimates only for those recipes where we are reasonably confident in their accuracy. These are
|
3
3
|
# only estimates and you should be clear about that in what you tell your users.
|
4
|
-
|
4
|
+
module Yummly
|
5
|
+
class NutritionEstimate
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
# Nutrition attribute’s search parameter name.
|
8
|
+
attr_accessor :attribute
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
# Display name of this nutrition attribute.
|
11
|
+
attr_accessor :description
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
# Nutrition attribute value for this recipe.
|
14
|
+
attr_accessor :value
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
# Implied unit of measure as a Yummly::Unit object.
|
17
|
+
attr_accessor :unit
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def initialize(values)
|
20
|
+
@attribute = values["attribute"]
|
21
|
+
@description = values["description"]
|
22
|
+
@value = values["value"]
|
23
|
+
@unit = Yummly::Unit.new(values["unit"])
|
24
|
+
end
|
24
25
|
|
26
|
+
end
|
25
27
|
end
|
data/lib/yummly/recipe.rb
CHANGED
@@ -4,104 +4,106 @@
|
|
4
4
|
# When a response attribute is an array, collections of related objects will be created for convenience. For example,
|
5
5
|
# the "images" attribute on the response maps to the #images method which returns a collection of Yummlly::Image
|
6
6
|
# objects.
|
7
|
-
|
7
|
+
module Yummly
|
8
|
+
class Recipe
|
8
9
|
|
9
|
-
|
10
|
+
attr_accessor :response
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def initialize(recipe_json)
|
13
|
+
@response = recipe_json
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
# Nutrition attribute’s search parameter name.
|
17
|
+
def attribute
|
18
|
+
response["attribute"]
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def attributes
|
22
|
+
response["attributes"]
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def attribution
|
26
|
+
response["attribution"]
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def description
|
30
|
+
response["description"]
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
# @return [Yummly::Flavor] instance of a Yummly::Flavor object
|
34
|
+
def flavor
|
35
|
+
@flavor ||= Yummly::Flavor.new(response["flavors"])
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
# @return [String] the Yummly id for this recipe.
|
39
|
+
def id
|
40
|
+
response["id"]
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
# @return [Array] collection of Yummly::Image objects.
|
44
|
+
def images
|
45
|
+
@images ||= images_node.collect { |image| Yummly::Image.new(image) }
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
# @return [Array] collection of strings of ingredients.
|
49
|
+
def ingredients
|
50
|
+
response["ingredients"] || ingredient_lines
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
# @return [Array] collection of strings of ingredients.
|
54
|
+
def ingredient_lines
|
55
|
+
response["ingredientLines"]
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
# Returns the name of the recipe, automatically finding it using the correct response node.
|
59
|
+
# @return [String] name of the recipe
|
60
|
+
def name
|
61
|
+
response["name"] || recipe_name
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
# @return [Integer] number of servings this recipe provides.
|
65
|
+
def number_of_servings
|
66
|
+
response["numberOfServings"]
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
# The nutritional composition of the recipe, in the form of a list of nutrients and their amounts, per serving. We
|
70
|
+
# will return nutrition estimates only for those recipes where we are reasonably confident in their accuracy. These
|
71
|
+
# are only estimates and you should be clear about that in what you tell your users.
|
72
|
+
# @return [Array] collection of Yummly::NutritionEstimate objects.
|
73
|
+
def nutrition_estimates
|
74
|
+
@nutrition_estimates ||= response["nutritionEstimates"].collect { |ne| Yummly::NutritionEstimate.new(ne) }
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
def rating
|
78
|
+
response["rating"]
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
def recipe_name
|
82
|
+
response["recipeName"]
|
83
|
+
end
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def total_time
|
86
|
+
response["totalTime"]
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
def total_time_in_seconds
|
90
|
+
response["totalTimeInSeconds"]
|
91
|
+
end
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
def thumbnail
|
94
|
+
if images
|
95
|
+
images.first.small_url
|
96
|
+
end
|
95
97
|
end
|
96
|
-
end
|
97
98
|
|
98
|
-
|
99
|
+
private
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
# The search and find API calls populate different image attribute nodes in their respective responses. This method
|
102
|
+
# determines which one has been populated and returns a populated node for the images collection method to use. This
|
103
|
+
# allows the developer using this API to only use one method to access images.
|
104
|
+
def images_node
|
105
|
+
response["images"] || response["smallImageUrls"].collect { |url| {"hostedSmallUrl" => url} }
|
106
|
+
end
|
106
107
|
|
108
|
+
end
|
107
109
|
end
|
data/lib/yummly/source.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
# Contains details about the origin of the recipe.
|
2
|
-
|
2
|
+
module Yummly
|
3
|
+
class Source
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
# The original source url of this recipe.
|
6
|
+
attr_accessor :recipe_url
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
# The url of the source site of this recipe.
|
9
|
+
attr_accessor :site_url
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
# The display name of the source site.
|
12
|
+
attr_accessor :display_name
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def initialize(values)
|
15
|
+
@recipe_url = values["sourceRecipeUrl"]
|
16
|
+
@site_url = values["sourceSiteUrl"]
|
17
|
+
@display_name= values["sourceDisplayName"]
|
18
|
+
end
|
18
19
|
|
20
|
+
end
|
19
21
|
end
|
data/lib/yummly/unit.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
# The implied unit of measure for a nutrition estimate.
|
2
|
-
|
2
|
+
module Yummly
|
3
|
+
class Unit
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
# Single unit display name for unit of measure.
|
6
|
+
attr_accessor :name
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
# Single unit abbreviation for unit of measure.
|
9
|
+
attr_accessor :abbreviation
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
# Plural display name for unit of measure.
|
12
|
+
attr_accessor :plural
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
# Plural unit abbreviation for unit of measure.
|
15
|
+
attr_accessor :plural_abbreviation
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def initialize(values)
|
18
|
+
@name = values["name"]
|
19
|
+
@abbreviation = values["abbreviation"]
|
20
|
+
@plural = values["plural"]
|
21
|
+
@plural_abbreviation = values["pluralAbbreviation"]
|
22
|
+
end
|
22
23
|
|
24
|
+
end
|
23
25
|
end
|
data/lib/yummly/version.rb
CHANGED
data/lib/yummly.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "yummly/api"
|
2
|
-
require "yummly/connection"
|
3
2
|
require "yummly/configuration"
|
3
|
+
require "yummly/connection"
|
4
4
|
require "yummly/flavor"
|
5
5
|
require "yummly/image"
|
6
6
|
require "yummly/nutrition_estimate"
|
@@ -31,4 +31,7 @@ module Yummly
|
|
31
31
|
Yummly::Api.find(recipe_id)
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
class Error < StandardError; end
|
36
|
+
class PermissionError < Error; end
|
34
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yummly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.8.
|
94
|
+
rubygems_version: 1.8.24
|
95
95
|
signing_key:
|
96
96
|
specification_version: 3
|
97
97
|
summary: Ruby wrapper to the Yummly API
|