Sha256: 98fb295363eb4600f69e6e78783323497085e687238b14e7c6468b9b25237a62
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
# This class handles the HTTP interactions with the Yummly API calls. module Yummly class Connection attr_accessor :connection def self.get(command, params = {}) response = self.api_connection.get(build_uri(command, params)) self.parse_response(response) end 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 def self.parse_response(response) case response.status when 409 then raise Yummly::PermissionError, response.body when 404 then nil when 200 then JSON.parse(response.body) end end def build_uri(command, params) query_string = build_params_query_string(params) "/#{self.api_version}/api/#{command}?#{query_string}" end def self.build_params_query_string(params) params['_app_id'] = Yummly.configuration.app_id params['_app_key'] = Yummly.configuration.app_key Rack::Utils.build_query(params) end def self.protocol Yummly.configuration.use_ssl? ? 'https' : 'http' end def self.api_version Yummly::API_VERSION end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yummly-0.0.4 | lib/yummly/connection.rb |