Sha256: 78c66bcdcc20ebc612364d99f6d7c2ddbd5fc9d2a6c30112a0c53cedf7c93599

Contents?: true

Size: 896 Bytes

Versions: 3

Compression:

Stored size: 896 Bytes

Contents

# This class handles the HTTP interactions with the Yummly API calls.
class Yummly::Connection

  attr_accessor :connection

  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

  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.protocol
    Yummly.configuration.use_ssl? ? 'https' : 'http'
  end

  def self.api_version
    Yummly::API_VERSION
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yummly-0.0.3 lib/yummly/connection.rb
yummly-0.0.2 lib/yummly/connection.rb
yummly-0.0.1 lib/yummly/connection.rb