Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Various Faraday middlewares for my Faraday-based API wrappers

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gemtest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE.md
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 faraday_middleware.gemspec
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::ParseJson
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::ParseJson
  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"
Something went wrong with that request. Please try again.