Class: Request::Hmac
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Request::Hmac
- Defined in:
- lib/faraday/request/hmac.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, secret, options = {}) ⇒ Hmac
constructor
create a new Hmac middleware instance.
- #sign(env) ⇒ Object
Constructor Details
#initialize(app, secret, options = {}) ⇒ Hmac
create a new Hmac middleware instance
27 28 29 |
# File 'lib/faraday/request/hmac.rb', line 27 def initialize(app, secret, = {}) @app, @secret, @options, @query_values = app, secret, end |
Instance Method Details
#call(env) ⇒ Object
31 32 33 34 |
# File 'lib/faraday/request/hmac.rb', line 31 def call(env) sign(env) @app.call(env) end |
#sign(env) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/faraday/request/hmac.rb', line 36 def sign(env) signer = HMAC::Signer.new url = env[:url] method = env[:method] headers, url = *signer.sign_request(url, @secret, @options.merge(:method => env[:method])) env[:request_headers] = (env[:request_headers] || {}).merge(headers) env[:url] = URI.parse(url) env end |