Class: Yummly::Connection
- Inherits:
-
Object
- Object
- Yummly::Connection
- Defined in:
- lib/yummly/connection.rb
Overview
This class handles the HTTP interactions with the Yummly API calls.
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
- .api_connection ⇒ Object
- .api_version ⇒ Object
- .get(command, params = {}) ⇒ Object
- .protocol ⇒ Object
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
4 5 6 |
# File 'lib/yummly/connection.rb', line 4 def connection @connection end |
Class Method Details
.api_connection ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/yummly/connection.rb', line 13 def self.api_connection Faraday.new(:url => "#{self.protocol}://api.yummly.com") do |faraday| faraday.request :url_encoded # form-encode POST params faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end |
.api_version ⇒ Object
25 26 27 |
# File 'lib/yummly/connection.rb', line 25 def self.api_version Yummly::API_VERSION end |
.get(command, params = {}) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/yummly/connection.rb', line 6 def self.get(command, params = {}) params['_app_id'] = Yummly.configuration.app_id params['_app_key'] = Yummly.configuration.app_key response = self.api_connection.get("/#{self.api_version}/api/#{command}?#{Rack::Utils.build_query(params)}") JSON.parse(response.body) end |
.protocol ⇒ Object
21 22 23 |
# File 'lib/yummly/connection.rb', line 21 def self.protocol Yummly.configuration.use_ssl? ? 'https' : 'http' end |