Class: Rafaday::BodySigningMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rafaday/body_signing_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ BodySigningMiddleware

Returns a new instance of BodySigningMiddleware.



7
8
9
10
11
# File 'lib/rafaday/body_signing_middleware.rb', line 7

def initialize(app, options={})
  @app = app
  @secret = options.fetch(:secret) { '' }
  @digest = options.fetch(:digest) { 'sha1' }
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/rafaday/body_signing_middleware.rb', line 13

def call(env)
  if env[:body]
    digest = OpenSSL::HMAC.new @secret, @digest
    digest << env[:body].to_s
    url = env[:url]
    query = url.query_values || {}
    url.query_values = query.merge :sig => digest.to_s
  end
  @app.call env
end