epilicious 0.2.0 → 0.3.3
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/Rakefile +10 -0
- data/epilicious.gemspec +2 -0
- data/lib/epilicious/cookbook.rb +50 -0
- data/lib/epilicious/recipe.rb +7 -0
- data/lib/epilicious/version.rb +1 -2
- data/lib/epilicious.rb +5 -4
- data/test/cookbook_test.rb +34 -0
- data/test/recipe_test.rb +17 -0
- metadata +35 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dcc4875efef2e7e510646b48699d003e58ac635
|
4
|
+
data.tar.gz: f0033a03a7d99bb1803b2a34cdcb3c8c6bfc7447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd130556b1a1791ea1c3a3c735e93d5ecaa478192fb089f1623872726bbaf345ab13361d95be89c7de94440cf28d4e85e3f812126d3fe8a615a49220beb3c3c2
|
7
|
+
data.tar.gz: 8ddb85e92fc9baba81a152b90e61ee0d10049e0f2099c8083b505bc993ef6586d428381e579cbf96eeddba96ad4ce85e2161c03e2950ef306669ae04f0ccc0b3
|
data/Rakefile
CHANGED
@@ -6,3 +6,13 @@ Rake::TestTask.new(:default) do |t|
|
|
6
6
|
t.libs << "test"
|
7
7
|
t.test_files = FileList["test/**/*_test.rb"]
|
8
8
|
end
|
9
|
+
|
10
|
+
Rake::TestTask.new(:cookbook) do |t|
|
11
|
+
t.libs << "test"
|
12
|
+
t.test_files = FileList["test/**/cookbook_test.rb"]
|
13
|
+
end
|
14
|
+
|
15
|
+
Rake::TestTask.new(:recipe) do |t|
|
16
|
+
t.libs << "test"
|
17
|
+
t.test_files = FileList["test/**/recipe_test.rb"]
|
18
|
+
end
|
data/epilicious.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "nokogiri"
|
22
|
+
spec.add_dependency "redis"
|
23
|
+
spec.add_dependency "json"
|
22
24
|
|
23
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
26
|
spec.add_development_dependency "mocha"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require_relative './recipe'
|
5
|
+
|
6
|
+
module Epilicious
|
7
|
+
class CookBook
|
8
|
+
|
9
|
+
def self.redis
|
10
|
+
Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
|
11
|
+
rescue
|
12
|
+
Redis.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.recipes(url)
|
16
|
+
unless recipe_vault = redis.get(url)
|
17
|
+
fetched_recipes = fetcher(url)
|
18
|
+
self.recipes = {url => fetched_recipes }
|
19
|
+
return fetched_recipes
|
20
|
+
end
|
21
|
+
|
22
|
+
JSON.parse(recipe_vault).map do |recipe|
|
23
|
+
recipe.keys.each do |key|
|
24
|
+
recipe[(key.to_sym rescue key) || key] = recipe.delete(key)
|
25
|
+
end
|
26
|
+
Recipe.new(recipe)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.recipes=(cookbook)
|
31
|
+
url = cookbook.keys.first
|
32
|
+
cookbook = cookbook[url].to_json
|
33
|
+
redis.set(url, cookbook)
|
34
|
+
redis.expire(url, day)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.fetcher(url)
|
38
|
+
Fetcher.new.fetch_recipes(url)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.day
|
42
|
+
24 * 60 * 60
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.uri
|
46
|
+
URI.parse(ENV["REDISCLOUD_URL"])
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/epilicious/recipe.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Epilicious
|
2
4
|
|
3
5
|
class Recipe
|
@@ -9,5 +11,10 @@ module Epilicious
|
|
9
11
|
@ingredients = args[:ingredients]
|
10
12
|
@instructions = args[:instructions]
|
11
13
|
end
|
14
|
+
|
15
|
+
def to_json(*args)
|
16
|
+
{ name: name, servings: servings, ingredients: ingredients, instructions: instructions }.to_json(*args)
|
17
|
+
end
|
18
|
+
|
12
19
|
end
|
13
20
|
end
|
data/lib/epilicious/version.rb
CHANGED
data/lib/epilicious.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require "epilicious/version"
|
2
2
|
require "epilicious/fetcher"
|
3
|
+
require "epilicious/cookbook"
|
3
4
|
|
4
5
|
module Epilicious
|
5
6
|
def self.recipes(url = recipes_url)
|
6
|
-
|
7
|
+
CookBook.recipes(url)
|
7
8
|
end
|
8
|
-
end
|
9
9
|
|
10
|
-
def recipes_url
|
11
|
-
|
10
|
+
def self.recipes_url
|
11
|
+
"http://www.epicurious.com/recipesmenus/whatsnew/recipes"
|
12
|
+
end
|
12
13
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Epilicious::CookBook do
|
4
|
+
let(:cookbook) { Epilicious::CookBook }
|
5
|
+
let(:recipes) { cookbook.recipes("test") }
|
6
|
+
|
7
|
+
context "#recipes" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
cookbook.recipes = { "test" => [Epilicious::Recipe.new({})] }
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
cookbook.redis.flushdb
|
15
|
+
end
|
16
|
+
|
17
|
+
it "must return a list of recipe objects" do
|
18
|
+
recipes.must_be_instance_of Array
|
19
|
+
recipes.first.must_be_instance_of Epilicious::Recipe
|
20
|
+
cookbook.redis.ttl("test").must_be :<=, day
|
21
|
+
cookbook.redis.ttl("test").must_be :>=, day - 10
|
22
|
+
end
|
23
|
+
|
24
|
+
it "must fetch a list recipes when url does not exits" do
|
25
|
+
cookbook.expects(:fetcher).with("bla").returns([Epilicious::Recipe.new({})])
|
26
|
+
cookbook.recipes("bla").must_be_instance_of Array
|
27
|
+
cookbook.recipes("bla").first.must_be_instance_of Epilicious::Recipe
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def day
|
32
|
+
24 * 60 * 60
|
33
|
+
end
|
34
|
+
end
|
data/test/recipe_test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'pry'
|
3
|
+
describe Epilicious::Recipe do
|
4
|
+
let(:recipe) { Epilicious::Recipe.new({name: "test", servings: "4", ingredients: ["many"], instructions: ["more"]}) }
|
5
|
+
it "should have the right attributes" do
|
6
|
+
recipe.name.must_equal "test"
|
7
|
+
recipe.servings.must_equal "4"
|
8
|
+
recipe.ingredients.must_be_instance_of Array
|
9
|
+
recipe.instructions.must_be_instance_of Array
|
10
|
+
end
|
11
|
+
|
12
|
+
context "#to_json" do
|
13
|
+
it "should return a string" do
|
14
|
+
recipe.to_json.must_be_instance_of String
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epilicious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Hein Hoogstad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,14 +136,17 @@ files:
|
|
108
136
|
- Rakefile
|
109
137
|
- epilicious.gemspec
|
110
138
|
- lib/epilicious.rb
|
139
|
+
- lib/epilicious/cookbook.rb
|
111
140
|
- lib/epilicious/fetcher.rb
|
112
141
|
- lib/epilicious/parser.rb
|
113
142
|
- lib/epilicious/recipe.rb
|
114
143
|
- lib/epilicious/version.rb
|
144
|
+
- test/cookbook_test.rb
|
115
145
|
- test/epilicious_test.rb
|
116
146
|
- test/fetcher_test.rb
|
117
147
|
- test/fixtures/recipes_page.html
|
118
148
|
- test/parser_test.rb
|
149
|
+
- test/recipe_test.rb
|
119
150
|
- test/test_helper.rb
|
120
151
|
homepage: ''
|
121
152
|
licenses:
|
@@ -142,8 +173,10 @@ signing_key:
|
|
142
173
|
specification_version: 4
|
143
174
|
summary: a gem to parse recipes from epicurious
|
144
175
|
test_files:
|
176
|
+
- test/cookbook_test.rb
|
145
177
|
- test/epilicious_test.rb
|
146
178
|
- test/fetcher_test.rb
|
147
179
|
- test/fixtures/recipes_page.html
|
148
180
|
- test/parser_test.rb
|
181
|
+
- test/recipe_test.rb
|
149
182
|
- test/test_helper.rb
|