Class: VerifyNexmoSignature::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/verify_nexmo_signature/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



4
5
6
# File 'lib/verify_nexmo_signature/middleware.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/verify_nexmo_signature/middleware.rb', line 8

def call(env)
  req = ::Rack::Request.new(env)
  if req.post?
    params = req.params.dup 
    verify = nexmo_client
    if verify.check(params)
      @app.call(env)
    else
      [403, {}, ['']]
    end
  else
    @app.call(env)
  end
end