Module: Xively::Parsers::XML::TriggerDefaults

Included in:
Trigger
Defined in:
lib/xively-rb/parsers/xml/trigger_defaults.rb

Instance Method Summary collapse

Instance Method Details

#from_xml(xml) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/xively-rb/parsers/xml/trigger_defaults.rb', line 5

def from_xml(xml)
  begin
    xml = Nokogiri::XML(xml) do |config|
      config.strict.nonet
    end
    hash = {}
    hash["id"] = xml.at_xpath("//id").content if xml.at_xpath("//id")
    hash["url"] = xml.at_xpath("//url").content if xml.at_xpath("//url")
    hash["trigger_type"] = xml.at_xpath("//trigger-type").content if xml.at_xpath("//trigger-type")
    hash["threshold_value"] = xml.at_xpath("//threshold-value").content if xml.at_xpath("//threshold-value")
    hash["notified_at"] = xml.at_xpath("//notified-at").content if xml.at_xpath("//notified-at")
    hash["user"] = xml.at_xpath("//user").content if xml.at_xpath("//user")
    hash["environment_id"] = xml.at_xpath("//environment-id").content if xml.at_xpath("//environment-id")
    hash["stream_id"] = xml.at_xpath("//stream-id").content if xml.at_xpath("//stream-id")
    hash
  rescue Nokogiri::SyntaxError => e
    raise InvalidXMLError, e.message
  end
end