Class: Rack::Verify::Line::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/verify/line/bot.rb,
lib/rack/verify/line/bot/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Bot.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/verify/line/bot.rb', line 9

def initialize(app, options = {})
  @app = app
  @options = options

  @secret = @options[:secret]
  unless @secret
    raise 'missing secret parameter for ' + self.class.name
  end

  @buffer_size = @options[:buffer_size] || 65536
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rack/verify/line/bot.rb', line 21

def call(env)
  if need_verification?(env)
    unless verify_signature(env)
      return [
        400,
        {
          'Content-Type'   => 'text/plain',
          'Content-Length' => '11',
        },
        [ 'Bad Request' ]
      ]
    end
  end

  @app.call(env)
end