Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monkeypatch faraday_middleware oauth to work with put requests
- Loading branch information
Adam Kittelson
committed
Jul 15, 2011
1 parent
ecc8326
commit 162a1c0
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'faraday' | ||
|
||
module Faraday | ||
class Request::OAuth < Faraday::Middleware | ||
dependency 'simple_oauth' | ||
|
||
def call(env) | ||
params = env[:body] || {} | ||
|
||
signature_params = params.reject{ |k,v| v.respond_to?(:content_type) || (env[:method] == :put) } | ||
|
||
header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options) | ||
|
||
env[:request_headers]['Authorization'] = header.to_s | ||
|
||
@app.call(env) | ||
end | ||
|
||
def initialize(app, options) | ||
@app, @options = app, options | ||
end | ||
end | ||
end |