Add ability to send custom headers on each http request by an ActiveResource model.
There are two ways of setting headers.
- class method
custom_headers do ... end
in a model, that is an ActiveResource::Base kind - chainable method
with_headers
, that can be putten between model class andfind
method
class Person < ActiveResource::Base
include ActiveresourceHeaders::CustomHeaders
self.site = 'http://example.com'
custom_headers do
{"My-Time" => Time.now.to_s}
end
end
Person.find(:all) #=> will add header "My-Time: 2012-10-02 18:56:18 +0300"
Person.with_headers("My-Time" => "to drink!", "Age" => "25+").find(:all)
#=> will add headers "My-Time: to drink!" and "Age: 25+"
Add this line to your application's Gemfile:
gem 'activeresource_headers'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activeresource_headers
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request