class Innologix::Device
Attributes
address[RW]
client[RW]
created_at[RW]
device_type[RW]
device_type_id[RW]
error[RW]
fwd_proto[RW]
group[RW]
id[RW]
interval[RW]
logs[RW]
m2m[RW]
m2m_id[RW]
mac_address[RW]
name[RW]
sla_group[RW]
sla_group_id[RW]
status[RW]
supervisor[RW]
timestamp[RW]
updated_at[RW]
Public Class Methods
new(h = {})
click to toggle source
# File lib/innologix/device.rb, line 28 def initialize(h = {}) h.each { |k, v| public_send("#{k}=", v) } @client = Client.default end
Public Instance Methods
create()
click to toggle source
# 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
delete()
click to toggle source
# 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
disable()
click to toggle source
# 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
enable()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
# 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
total()
click to toggle source
# 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
update()
click to toggle source
# 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