Various Faraday middlewares for my Faraday-based API wrappers
Ruby
Pull request Compare This branch is 3 commits ahead, 355 commits behind lostisland:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib elegantly handle empty bodies Aug 14, 2010
test
.gitignore
Gemfile
README.md
Rakefile
faraday_middleware.gemspec mashify, multi_json Jun 28, 2010

README.md

Faraday Middleware

Collection of Faraday middlewares I've been using in some of my API wrappers

Installation

sudo gem install faraday-middleware

Some examples

Let's decode the response body with MultiJson

conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
  builder.adapter Faraday.default_adapter
  builder.use Faraday::Response::MultiJson
end

resp = conn.get do |req|
  req.url '/users/show.json', :screen_name => 'pengwynn'
end

u = resp.body
u['name']
# => "Wynn Netherland"

Want to ditch the brackets and use dot notation? Mashify it!

conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
  builder.adapter Faraday.default_adapter
  builder.use Faraday::Response::MultiJson
  builder.use Faraday::Response::Mashify
end

resp = conn.get do |req|
  req.url '/users/show.json', :screen_name => 'pengwynn'
end

u = resp.body
u.name
# => "Wynn Netherland"