Class: Pechkin::RequestHandler
- Inherits:
-
Object
- Object
- Pechkin::RequestHandler
- Defined in:
- lib/pechkin/app/request_handler.rb
Overview
Http requests handler. We need fresh instance per each request. To keep internal state isolated
Constant Summary collapse
- REQ_PATH_PATTERN =
%r{^/(.+)/([^/]+)/?$}
Instance Attribute Summary collapse
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#req ⇒ Object
readonly
Returns the value of attribute req.
Instance Method Summary collapse
- #handle ⇒ Object
-
#initialize(handler, req, logger) ⇒ RequestHandler
constructor
A new instance of RequestHandler.
Constructor Details
#initialize(handler, req, logger) ⇒ RequestHandler
Returns a new instance of RequestHandler.
11 12 13 14 15 16 17 18 19 |
# File 'lib/pechkin/app/request_handler.rb', line 11 def initialize(handler, req, logger) @handler = handler @req = req @logger = logger @channel_id, @message_id = req.path_info.match(REQ_PATH_PATTERN) do |m| [m[1], m[2]] end end |
Instance Attribute Details
#channel_id ⇒ Object (readonly)
Returns the value of attribute channel_id.
7 8 9 |
# File 'lib/pechkin/app/request_handler.rb', line 7 def channel_id @channel_id end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
7 8 9 |
# File 'lib/pechkin/app/request_handler.rb', line 7 def handler @handler end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/pechkin/app/request_handler.rb', line 7 def logger @logger end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
7 8 9 |
# File 'lib/pechkin/app/request_handler.rb', line 7 def @message_id end |
#req ⇒ Object (readonly)
Returns the value of attribute req.
7 8 9 |
# File 'lib/pechkin/app/request_handler.rb', line 7 def req @req end |
Instance Method Details
#handle ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pechkin/app/request_handler.rb', line 21 def handle raise AppError.http_method_not_allowed unless post? raise AppError. unless data = parse_data(req.body.read) # handler.handle() requires keyword arguments handler.handle(channel_id, , **data).each do |i| logger.info "Sent #{channel_id}/#{}: #{i.to_json}" end end |