Permalink
Browse files

monkeypatch faraday_middleware oauth to work with put requests

  • Loading branch information...
adamkittelson committed Jul 15, 2011
1 parent ecc8326 commit 162a1c065d34cc8c6d43a96b98c928826dedad58
Showing with 23 additions and 0 deletions.
  1. +23 −0 lib/faraday/request/oauth.rb
@@ -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

0 comments on commit 162a1c0

Please sign in to comment.