Faraday middleware for wrapping responses into Hashie::Mash.
This very specific middleware has been extracted from the faraday_middleware project.
This is fully compatible with FaradayMiddleware::Mashify
Add this line to your application's Gemfile:
gem 'faraday-mashify'
And then execute:
bundle install
Or install it yourself as:
gem install faraday-mashify
curl http://www.example.com/api/me
{"name":"sue445"}
require 'faraday/mashify'
connection =
Faraday.new(url: 'http://www.example.com') do |conn|
conn.response :mashify
conn.response :json
end
response = connection.get('/api/me').body
response[:name]
#=> "sue445"
response['name']
#=> "sue445"
response.name
#=> "sue445"
If you want to customize the response class, pass mash_class
to conn.response :mashify
. (default is Hashie::Mash
)
e.g.
class MyHash < Hashie::Mash
end
connection =
Faraday.new(url: 'http://www.example.com') do |conn|
conn.response :mashify, mash_class: MyHash
conn.response :json
end
response = connection.get('/api/me').body
response.class
#=> MyHash
Please do the following
gem "faraday_middleware"
->gem "faraday-mashify"
inGemfile
require "faraday_middleware"
->require "faraday/mashify"
After checking out the repo, run bin/setup
to install dependencies.
Then, run bin/test
to run the tests.
To install this gem onto your local machine, run rake build
.
To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run rake release
.
See how it works here.
Bug reports and pull requests are welcome on GitHub.
The gem is available as open source under the terms of the MIT License.