lib/rising_dragon/sqs/emitter.rb in rising_dragon-0.1.0 vs lib/rising_dragon/sqs/emitter.rb in rising_dragon-0.1.1

- old
+ new

@@ -1,6 +1,6 @@ -require 'json' +require "json" module RisingDragon module SQS class Emitter def initialize @@ -33,25 +33,21 @@ @handlers.keys end def emit_event(event) handler = @handlers[event.type] - unless handler - raise "RisingDragon::SQS::Emitter handler is not registered. event_name: #{event.type}" - end + handler.new.handle(event) if handler - handler.new.handle(event) nil end - def event_from_json(json_text) - json = JSON.parse(json_text) - msg = json['Message'] + def event_from_json(body) + msg = JSON.parse(body["Message"]) - id = msg['id'] - type = msg['type'] - timestamp = Time.at(msg['timestamp'] / 1000.0) - data = msg['data'] + id = msg["id"] + type = msg["type"] + timestamp = Time.at(msg["timestamp"] / 1000.0) + data = msg["data"] ::RisingDragon::Event.new(id: id, type: type, timestamp: timestamp, data: data) end def emit_sns_msg(body)