Class: Igniter::Store::HTTPAdapter::DispatchHandler
- Inherits:
-
Object
- Object
- Igniter::Store::HTTPAdapter::DispatchHandler
- Includes:
- ResponseHelper
- Defined in:
- lib/igniter/store/http_adapter.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(interpreter) ⇒ DispatchHandler
constructor
A new instance of DispatchHandler.
Constructor Details
#initialize(interpreter) ⇒ DispatchHandler
Returns a new instance of DispatchHandler.
36 37 38 |
# File 'lib/igniter/store/http_adapter.rb', line 36 def initialize(interpreter) @interpreter = interpreter end |
Instance Method Details
#call(env) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/igniter/store/http_adapter.rb', line 40 def call(env) return method_not_allowed unless env["REQUEST_METHOD"] == "POST" body = env["rack.input"].read begin envelope = JSON.parse(body, symbolize_names: true) rescue JSON::ParserError => e return json_response(400, { error: "Invalid JSON: #{e.}" }) end json_response(200, @interpreter.wire.dispatch(envelope)) end |