Class: Rack::TwilioValidator
- Inherits:
-
Object
- Object
- Rack::TwilioValidator
- Defined in:
- lib/rack/twilio-validator.rb,
lib/rack/twilio-validator/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ TwilioValidator
constructor
A new instance of TwilioValidator.
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, = {}) @app = app @options = @auth_token = .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 |