Class: Innologix::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/innologix/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h = {}) ⇒ Device

Returns a new instance of Device.



28
29
30
31
# File 'lib/innologix/device.rb', line 28

def initialize(h = {})
  h.each { |k, v| public_send("#{k}=", v) }
  @client = Client.default
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'lib/innologix/device.rb', line 5

def address
  @address
end

#clientObject

Returns the value of attribute client.



25
26
27
# File 'lib/innologix/device.rb', line 25

def client
  @client
end

#created_atObject

Returns the value of attribute created_at.



15
16
17
# File 'lib/innologix/device.rb', line 15

def created_at
  @created_at
end

#device_typeObject

Returns the value of attribute device_type.



22
23
24
# File 'lib/innologix/device.rb', line 22

def device_type
  @device_type
end

#device_type_idObject

Returns the value of attribute device_type_id.



10
11
12
# File 'lib/innologix/device.rb', line 10

def device_type_id
  @device_type_id
end

#errorObject

Returns the value of attribute error.



26
27
28
# File 'lib/innologix/device.rb', line 26

def error
  @error
end

#fwd_protoObject

Returns the value of attribute fwd_proto.



8
9
10
# File 'lib/innologix/device.rb', line 8

def fwd_proto
  @fwd_proto
end

#groupObject

Returns the value of attribute group.



20
21
22
# File 'lib/innologix/device.rb', line 20

def group
  @group
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/innologix/device.rb', line 3

def id
  @id
end

#intervalObject

Returns the value of attribute interval.



7
8
9
# File 'lib/innologix/device.rb', line 7

def interval
  @interval
end

#logsObject

Returns the value of attribute logs.



13
14
15
# File 'lib/innologix/device.rb', line 13

def logs
  @logs
end

#m2mObject

Returns the value of attribute m2m.



21
22
23
# File 'lib/innologix/device.rb', line 21

def m2m
  @m2m
end

#m2m_idObject

Returns the value of attribute m2m_id.



12
13
14
# File 'lib/innologix/device.rb', line 12

def m2m_id
  @m2m_id
end

#mac_addressObject

Returns the value of attribute mac_address.



6
7
8
# File 'lib/innologix/device.rb', line 6

def mac_address
  @mac_address
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/innologix/device.rb', line 4

def name
  @name
end

#sla_groupObject

Returns the value of attribute sla_group.



23
24
25
# File 'lib/innologix/device.rb', line 23

def sla_group
  @sla_group
end

#sla_group_idObject

Returns the value of attribute sla_group_id.



11
12
13
# File 'lib/innologix/device.rb', line 11

def sla_group_id
  @sla_group_id
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/innologix/device.rb', line 9

def status
  @status
end

#supervisorObject

Returns the value of attribute supervisor.



19
20
21
# File 'lib/innologix/device.rb', line 19

def supervisor
  @supervisor
end

#timestampObject

Returns the value of attribute timestamp.



14
15
16
# File 'lib/innologix/device.rb', line 14

def timestamp
  @timestamp
end

#updated_atObject

Returns the value of attribute updated_at.



16
17
18
# File 'lib/innologix/device.rb', line 16

def updated_at
  @updated_at
end

Instance Method Details

#createObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/innologix/device.rb', line 121

def create
  path = '/devices'
  method = 'post'
  form_params = { name: name, address: address, device_type_id: device_type_id,
                  sla_group_id: sla_group_id, fwd_proto: fwd_proto, m2m_id: m2m_id,
                  mac_address: mac_address, interval: interval }
  options = { form_params: { device: form_params } }
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end

#deleteObject



177
178
179
180
181
182
183
184
185
186
# File 'lib/innologix/device.rb', line 177

def delete
  path = '/devices/' + id.to_s
  method = 'delete'
  result = client.call_api(path, method)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end

#disableObject



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/innologix/device.rb', line 149

def disable
  path = '/devices/' + id.to_s + '/disable'
  method = 'patch'
  form_params = {}
  options = { form_params: { device: form_params } }
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end

#enableObject



