Sha256: 7419babe629709639d1fb0ef08d98f977817e5d177174c5f7337bb7537fc49ac
Contents?: true
Size: 1.4 KB
Versions: 3
Compression:
Stored size: 1.4 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(self.url).get(self.uri(command, params)) self.parse_response(response) end def self.api_connection(url) Faraday.new(:url => url) 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 self.url "#{self.protocol}://api.yummly.com" end def self.uri(command, params) query_string = self.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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
yummly-0.0.9 | lib/yummly/connection.rb |
yummly-0.0.8 | lib/yummly/connection.rb |
yummly-0.0.7 | lib/yummly/connection.rb |