Class: Hahamut::Handler
- Inherits:
-
Object
- Object
- Hahamut::Handler
- Defined in:
- lib/hahamut/handler.rb
Overview
Handling HTTP Request
Constant Summary collapse
- SIGNATURE_HEADER =
'HTTP_X_BAHA_DATA_SIGNATURE'
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #body ⇒ Object
- #client ⇒ Object
-
#initialize(env) ⇒ Handler
constructor
A new instance of Handler.
- #process ⇒ Object
- #raw ⇒ Object
Constructor Details
#initialize(env) ⇒ Handler
Returns a new instance of Handler.
13 14 15 |
# File 'lib/hahamut/handler.rb', line 13 def initialize(env) @request = Rack::Request.new(env) end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
11 12 13 |
# File 'lib/hahamut/handler.rb', line 11 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
11 12 13 |
# File 'lib/hahamut/handler.rb', line 11 def response @response end |
Instance Method Details
#body ⇒ Object
26 27 28 |
# File 'lib/hahamut/handler.rb', line 26 def body @body ||= JSON.parse(raw) end |
#client ⇒ Object
30 31 32 |
# File 'lib/hahamut/handler.rb', line 30 def client Manager.find(body['botid']) end |
#process ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/hahamut/handler.rb', line 17 def process return invalid_client if client.nil? return invalid_signature unless valid_signature? Manager.handle(client, Event.new(body)) Rack::Response.new([], 204) end |
#raw ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/hahamut/handler.rb', line 34 def raw return @raw unless @raw.nil? @raw = @request.body.read @request.body.rewind @raw end |