136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/innologix/device.rb', line 136

def enable
  path = '/devices/' + id.to_s + '/enable'
  method = 'patch'
  form_params = {}
  options = { form_params: { device: form_params } }
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end

#from_hash(attributes) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/innologix/device.rb', line 188

def from_hash(attributes)
  device = Innologix::Device.new
  device.id = attributes[:id]
  device.name = attributes[:name]
  device.address = attributes[:address]
  device.mac_address = attributes[:mac_address]
  device.interval = attributes[:interval]
  device.fwd_proto = attributes[:fwd_proto]
  device.status = attributes[:status]
  device.device_type_id = attributes[:device_type_id]
  device.sla_group_id = attributes[:sla_group_id]
  device.m2m_id = attributes[:m2m_id]
  device.logs = attributes[:logs].nil? ? nil : attributes[:logs]
  device.timestamp = attributes[:timestamp].nil? ? nil : attributes[:timestamp]
  device.created_at = attributes[:created_at]
  device.updated_at = attributes[:updated_at]

  if attributes[:device_type] != nil
    device.device_type = DeviceType.new(attributes[:device_type])
  end

  if attributes[:sla_group] != nil
    device.sla_group = SlaGroup.new(attributes[:sla_group])
  end
  device
end

#get(id) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/innologix/device.rb', line 110

def get(id)
  path = '/devices/' + id.to_s
  method = 'get'
  result = client.call_api(path, method)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end

#list(offset = 0, limit = 10, params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/innologix/device.rb', line 33

def list(offset = 0, limit = 10, params = {})
  path = '/devices'
  method = 'get'
  options = { query_params: { offset: offset, limit: limit }.merge(params) }
  result = client.call_api(path, method, options)
  if result[:error].nil?
    list = []
    result[:devices].each do |device|
      list.push(from_hash(device))
    end
    meta = OpenStruct.new
    meta.offset = result[:meta][:offset]
    meta.limit = result[:meta][:limit]
    meta.total = result[:meta][:total]

    result = OpenStruct.new
    result.devices = list
    result.meta = meta
    result
  else
    RequestError.new(result)
  end
end

#list_devices(offset = 0, limit = 10, params = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/innologix/device.rb', line 57

def list_devices(offset = 0, limit = 10, params = {})
  path = '/devices/list'
  method = 'get'
  options = { query_params: { offset: offset, limit: limit }.merge(params) }
  result = client.call_api(path, method, options)
  list = []
  if result[:error].nil?
    result[:devices].each do |device|
      list.push(from_hash(device))
    end
  end
  meta = OpenStruct.new
  meta.offset = result[:meta][:offset]
  meta.limit = result[:meta][:limit]
  meta.total = result[:meta][:total]

  result = OpenStruct.new
  result.devices = list
  result.meta = meta
  result
end

#statistic_minutes(from_time, to_time, arrange, supervisor_id = 0) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/innologix/device.rb', line 91

def statistic_minutes(from_time, to_time, arrange, supervisor_id = 0)
  path = '/devices/statistic_minutes'
  method = 'get'
  options = { query_params: { from_time: from_time, to_time: to_time, arrange: arrange, supervisor_id: supervisor_id } }
  result = client.call_api(path, method, options)
  if result[:error] == 0
    list = []
    result[:statistics].each do |statistic|
      _statistic = OpenStruct.new
      _statistic.timestamp = statistic[:timestamp]
      _statistic.devices = statistic[:devices]
      list.push(_statistic)
    end
    list
  else
    []
  end
end

#totalObject



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/innologix/device.rb', line 79

def total
  path = '/devices/total'
  method = 'get'
  options = {}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    result
  else
    nil
  end
end

#updateObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/innologix/device.rb', line 162

def update
  path = '/devices/' + id.to_s
  method = 'put'
  form_params = { name: name, address: address, device_type_id: device_type_id,
                  sla_group_id: sla_group_id, fwd_proto: fwd_proto, m2m_id: m2m_id,
                  mac_address: mac_address, interval: interval }
  options = { form_params: { device: form_params } }
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end