Class: DeviceCloud::Monitor
- Inherits:
-
Object
- Object
- DeviceCloud::Monitor
- Defined in:
- lib/device_cloud/monitor.rb
Constant Summary collapse
- RESOURCE_PATH =
"/ws/Monitor"
Instance Attribute Summary collapse
-
#element ⇒ Object
Returns the value of attribute element.
-
#id ⇒ Object
Returns the value of attribute id.
-
#topic ⇒ Object
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #delete(client) ⇒ Object
-
#initialize(topic, element = nil) ⇒ Monitor
constructor
A new instance of Monitor.
- #resource_path ⇒ Object
- #save(client) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(topic, element = nil) ⇒ Monitor
Returns a new instance of Monitor.
19 20 21 22 |
# File 'lib/device_cloud/monitor.rb', line 19 def initialize(topic, element = nil) @topic = topic @element = element end |
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
7 8 9 |
# File 'lib/device_cloud/monitor.rb', line 7 def element @element end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/device_cloud/monitor.rb', line 7 def id @id end |
#topic ⇒ Object
Returns the value of attribute topic.
7 8 9 |
# File 'lib/device_cloud/monitor.rb', line 7 def topic @topic end |
Class Method Details
.all(client) ⇒ Object
9 10 11 12 |
# File 'lib/device_cloud/monitor.rb', line 9 def self.all(client) xml_result = Nokogiri::XML.parse client.get RESOURCE_PATH xml_result.xpath("//result/Monitor").map { |monitor| parse monitor } end |
.parse(xml) ⇒ Object
14 15 16 17 |
# File 'lib/device_cloud/monitor.rb', line 14 def self.parse(xml) topic = xml.xpath("monTopic").text DeviceCloud::Monitor.new(topic, xml) end |
Instance Method Details
#build ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/device_cloud/monitor.rb', line 44 def build builder = Nokogiri::XML::Builder.new do |xml| xml.Monitor { xml.monTopic @topic xml.monTransportType "http" xml.monTransportUrl "https://staging.cleanintel.com/ivx/sync" xml.monFormatType "json" xml.monBatchSize 100 xml.monCompression "none" xml.monBatchDuration 10 } end end |
#delete(client) ⇒ Object
35 36 37 38 |
# File 'lib/device_cloud/monitor.rb', line 35 def delete(client) raise NotImplementedError, "Incomplete" puts client.delete resource_path end |
#resource_path ⇒ Object
24 25 26 |
# File 'lib/device_cloud/monitor.rb', line 24 def resource_path RESOURCE_PATH end |
#save(client) ⇒ Object
29 30 31 32 33 |
# File 'lib/device_cloud/monitor.rb', line 29 def save(client) response = client.post resource_path, build.to_xml xml_res = Nokogiri::XML.parse response @id = xml_res.xpath("//result/location").text end |
#update ⇒ Object
40 41 42 |
# File 'lib/device_cloud/monitor.rb', line 40 def update end |