ryanlecompte / letsfreckle-client

Ruby client for the Let's Freckle API (http://www.letsfreckle.com)
MIT License
16 stars 10 forks source link

Reorganize middleware for Faraday v0.8 paradigm #13

Closed tekwiz closed 10 years ago

tekwiz commented 10 years ago

From the FaradayMiddleware readme

Old Way (Faraday <= v0.7):

connection = Faraday.new 'http://example.com/api' do |builder|
  builder.use FaradayMiddleware::OAuth2, 'TOKEN'
  builder.use FaradayMiddleware::EncodeJson

  builder.use FaradayMiddleware::ParseXml,  :content_type => /\bxml$/
  builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/

  builder.use FaradayMiddleware::Instrumentation
  builder.adapter Faraday.default_adapter
end

New Way (Faraday >= v0.8):

connection = Faraday.new 'http://example.com/api' do |conn|
  conn.request :oauth2, 'TOKEN'
  conn.request :json

  conn.response :xml,  :content_type => /\bxml$/
  conn.response :json, :content_type => /\bjson$/

  conn.use :instrumentation
  conn.adapter Faraday.default_adapter
end