recipe_puppy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +58 -0
- data/Rakefile +21 -0
- data/lib/recipe_puppy.rb +46 -0
- data/lib/recipe_puppy/recipe_data.rb +18 -0
- metadata +72 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Phil McClure
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
= Recipe Puppy
|
2
|
+
|
3
|
+
This is a ruby wrapper for the recipepuppy.com API. Search for recipes by recipe name and/or by ingredients.
|
4
|
+
|
5
|
+
{API Details}[http://www.recipepuppy.com/about/api/]
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
gem install recipe_puppy
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'recipe_puppy'
|
15
|
+
|
16
|
+
# Simple Search
|
17
|
+
steakrecipes = RecipePuppy::Recipe.search_for("steak")
|
18
|
+
steakrecipes.get['results'].each do |recipe|
|
19
|
+
puts recipe['title']
|
20
|
+
puts recipe['href']
|
21
|
+
puts recipe['ingredients']
|
22
|
+
puts recipe['thumbnail']
|
23
|
+
end
|
24
|
+
|
25
|
+
# Chaining Search with_ingredients
|
26
|
+
steakrecipes = RecipePuppy::Recipe.search_for("steak").with_ingredients("onions, mushrooms")
|
27
|
+
steakrecipes.get['results'].each do |recipe|
|
28
|
+
puts recipe['title']
|
29
|
+
puts recipe['href']
|
30
|
+
puts recipe['ingredients']
|
31
|
+
puts recipe['thumbnail']
|
32
|
+
end
|
33
|
+
|
34
|
+
# All methods can be chained as follows
|
35
|
+
RecipePuppy::Recipe.search_for("steak").with_ingredients("onions, mushrooms").get['results'].each do |recipe|
|
36
|
+
puts recipe['title']
|
37
|
+
puts recipe['href']
|
38
|
+
puts recipe['ingredients']
|
39
|
+
puts recipe['thumbnail']
|
40
|
+
end
|
41
|
+
|
42
|
+
== Dependencies
|
43
|
+
|
44
|
+
JSON
|
45
|
+
|
46
|
+
== Note on Patches/Pull Requests
|
47
|
+
|
48
|
+
* Fork the project.
|
49
|
+
* Make your feature addition or bug fix.
|
50
|
+
* Add tests for it. This is important so I don't break it in a
|
51
|
+
future version unintentionally.
|
52
|
+
* Commit, do not mess with rakefile, version, or history.
|
53
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
54
|
+
* Send me a pull request. Bonus points for topic branches.
|
55
|
+
|
56
|
+
== Copyright
|
57
|
+
|
58
|
+
Copyright (c) 2010 Phil McClure. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "recipe_puppy"
|
8
|
+
gem.summary = %Q{Ruby wrapper for the recipepuppy.com API}
|
9
|
+
gem.description = %Q{Search for recipes by name or by the ingredients it contains}
|
10
|
+
gem.email = "phil.mcclure@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/overture8/recipe_puppy"
|
12
|
+
gem.authors = ["Phil McClure"]
|
13
|
+
gem.files = Dir["lib/**/*"] + ["LICENSE", "README.rdoc", "Rakefile", "CHANGELOG.rdoc"]
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
|
data/lib/recipe_puppy.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'json'
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/recipe_puppy/recipe_data')
|
5
|
+
|
6
|
+
module RecipePuppy
|
7
|
+
class Recipe
|
8
|
+
attr_accessor :recipe_data
|
9
|
+
|
10
|
+
def self.search_for(search_text = nil)
|
11
|
+
unless search_text.nil?
|
12
|
+
recipe = self.new
|
13
|
+
recipe.recipe_data = RecipeData.new
|
14
|
+
recipe.recipe_data.search_term = search_text
|
15
|
+
recipe
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.with_ingredients(ingredients = nil)
|
20
|
+
unless ingredients.nil?
|
21
|
+
recipe = self.new
|
22
|
+
recipe.recipe_data = RecipeData.new
|
23
|
+
recipe.recipe_data.ingredients = ingredients
|
24
|
+
recipe
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# This instance method is used for chaining to the search_for method.
|
29
|
+
def with_ingredients(ingredients = nil)
|
30
|
+
unless ingredients.nil?
|
31
|
+
self.recipe_data.ingredients = ingredients
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Gets the data
|
37
|
+
def get
|
38
|
+
self.recipe_data.results
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the API call url
|
42
|
+
def url
|
43
|
+
self.recipe_data.url
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RecipePuppy
|
2
|
+
class RecipeData
|
3
|
+
attr_accessor :ingredients, :search_term
|
4
|
+
attr_reader :url
|
5
|
+
|
6
|
+
def results
|
7
|
+
if @ingredients && @search_term
|
8
|
+
@url = "http://www.recipepuppy.com/api/?i=#{CGI.escape(@ingredients)}&q=#{CGI.escape(@search_term)}"
|
9
|
+
elsif @ingredients && @search_term.nil?
|
10
|
+
@url = "http://www.recipepuppy.com/api/?i=#{CGI.escape(@ingredients)}"
|
11
|
+
elsif @ingredients.nil? && @search_term
|
12
|
+
@url = "http://www.recipepuppy.com/api/?q=#{CGI.escape(@search_term)}"
|
13
|
+
end
|
14
|
+
|
15
|
+
JSON.parse(open(@url).string)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: recipe_puppy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Phil McClure
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-20 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Search for recipes by name or by the ingredients it contains
|
23
|
+
email: phil.mcclure@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.rdoc
|
31
|
+
files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- lib/recipe_puppy.rb
|
36
|
+
- lib/recipe_puppy/recipe_data.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/overture8/recipe_puppy
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.7
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Ruby wrapper for the recipepuppy.com API
|
71
|
+
test_files: []
|
72
|
+
|