Module: Punchfork::Base
- Included in:
- Punchfork
- Defined in:
- lib/punchfork/base.rb
Instance Method Summary collapse
-
#search(*args) ⇒ Object
Returns a Punchfork::Search object.
-
#search_url(*args) ⇒ Object
used by #search to query punchfork.com.
Instance Method Details
#search(*args) ⇒ Object
Returns a Punchfork::Search object. Accepts any number of arguments that will be used as ingredients in your search as well as an options hash. Example: Punchfork.search(:tomatoes, :garlic, protocol:‘https’)
6 7 8 |
# File 'lib/punchfork/base.rb', line 6 def search(*args) Punchfork::Search.new(JSON.load(Net::HTTP.get_response(search_url(*args)).body)) end |
#search_url(*args) ⇒ Object
used by #search to query punchfork.com. Returns a URI object.
11 12 13 14 15 16 17 18 19 |
# File 'lib/punchfork/base.rb', line 11 def search_url(*args) = args..stringify_keys! protocol = (['protocol'] || self.protocol).to_s uri = search_uri uri.scheme = protocol uri.query = ["key=#{api_key}", "q=#{URI.escape(args.join(','))}", *.map{ |k,v| "#{k}=#{v}" }].join('&') return uri end |