class Innologix::M2m

Attributes

client[RW]
created_at[RW]
error[RW]
group[RW]
group_id[RW]
id[RW]
ip[RW]
name[RW]
status[RW]
updated_at[RW]

Public Class Methods

new(h = {}) click to toggle source
# File lib/innologix/m2m.rb, line 16
def initialize(h = {})
  h.each { |k, v| public_send("#{k}=", v) }
  @client = Client.default
end

Public Instance Methods

add_devices(devices = [], callback = nil) click to toggle source
# 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}
  options = {form_params: form_params}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end
check_status(callback = nil) click to toggle source
# 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}
  options = {form_params: form_params}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    result[:message]
  else
    RequestError.new(result)
  end
end
create() click to toggle source
# File lib/innologix/m2m.rb, line 56
def create
  path = '/m2ms'
  method = 'post'
  form_params = {name: name, ip: ip, group_id: group_id}
  options = {form_params: {m2m: 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/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 = {}) click to toggle source
# File lib/innologix/m2m.rb, line 160
def devices(offset = 0, limit = 10, params = {})
  path = '/devices/list'
  method = 'get'
  options = {query_params: {m2m_id: self.id, 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(Innologix::Device.new(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
from_hash(attributes) click to toggle source
# 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) click to toggle source
# 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 = {}) click to toggle source
# File lib/innologix/m2m.rb, line 21
def list(offset = 0, limit = 10, params = {})
  path = '/m2ms'
  method = 'get'
  options = {query_params: {offset: offset, limit: limit}.merge(params)}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    list =[]
    result[:m2ms].each do |m2m|
      list.push(from_hash(m2m))
    end
    meta = OpenStruct.new
    meta.offset = result[:meta][:offset]
    meta.limit = result[:meta][:limit]
    meta.total = result[:meta][:total]

    result = OpenStruct.new
    result.m2ms = list
    result.meta = meta
    result
  else
    RequestError.new(result)
  end
end
remove_devices(devices = [], callback = nil) click to toggle source
# 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}
  options = {form_params: form_params}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end
restart(callback = nil) click to toggle source
# File lib/innologix/m2m.rb, line 119
def restart(callback = nil)
  path = '/m2ms/' + id.to_s + '/restart'
  method = 'patch'
  form_params = {callback: callback}
  options = {form_params: form_params}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    result[:message]
  else
    RequestError.new(result)
  end
end
total_devices() click to toggle source
# File lib/innologix/m2m.rb, line 182
def total_devices
  path = '/devices/total'
  method = 'get'
  options = {query_params: {m2m_id: self.id}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    result
  else
    0
  end
end
update() click to toggle source
# 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}
  options = {form_params: {m2m: form_params}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end