Class: Innologix::Device
- Inherits:
-
Object
- Object
- Innologix::Device
- Defined in:
- lib/innologix/device.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#client ⇒ Object
Returns the value of attribute client.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#device_type ⇒ Object
Returns the value of attribute device_type.
-
#device_type_id ⇒ Object
Returns the value of attribute device_type_id.
-
#error ⇒ Object
Returns the value of attribute error.
-
#fwd_proto ⇒ Object
Returns the value of attribute fwd_proto.
-
#group ⇒ Object
Returns the value of attribute group.
-
#id ⇒ Object
Returns the value of attribute id.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#logs ⇒ Object
Returns the value of attribute logs.
-
#m2m ⇒ Object
Returns the value of attribute m2m.
-
#m2m_id ⇒ Object
Returns the value of attribute m2m_id.
-
#mac_address ⇒ Object
Returns the value of attribute mac_address.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sla_group ⇒ Object
Returns the value of attribute sla_group.
-
#sla_group_id ⇒ Object
Returns the value of attribute sla_group_id.
-
#status ⇒ Object
Returns the value of attribute status.
-
#supervisor ⇒ Object
Returns the value of attribute supervisor.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
- #from_hash(attributes) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(h = {}) ⇒ Device
constructor
A new instance of Device.
- #list(offset = 0, limit = 10, params = {}) ⇒ Object
- #list_devices(offset = 0, limit = 10, params = {}) ⇒ Object
- #statistic_minutes(from_time, to_time, arrange, supervisor_id = 0) ⇒ Object
- #total ⇒ Object
- #update ⇒ Object
Constructor Details
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/innologix/device.rb', line 5 def address @address end |
#client ⇒ Object
Returns the value of attribute client.
25 26 27 |
# File 'lib/innologix/device.rb', line 25 def client @client end |
#created_at ⇒ Object
Returns the value of attribute created_at.
15 16 17 |
# File 'lib/innologix/device.rb', line 15 def created_at @created_at end |
#device_type ⇒ Object
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_id ⇒ Object
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 |
#error ⇒ Object
Returns the value of attribute error.
26 27 28 |
# File 'lib/innologix/device.rb', line 26 def error @error end |
#fwd_proto ⇒ Object
Returns the value of attribute fwd_proto.
8 9 10 |
# File 'lib/innologix/device.rb', line 8 def fwd_proto @fwd_proto end |
#group ⇒ Object
Returns the value of attribute group.
20 21 22 |
# File 'lib/innologix/device.rb', line 20 def group @group end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/innologix/device.rb', line 3 def id @id end |
#interval ⇒ Object
Returns the value of attribute interval.
7 8 9 |
# File 'lib/innologix/device.rb', line 7 def interval @interval end |
#logs ⇒ Object
Returns the value of attribute logs.
13 14 15 |
# File 'lib/innologix/device.rb', line 13 def logs @logs end |
#m2m ⇒ Object
Returns the value of attribute m2m.
21 22 23 |
# File 'lib/innologix/device.rb', line 21 def m2m @m2m end |
#m2m_id ⇒ Object
Returns the value of attribute m2m_id.
12 13 14 |
# File 'lib/innologix/device.rb', line 12 def m2m_id @m2m_id end |
#mac_address ⇒ Object
Returns the value of attribute mac_address.
6 7 8 |
# File 'lib/innologix/device.rb', line 6 def mac_address @mac_address end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/innologix/device.rb', line 4 def name @name end |
#sla_group ⇒ Object
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_id ⇒ Object
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 |
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/innologix/device.rb', line 9 def status @status end |
#supervisor ⇒ Object
Returns the value of attribute supervisor.
19 20 21 |
# File 'lib/innologix/device.rb', line 19 def supervisor @supervisor end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
14 15 16 |
# File 'lib/innologix/device.rb', line 14 def @timestamp end |
#updated_at ⇒ Object
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
#create ⇒ Object
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 } = { form_params: { device: form_params } } result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#delete ⇒ Object
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 |
#disable ⇒ Object
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 = {} = { form_params: { device: form_params } } result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#enable ⇒ Object
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 = {} = { form_params: { device: form_params } } result = client.call_api(path, method, ) 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. = 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' = { query_params: { offset: offset, limit: limit }.merge(params) } result = client.call_api(path, method, ) if result[:error].nil? list = [] result[:devices].each do |device| list.push(from_hash(device)) end = OpenStruct.new .offset = result[:meta][:offset] .limit = result[:meta][:limit] .total = result[:meta][:total] result = OpenStruct.new result.devices = list result. = 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' = { query_params: { offset: offset, limit: limit }.merge(params) } result = client.call_api(path, method, ) list = [] if result[:error].nil? result[:devices].each do |device| list.push(from_hash(device)) end end = OpenStruct.new .offset = result[:meta][:offset] .limit = result[:meta][:limit] .total = result[:meta][:total] result = OpenStruct.new result.devices = list result. = 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' = { query_params: { from_time: from_time, to_time: to_time, arrange: arrange, supervisor_id: supervisor_id } } result = client.call_api(path, method, ) if result[:error] == 0 list = [] result[:statistics].each do |statistic| _statistic = OpenStruct.new _statistic. = statistic[:timestamp] _statistic.devices = statistic[:devices] list.push(_statistic) end list else [] end end |
#total ⇒ Object
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' = {} result = client.call_api(path, method, ) if result[:error].nil? result else nil end end |
#update ⇒ Object
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 } = { form_params: { device: form_params } } result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |