Class: DeviceCloud::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/device_cloud/monitor.rb

Constant Summary collapse

RESOURCE_PATH =
"/ws/Monitor"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#elementObject

Returns the value of attribute element.



7
8
9
# File 'lib/device_cloud/monitor.rb', line 7

def element
  @element
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/device_cloud/monitor.rb', line 7

def id
  @id
end

#topicObject

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

#buildObject



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

Raises:

  • (NotImplementedError)


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_pathObject



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

#updateObject



40
41
42
# File 'lib/device_cloud/monitor.rb', line 40

def update

end