Class: DeviceCloud::Monitor

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

Constant Summary collapse

DEFAULT_CREATE_OPTIONS =
{
  'monTransportType' => 'http',
  'monTransportUrl' => "http://www.example.com/push_notifications",
  'monTransportToken' => "USERNAME:PASSWORD",
  'monFormatType' => 'json',
  'monBatchSize' => '1',
  'monCompression' => 'none',
  'monBatchDuration' => '0',
  'monAutoReplayOnConnect' => 'true'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Monitor

Returns a new instance of Monitor.



37
38
39
40
41
42
43
44
45
# 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

Instance Attribute Details

#cstIdObject

Returns the value of attribute cstId.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def cstId
  @cstId
end

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/device_cloud/monitor.rb', line 4

def error
  @error
end

#monAutoReplayOnConnectObject

Returns the value of attribute monAutoReplayOnConnect.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monAutoReplayOnConnect
  @monAutoReplayOnConnect
end

#monBatchDurationObject

Returns the value of attribute monBatchDuration.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monBatchDuration
  @monBatchDuration
end

#monBatchSizeObject

Returns the value of attribute monBatchSize.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monBatchSize
  @monBatchSize
end

#monCompressionObject

Returns the value of attribute monCompression.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monCompression
  @monCompression
end

#monFormatTypeObject

Returns the value of attribute monFormatType.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monFormatType
  @monFormatType
end

#monIdObject

Returns the value of attribute monId.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monId
  @monId
end

#monLastConnectObject

Returns the value of attribute monLastConnect.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monLastConnect
  @monLastConnect
end

#monLastSentObject

Returns the value of attribute monLastSent.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monLastSent
  @monLastSent
end

#monLastSentUuidObject

Returns the value of attribute monLastSentUuid.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monLastSentUuid
  @monLastSentUuid
end

#monStatusObject

Returns the value of attribute monStatus.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monStatus
  @monStatus
end

#monTopicObject

Returns the value of attribute monTopic.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monTopic
  @monTopic
end

#monTransportTokenObject

Returns the value of attribute monTransportToken.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monTransportToken
  @monTransportToken
end

#monTransportTypeObject

Returns the value of attribute monTransportType.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monTransportType
  @monTransportType
end

#monTransportUrlObject

Returns the value of attribute monTransportUrl.



3
4
5
# File 'lib/device_cloud/monitor.rb', line 3

def monTransportUrl
  @monTransportUrl
end

Class Method Details

.allObject



18
19
20
21
22
23
24
25
26
# 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) ⇒ Object



28
29
30
31
32
33
34
# 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

Instance Method Details

#attributesObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# 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!Object



62
63
64
65
66
67
68
# 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!Object



47
48
49
50
# File 'lib/device_cloud/monitor.rb', line 47

def persist!
  @error = nil
  monId.nil? ? create : update
end

#reset!Object



52
53
54
55
56
57
58
59
60
# 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