yummly 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/README.md +16 -2
- data/Rakefile +3 -0
- data/lib/yummly.rb +0 -2
- data/lib/yummly/api.rb +1 -1
- data/lib/yummly/connection.rb +2 -2
- data/lib/yummly/recipe.rb +23 -23
- data/lib/yummly/search_result.rb +7 -7
- data/lib/yummly/version.rb +1 -1
- data/spec/api_spec.rb +35 -0
- data/yummly.gemspec +3 -1
- metadata +24 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78e584a537c9ead08a12229ece8b465b98182324
|
4
|
+
data.tar.gz: 4231fb36513103e5392bd5b38d3a548574fc791a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 609b03d8ba5bf41c245bf9d00458b5a5cdea08397c134499dc965fce3e1e48e751ea9b962d8504fced923d60928bc61ec8af832416cd8569bc2c32b5e677ee37
|
7
|
+
data.tar.gz: bbd42efa959d1b8a60de140da85805000606b4437c6803f5a9fcaf549effc1dbc2f064c2a508175a38907038d903397cff0befc7e0369127c40ee67f8735ded6
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
[](https://codeclimate.com/repos/51b73d4a13d6371539009033/feed)
|
2
|
+
[](https://travis-ci.org/twmills/yummly)
|
3
|
+
|
1
4
|
# Yummly
|
2
5
|
|
3
6
|
This is the unofficial ruby wrapper to the Yummly API, "the world's largest and most powerful recipe search site".
|
4
7
|
|
5
8
|
https://developer.yummly.com/
|
6
9
|
|
7
|
-
Still in the baking phase. Tests are being written, lots of churn at the moment.
|
8
|
-
|
9
10
|
## Installation
|
10
11
|
|
11
12
|
Add this line to your application's Gemfile:
|
@@ -24,6 +25,7 @@ Or install it yourself as:
|
|
24
25
|
|
25
26
|
First, configure Yummly with your APP key and ID, for example in an initializer if you're using Rails:
|
26
27
|
|
28
|
+
# config/initializers/yummly.rb
|
27
29
|
Yummly.configure do |config|
|
28
30
|
config.app_id = "21334"
|
29
31
|
config.app_key = "XXXXXXXXXXXXXXXXX"
|
@@ -68,6 +70,18 @@ For example, to access the thumbnail image for a recipe:
|
|
68
70
|
|
69
71
|
Explore the Yummly::Recipe class to see the full range of available attributes.
|
70
72
|
|
73
|
+
## Errors
|
74
|
+
|
75
|
+
The yummly gem handles the API's exceptions by raising the following errors:
|
76
|
+
|
77
|
+
* **Yummly::PermissionError** - When your credentials are incorrect or you've exceeded the rate limit.
|
78
|
+
* **Yummly::InternalServerError** - When something's gone wrong on Yummly's servers
|
79
|
+
* **Yummly::Error** - Any other unexpected error that is returned.
|
80
|
+
|
81
|
+
_**Note:** There had been some discussion about raising an exception when a 404 is encountered, i.e. when a recipe doesn't
|
82
|
+
exist for a given ID. Currently the find call returns nil if a recipe cannot be found, but I may raise a new error in
|
83
|
+
the future if this is considered a truly exceptional case._
|
84
|
+
|
71
85
|
## Contributing
|
72
86
|
|
73
87
|
1. Fork it
|
data/Rakefile
CHANGED
data/lib/yummly.rb
CHANGED
data/lib/yummly/api.rb
CHANGED
@@ -18,7 +18,7 @@ module Yummly
|
|
18
18
|
# recipe = Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')
|
19
19
|
def self.find(id)
|
20
20
|
recipe_json = Yummly::Connection.get("recipe/#{id}")
|
21
|
-
Yummly::Recipe.new(recipe_json)
|
21
|
+
recipe_json.nil? ? nil : Yummly::Recipe.new(recipe_json)
|
22
22
|
end
|
23
23
|
|
24
24
|
# Searches for recipes that match the supplied search terms.
|
data/lib/yummly/connection.rb
CHANGED
@@ -27,10 +27,10 @@ module Yummly
|
|
27
27
|
nil
|
28
28
|
when 200 then
|
29
29
|
JSON.parse(response.body)
|
30
|
-
when 501 then
|
31
|
-
raise Yummly::NotImplementedError, response.body
|
32
30
|
when 500 then
|
33
31
|
raise Yummly::InternalServerError, "An internal error on the Yummly servers was encountered: #{response.body}"
|
32
|
+
else
|
33
|
+
raise Yummly::Error, response.body
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/lib/yummly/recipe.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
# This class maps a Yummly
|
1
|
+
# This class maps a Yummly json to attributes on to a recipe object. Because the search and find API calls return
|
2
2
|
# recipe data slightly different structures, it also automatically rectifies these differences where possible.
|
3
3
|
#
|
4
|
-
# When a
|
4
|
+
# When a json 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
8
|
class Recipe
|
9
9
|
|
10
|
-
attr_accessor :
|
10
|
+
attr_accessor :json
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
@
|
12
|
+
def initialize(json)
|
13
|
+
@json = json
|
14
14
|
end
|
15
15
|
|
16
16
|
# Nutrition attribute’s search parameter name.
|
17
17
|
def attribute
|
18
|
-
|
18
|
+
json["attribute"]
|
19
19
|
end
|
20
20
|
|
21
21
|
def attributes
|
22
|
-
|
22
|
+
json["attributes"]
|
23
23
|
end
|
24
24
|
|
25
25
|
def attribution
|
26
|
-
@attribution ||= Yummly::Attribution.new(
|
26
|
+
@attribution ||= Yummly::Attribution.new(json["attribution"])
|
27
27
|
end
|
28
28
|
|
29
29
|
def description
|
30
|
-
|
30
|
+
json["description"]
|
31
31
|
end
|
32
32
|
|
33
33
|
# @return [Yummly::Flavor] instance of a Yummly::Flavor object
|
34
34
|
def flavor
|
35
|
-
@flavor ||= Yummly::Flavor.new(
|
35
|
+
@flavor ||= Yummly::Flavor.new(json["flavors"])
|
36
36
|
end
|
37
37
|
|
38
38
|
# @return [String] the Yummly id for this recipe.
|
39
39
|
def id
|
40
|
-
|
40
|
+
json["id"]
|
41
41
|
end
|
42
42
|
|
43
43
|
# @return [Array] collection of Yummly::Image objects.
|
@@ -47,23 +47,23 @@ module Yummly
|
|
47
47
|
|
48
48
|
# @return [Array] collection of strings of ingredients.
|
49
49
|
def ingredients
|
50
|
-
|
50
|
+
json["ingredients"] || ingredient_lines
|
51
51
|
end
|
52
52
|
|
53
53
|
# @return [Array] collection of strings of ingredients.
|
54
54
|
def ingredient_lines
|
55
|
-
|
55
|
+
json["ingredientLines"]
|
56
56
|
end
|
57
57
|
|
58
|
-
# Returns the name of the recipe, automatically finding it using the correct
|
58
|
+
# Returns the name of the recipe, automatically finding it using the correct json node.
|
59
59
|
# @return [String] name of the recipe
|
60
60
|
def name
|
61
|
-
|
61
|
+
json["name"] || recipe_name
|
62
62
|
end
|
63
63
|
|
64
64
|
# @return [Integer] number of servings this recipe provides.
|
65
65
|
def number_of_servings
|
66
|
-
|
66
|
+
json["numberOfServings"]
|
67
67
|
end
|
68
68
|
|
69
69
|
# The nutritional composition of the recipe, in the form of a list of nutrients and their amounts, per serving. We
|
@@ -71,23 +71,23 @@ module Yummly
|
|
71
71
|
# are only estimates and you should be clear about that in what you tell your users.
|
72
72
|
# @return [Array] collection of Yummly::NutritionEstimate objects.
|
73
73
|
def nutrition_estimates
|
74
|
-
@nutrition_estimates ||=
|
74
|
+
@nutrition_estimates ||= json["nutritionEstimates"].collect { |ne| Yummly::NutritionEstimate.new(ne) }
|
75
75
|
end
|
76
76
|
|
77
77
|
def rating
|
78
|
-
|
78
|
+
json["rating"]
|
79
79
|
end
|
80
80
|
|
81
81
|
def recipe_name
|
82
|
-
|
82
|
+
json["recipeName"]
|
83
83
|
end
|
84
84
|
|
85
85
|
def total_time
|
86
|
-
|
86
|
+
json["totalTime"]
|
87
87
|
end
|
88
88
|
|
89
89
|
def total_time_in_seconds
|
90
|
-
|
90
|
+
json["totalTimeInSeconds"]
|
91
91
|
end
|
92
92
|
|
93
93
|
def thumbnail
|
@@ -98,11 +98,11 @@ module Yummly
|
|
98
98
|
|
99
99
|
private
|
100
100
|
|
101
|
-
# The search and find API calls populate different image attribute nodes in their respective
|
101
|
+
# The search and find API calls populate different image attribute nodes in their respective jsons. This method
|
102
102
|
# determines which one has been populated and returns a populated node for the images collection method to use. This
|
103
103
|
# allows the developer using this API to only use one method to access images.
|
104
104
|
def images_node
|
105
|
-
|
105
|
+
json["images"] || json["smallImageUrls"].collect { |url| {"hostedSmallUrl" => url} }
|
106
106
|
end
|
107
107
|
|
108
108
|
end
|
data/lib/yummly/search_result.rb
CHANGED
@@ -7,10 +7,10 @@ module Yummly
|
|
7
7
|
|
8
8
|
include Enumerable
|
9
9
|
|
10
|
-
attr_accessor :
|
10
|
+
attr_accessor :json, :params, :max_result, :start
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
@
|
12
|
+
def initialize(json)
|
13
|
+
@json = json
|
14
14
|
end
|
15
15
|
|
16
16
|
def each(&block)
|
@@ -22,20 +22,20 @@ module Yummly
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def matches
|
25
|
-
|
25
|
+
json["matches"] || []
|
26
26
|
end
|
27
27
|
|
28
28
|
def total_match_count
|
29
|
-
|
29
|
+
json["totalMatchCount"]
|
30
30
|
end
|
31
31
|
alias_method :total, :total_match_count
|
32
32
|
|
33
33
|
def attribution
|
34
|
-
Yummly::Attribution.new(
|
34
|
+
Yummly::Attribution.new(json["attribution"])
|
35
35
|
end
|
36
36
|
|
37
37
|
def criteria
|
38
|
-
|
38
|
+
json["criteria"]
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
data/lib/yummly/version.rb
CHANGED
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Yummly::Api do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Yummly.configure do |config|
|
7
|
+
config.app_id = "12345"
|
8
|
+
config.app_key = "XEARSGSTH12345789"
|
9
|
+
config.http_adapter = MockHttpAdapter
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { }
|
14
|
+
|
15
|
+
describe "#find" do
|
16
|
+
let(:result) { Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364') }
|
17
|
+
|
18
|
+
specify { result.should be_a(Yummly::Recipe) }
|
19
|
+
|
20
|
+
it "populates the recipe object with the json response" do
|
21
|
+
result.json.should == read_json_file('get_recipe.json')
|
22
|
+
end
|
23
|
+
|
24
|
+
context "no recipe found" do
|
25
|
+
let(:result) { Yummly::Api.find('missing-recipe-1234') }
|
26
|
+
specify { result.should be_nil }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def read_json_file(name)
|
33
|
+
path = File.expand_path("spec/fixtures/#{name}")
|
34
|
+
JSON.parse(File.open(path, 'rb').read)
|
35
|
+
end
|
data/yummly.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = "yummly"
|
8
8
|
gem.version = Yummly::VERSION
|
9
9
|
gem.authors = ["Theo Mills"]
|
10
|
+
gem.license = 'MIT'
|
10
11
|
gem.email = ["twmills@twmills.com"]
|
11
12
|
gem.description = %q{Ruby wrapper to the Yummly API}
|
12
13
|
gem.summary = "This is the unofficial ruby wrapper to the Yummly API, \"the world's largest and most powerful recipe search site\""
|
@@ -17,7 +18,8 @@ Gem::Specification.new do |gem|
|
|
17
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ["lib"]
|
19
20
|
gem.add_dependency('faraday', '>= 0.8.7')
|
20
|
-
gem.add_dependency('rack', "
|
21
|
+
gem.add_dependency('rack', ">= 1.4.5")
|
21
22
|
gem.add_dependency('json', "~> 1.8.0")
|
22
23
|
gem.add_development_dependency "rspec"
|
24
|
+
gem.add_development_dependency "rake"
|
23
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo Mills
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.4.5
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.4.5
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Ruby wrapper to the Yummly API
|
70
84
|
email:
|
71
85
|
- twmills@twmills.com
|
@@ -75,6 +89,7 @@ extra_rdoc_files: []
|
|
75
89
|
files:
|
76
90
|
- .gitignore
|
77
91
|
- .rspec
|
92
|
+
- .travis.yml
|
78
93
|
- Gemfile
|
79
94
|
- LICENSE.txt
|
80
95
|
- README.md
|
@@ -94,6 +109,7 @@ files:
|
|
94
109
|
- lib/yummly/unit.rb
|
95
110
|
- lib/yummly/url_builder.rb
|
96
111
|
- lib/yummly/version.rb
|
112
|
+
- spec/api_spec.rb
|
97
113
|
- spec/configuration_spec.rb
|
98
114
|
- spec/connection_spec.rb
|
99
115
|
- spec/fixtures/get_recipe.json
|
@@ -104,7 +120,8 @@ files:
|
|
104
120
|
- spec/yummly_spec.rb
|
105
121
|
- yummly.gemspec
|
106
122
|
homepage: https://github.com/twmills/yummly
|
107
|
-
licenses:
|
123
|
+
licenses:
|
124
|
+
- MIT
|
108
125
|
metadata: {}
|
109
126
|
post_install_message:
|
110
127
|
rdoc_options: []
|
@@ -122,12 +139,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
139
|
version: '0'
|
123
140
|
requirements: []
|
124
141
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.1.11
|
126
143
|
signing_key:
|
127
144
|
specification_version: 4
|
128
145
|
summary: This is the unofficial ruby wrapper to the Yummly API, "the world's largest
|
129
146
|
and most powerful recipe search site"
|
130
147
|
test_files:
|
148
|
+
- spec/api_spec.rb
|
131
149
|
- spec/configuration_spec.rb
|
132
150
|
- spec/connection_spec.rb
|
133
151
|
- spec/fixtures/get_recipe.json
|
@@ -136,4 +154,3 @@ test_files:
|
|
136
154
|
- spec/support/mock_http_adapter.rb
|
137
155
|
- spec/url_builder_spec.rb
|
138
156
|
- spec/yummly_spec.rb
|
139
|
-
has_rdoc:
|