Class: Rack::TwilioValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/twilio-validator.rb,
lib/rack/twilio-validator/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of TwilioValidator.



5
6
7
8
9
10
# File 'lib/rack/twilio-validator.rb', line 5

def initialize(app, options = {})
  @app = app
  @options = options
  @auth_token = options.fetch(:auth_token)
  @app
end

Instance Method Details

#_call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rack/twilio-validator.rb', line 16

def _call(env)
  @request = Rack::Request.new(env)

  if unprotected_path? || validate(env['HTTP_X_TWILIO_SIGNATURE'])
    @app.call(env)
  else
    response = ::Twilio::TwiML::Response.new do |r|
      r.Say("Middleware unable to authenticate request signature")
    end
    [401, { "Content-Type" => "application/xml" }, [response.text]]
  end
end

#call(env) ⇒ Object



12
13
14
# File 'lib/rack/twilio-validator.rb', line 12

def call(env)
  self.dup._call(env)
end