Class: Rack::BlockSlackbot
- Inherits:
-
Object
- Object
- Rack::BlockSlackbot
- Defined in:
- lib/rack/block_slackbot.rb
Constant Summary collapse
- SLACKBOT_UA_PATTERN =
Pattern to match Slack’s robots. Documentation here: api.slack.com/robots
/\ASlack(bot-LinkExpanding|-ImgProxy|bot) /.freeze
- DEFAULT_RESPONSE =
[ 403, { "Content-Type" => "text/plain" }.freeze, ["Bad Robot"].freeze ].freeze
- HTTP_USER_AGENT =
"HTTP_USER_AGENT".freeze
Instance Method Summary collapse
- #block?(env) ⇒ Boolean
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ BlockSlackbot
constructor
A new instance of BlockSlackbot.
Constructor Details
#initialize(app, options = {}) ⇒ BlockSlackbot
Returns a new instance of BlockSlackbot.
17 18 19 20 |
# File 'lib/rack/block_slackbot.rb', line 17 def initialize(app, = {}) @app = app @response = .fetch(:response, DEFAULT_RESPONSE) end |
Instance Method Details
#block?(env) ⇒ Boolean
30 31 32 |
# File 'lib/rack/block_slackbot.rb', line 30 def block?(env) env[HTTP_USER_AGENT] && env[HTTP_USER_AGENT] =~ SLACKBOT_UA_PATTERN end |
#call(env) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rack/block_slackbot.rb', line 22 def call(env) if block?(env) @response else @app.call(env) end end |