Class: Innologix::M2m
- Inherits:
-
Object
- Object
- Innologix::M2m
- Defined in:
- lib/innologix/m2m.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#error ⇒ Object
Returns the value of attribute error.
-
#group ⇒ Object
Returns the value of attribute group.
-
#group_id ⇒ Object
Returns the value of attribute group_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#name ⇒ Object
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #add_devices(devices = [], callback = nil) ⇒ Object
- #check_status(callback = nil) ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #devices(offset = 0, limit = 10, params = {}) ⇒ Object
- #from_hash(attributes) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(h = {}) ⇒ M2m
constructor
A new instance of M2m.
- #list(offset = 0, limit = 10, params = {}) ⇒ Object
- #remove_devices(devices = [], callback = nil) ⇒ Object
- #restart(callback = nil) ⇒ Object
- #total_devices ⇒ Object
- #update ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
13 14 15 |
# File 'lib/innologix/m2m.rb', line 13 def client @client end |
#created_at ⇒ Object
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/innologix/m2m.rb', line 8 def created_at @created_at end |
#error ⇒ Object
Returns the value of attribute error.
14 15 16 |
# File 'lib/innologix/m2m.rb', line 14 def error @error end |
#group ⇒ Object
Returns the value of attribute group.
11 12 13 |
# File 'lib/innologix/m2m.rb', line 11 def group @group end |
#group_id ⇒ Object
Returns the value of attribute group_id.
7 8 9 |
# File 'lib/innologix/m2m.rb', line 7 def group_id @group_id end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/innologix/m2m.rb', line 3 def id @id end |
#ip ⇒ Object
Returns the value of attribute ip.
5 6 7 |
# File 'lib/innologix/m2m.rb', line 5 def ip @ip end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/innologix/m2m.rb', line 4 def name @name end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/innologix/m2m.rb', line 6 def status @status end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
9 10 11 |
# File 'lib/innologix/m2m.rb', line 9 def updated_at @updated_at end |
Instance Method Details
#add_devices(devices = [], callback = nil) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/innologix/m2m.rb', line 93 def add_devices(devices = [], callback = nil) path = '/m2ms/' + id.to_s + '/add_devices' method = 'patch' form_params = {devices: devices, callback: callback} = {form_params: form_params} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#check_status(callback = nil) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/innologix/m2m.rb', line 132 def check_status(callback = nil) path = '/m2ms/' + id.to_s + '/check_status' method = 'patch' form_params = {callback: callback} = {form_params: form_params} result = client.call_api(path, method, ) if result[:error].nil? result[:message] else RequestError.new(result) end end |
#create ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/innologix/m2m.rb', line 56 def create path = '/m2ms' method = 'post' form_params = {name: name, ip: ip, group_id: group_id} = {form_params: {m2m: form_params}} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#delete ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/innologix/m2m.rb', line 82 def delete path = '/m2ms/' + id.to_s method = 'delete' result = client.call_api(path, method) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#devices(offset = 0, limit = 10, params = {}) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/innologix/m2m.rb', line 160 def devices(offset = 0, limit = 10, params = {}) path = '/devices/list' method = 'get' = {query_params: {m2m_id: self.id, offset: offset, limit: limit}.merge(params)} result = client.call_api(path, method, ) list =[] if result[:error].nil? result[:devices].each do |device| list.push(Innologix::Device.new(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 |
#from_hash(attributes) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/innologix/m2m.rb', line 145 def from_hash(attributes) m2m = Innologix::M2m.new m2m.id = attributes[:id] m2m.name = attributes[:name] m2m.ip = attributes[:ip] m2m.status = attributes[:status] m2m.group_id = attributes[:group_id] m2m.created_at = attributes[:created_at] m2m.updated_at = attributes[:updated_at] if attributes[:group] != nil m2m.group = Innologix::Group.new(attributes[:group]) end m2m end |
#get(id) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/innologix/m2m.rb', line 45 def get(id) path = '/m2ms/' + 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/innologix/m2m.rb', line 21 def list(offset = 0, limit = 10, params = {}) path = '/m2ms' method = 'get' = {query_params: {offset: offset, limit: limit}.merge(params)} result = client.call_api(path, method, ) if result[:error].nil? list =[] result[:m2ms].each do |m2m| list.push(from_hash(m2m)) end = OpenStruct.new .offset = result[:meta][:offset] .limit = result[:meta][:limit] .total = result[:meta][:total] result = OpenStruct.new result.m2ms = list result. = result else RequestError.new(result) end end |
#remove_devices(devices = [], callback = nil) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/innologix/m2m.rb', line 106 def remove_devices(devices = [], callback = nil) path = '/m2ms/' + id.to_s + '/remove_devices' method = 'patch' form_params = {devices: devices, callback: callback} = {form_params: form_params} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#restart(callback = nil) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/innologix/m2m.rb', line 119 def restart(callback = nil) path = '/m2ms/' + id.to_s + '/restart' method = 'patch' form_params = {callback: callback} = {form_params: form_params} result = client.call_api(path, method, ) if result[:error].nil? result[:message] else RequestError.new(result) end end |
#total_devices ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/innologix/m2m.rb', line 182 def total_devices path = '/devices/total' method = 'get' = {query_params: {m2m_id: self.id}} result = client.call_api(path, method, ) if result[:error].nil? result else 0 end end |
#update ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/innologix/m2m.rb', line 69 def update path = '/m2ms/' + id.to_s method = 'put' form_params = {name: name, ip: ip, group_id: group_id} = {form_params: {m2m: form_params}} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |