Home

Awesome

Faraday OAuth1

CI Gem License

Faraday OAuth1 Middleware.

Installation

Add this line to your application's Gemfile:

gem 'faraday-oauth1'

Note: There's an existing gem https://rubygems.org/gems/faraday-oauth which looks similar but, at this time, but does not have its source available and is not available for collaboration, though the gem is licensed as MIT and can be inspected. This library was written without reference to the faraday-oauth gem.

And then execute:

bundle install

Or install it yourself as:

gem install faraday-oauth1

Usage

require 'faraday'
require 'faraday/oauth1'

base_uri = "https://example.com"
path = "/webservices/has-oauth1"
headers = {}
headers["Content-Type"] ||= "application/x-www-form-urlencoded"
# see https://github.com/laserlemon/simple_oauth for credentials options
credentials = {
  consumer_key: consumer_key,
  consumer_secret: consumer_secret,
  access_token: nil,
  access_token_secret: nil
}.compact
auth_type = "param"
conn = Faraday.new(url: base_uri) do |builder|
  builder.request :oauth1, auth_type, **credentials
  builder.use Faraday::Response::RaiseError
  builder.adapter Faraday.default_adapter
  builder.headers.update(headers) if headers
end
response = conn.get(path)

Development

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.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the terms of the MIT License.