class DeviceCloud::Monitor
Constants
- DEFAULT_CREATE_OPTIONS
Attributes
cstId[RW]
error[R]
monAutoReplayOnConnect[RW]
monBatchDuration[RW]
monBatchSize[RW]
monCompression[RW]
monFormatType[RW]
monId[RW]
monLastConnect[RW]
monLastSent[RW]
monLastSentUuid[RW]
monStatus[RW]
monTopic[RW]
monTransportToken[RW]
monTransportType[RW]
monTransportUrl[RW]
Public Class Methods
all()
click to toggle source
# File lib/device_cloud/monitor.rb, line 18 def all monitors = DeviceCloud::Request.new(path: '/ws/Monitor/.json').get.to_hash_from_json return [] unless monitors['resultSize'].to_i > 0 monitors['items'].map { |monitor| Monitor.new monitor } end
find(monitor_id)
click to toggle source
# File lib/device_cloud/monitor.rb, line 28 def find(monitor_id) monitors = DeviceCloud::Request.new(path: "/ws/Monitor/#{monitor_id}.json").get.to_hash_from_json return nil unless monitors['resultSize'].to_i > 0 Monitor.new monitors['items'].first end
new(attributes = {})
click to toggle source
# File lib/device_cloud/monitor.rb, line 37 def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end @error = nil set_defaults end
Public Instance Methods
attributes()
click to toggle source
# File lib/device_cloud/monitor.rb, line 70 def attributes { 'monTopic' => monTopic, 'monTransportType' => monTransportType, 'monTransportToken' => monTransportToken, 'monTransportUrl' => monTransportUrl, 'monFormatType' => monFormatType, 'monBatchSize' => monBatchSize, 'monCompression' => monCompression, 'monBatchDuration' => monBatchDuration, 'monAutoReplayOnConnect' => monAutoReplayOnConnect } end
destroy!()
click to toggle source
# File lib/device_cloud/monitor.rb, line 62 def destroy! return false if monId.nil? response = DeviceCloud::Request.new(path: "/ws/Monitor/#{monId}").delete response.code == '200' ? true : false end
persist!()
click to toggle source
# File lib/device_cloud/monitor.rb, line 47 def persist! @error = nil monId.nil? ? create : update end
reset!()
click to toggle source
# File lib/device_cloud/monitor.rb, line 52 def reset! @error = nil if monId.nil? @error = 'monId is nil' return false else reset_monitor! end end
Private Instance Methods
create()
click to toggle source
# File lib/device_cloud/monitor.rb, line 91 def create response = DeviceCloud::Request.new(path: '/ws/Monitor', body: to_xml).post if response.code == '201' self.monId = response.headers['location'][0].sub(/Monitor\//, '') return true else @error = error_from_response_xml(response) return false end end
error_from_response_xml(response)
click to toggle source
# File lib/device_cloud/monitor.rb, line 136 def error_from_response_xml(response) response.body.match(/<error>(.*)<\/error>/)[1] end
reset_monitor!()
click to toggle source
# File lib/device_cloud/monitor.rb, line 113 def reset_monitor! response = DeviceCloud::Request.new(path: "/ws/Monitor", body: reset_xml).put if response.code == '200' return true else @error = error_from_response_xml(response) return false end end
reset_xml()
click to toggle source
# File lib/device_cloud/monitor.rb, line 124 def reset_xml "<Monitor><monId>#{monId}</monId></Monitor>" end
set_defaults()
click to toggle source
# File lib/device_cloud/monitor.rb, line 85 def set_defaults DEFAULT_CREATE_OPTIONS.each do |option, value| send("#{option}=", value) if attributes[:option].nil? end end
to_xml()
click to toggle source
# File lib/device_cloud/monitor.rb, line 128 def to_xml xml = '<Monitor>' attributes.each do |key,value| xml << "<#{key}>#{value}</#{key}>" end xml << '</Monitor>' end
update()
click to toggle source
# File lib/device_cloud/monitor.rb, line 102 def update response = DeviceCloud::Request.new(path: "/ws/Monitor/#{monId}", body: to_xml).put if response.code == '200' return true else @error = error_from_response_xml(response) return false end end