class ACIrb::MoEvent
Public Class Methods
new(_options = {})
click to toggle source
# File lib/acirb/events.rb, line 124 def initialize(_options = {}) end
parse_event(event_channel, event_str)
click to toggle source
# File lib/acirb/events.rb, line 127 def self.parse_event(event_channel, event_str) subscription = nil events = [] if event_channel.rest.format == 'xml' doc = Nokogiri::XML(event_str) subscription_id = doc.at_css('imdata')['subscriptionId'] puts event_str doc.root.elements.each do |xml_obj| event = { type: xml_obj.attributes['status'].to_s, properties: Hash[xml_obj.attributes.map { |k, str| [k, str.value.to_s] }], class: xml_obj.name, subscription_id: subscription_id } events.push(event) end elsif event_channel.rest.format == 'json' doc = JSON.parse(event_str, symbolize_names: false) subscription_id = doc['subscriptionId'] imdata = doc['imdata'] imdata.each do |obj| cls = obj.keys[0] event = { type: obj[cls]['attributes']['status'].to_s, properties: Hash[obj[cls]['attributes'].map { |k, str| [k, str.to_s] }], class: cls, subscription_id: subscription_id[0] } events.push(event) end end events end