Class: Cradlepoint::NetDevice

Inherits:
CradlepointObject show all
Includes:
HashHelpers
Defined in:
lib/cradlepoint/net_device.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashHelpers

#symbolize_keys

Methods inherited from CradlepointObject

build_new_url, #build_new_url, #build_url, build_url, #params

Constructor Details

#initialize(id = nil, router = nil) ⇒ NetDevice

Returns a new instance of NetDevice.



9
10
11
12
# File 'lib/cradlepoint/net_device.rb', line 9

def initialize(id = nil, router = nil)
  self.id = id
  self.router = router
end

Instance Attribute Details

#bytes_inObject

Returns the value of attribute bytes_in.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def bytes_in
  @bytes_in
end

#bytes_outObject

Returns the value of attribute bytes_out.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def bytes_out
  @bytes_out
end

#carrierObject

Returns the value of attribute carrier.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def carrier
  @carrier
end

#connection_stateObject

Returns the value of attribute connection_state.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def connection_state
  @connection_state
end

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def data
  @data
end

#dns0Object

Returns the value of attribute dns0.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def dns0
  @dns0
end

#dns1Object

Returns the value of attribute dns1.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def dns1
  @dns1
end

#esnObject

Returns the value of attribute esn.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def esn
  @esn
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def id
  @id
end

#imeiObject

Returns the value of attribute imei.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def imei
  @imei
end

#infoObject

Returns the value of attribute info.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def info
  @info
end

#ip_addressObject

Returns the value of attribute ip_address.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def ip_address
  @ip_address
end

#ip_modeObject

Returns the value of attribute ip_mode.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def ip_mode
  @ip_mode
end

#macObject

Returns the value of attribute mac.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def mac
  @mac
end

#modeObject

Returns the value of attribute mode.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def mode
  @mode
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def name
  @name
end

#netmaskObject

Returns the value of attribute netmask.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def netmask
  @netmask
end

#routerObject

Returns the value of attribute router.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def router
  @router
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def type
  @type
end

#uptimeObject

Returns the value of attribute uptime.



5
6
7
# File 'lib/cradlepoint/net_device.rb', line 5

def uptime
  @uptime
end

Class Method Details

.rel_urlObject



14
15
16
# File 'lib/cradlepoint/net_device.rb', line 14

def self.rel_url
  '/net_devices'
end

.rel_url_from_router(router_id) ⇒ Object



30
31
32
# File 'lib/cradlepoint/net_device.rb', line 30

def self.rel_url_from_router(router_id)
  "/routers/#{ router_id }/net_devices/"
end

.rel_url_with_id(id) ⇒ Object



22
23
24
# File 'lib/cradlepoint/net_device.rb', line 22

def self.rel_url_with_id(id)
  "#{ Cradlepoint::NetDevice.rel_url }/#{ id }"
end

Instance Method Details

#assign_attributes_from_blob(blob = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cradlepoint/net_device.rb', line 64

def assign_attributes_from_blob(blob = {})
  return unless blob and blob.any?

  self.connection_state = blob[:connection_state]
  self.bytes_in = blob[:bytes_in]
  self.bytes_out = blob[:bytes_out]
  self.carrier = blob[:carrier]
  self.esn = blob[:esn]
  self.imei = blob[:imei]
  self.info = blob[:info]
  self.ip_address = blob[:ip_address]
  self.mac = blob[:mac]
  self.mode = blob[:mode]
  self.name = blob[:name]
  self.type = blob[:type]
  self.uptime = blob[:uptime]
  self.netmask = blob[:netmask]
  self.dns0 = blob[:dns0]
  self.dns1 = blob[:dns1]
  self.ip_mode = blob[:config][:ipmode] if blob[:config].is_a?(Hash)
end

#assign_attributes_from_data(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cradlepoint/net_device.rb', line 44

def assign_attributes_from_data(options = {})
  return unless self.data and self.data.any?
  raw_data = self.data

  if options[:group]
    return unless raw_data.is_a?(Array)

    net_devices = []
    raw_data.each do |nd|
      new_net_device = NetDevice.new(nd[:id], self.id)
      new_net_device.assign_attributes_from_blob(nd)
      net_devices << new_net_device
    end

    net_devices
  else
    assign_attributes_from_blob(raw_data)
  end
end

#get_all_from_routerObject



38
39
40
41
42
# File 'lib/cradlepoint/net_device.rb', line 38

def get_all_from_router
  raise 'You must provide an ECM router' if router.nil?
  self.data = Cradlepoint.make_request(:get, build_url(rel_url_from_router))
  assign_attributes_from_data(group: true)
end

#rel_urlObject



18
19
20
# File 'lib/cradlepoint/net_device.rb', line 18

def rel_url
  Cradlepoint::NetDevice.rel_url
end

#rel_url_from_routerObject



34
35
36
# File 'lib/cradlepoint/net_device.rb', line 34

def rel_url_from_router
  Cradlepoint::NetDevice.rel_url_from_router(router.id)
end

#rel_url_with_idObject



26
27
28
# File 'lib/cradlepoint/net_device.rb', line 26

def rel_url_with_id
  Cradlepoint::NetDevice.rel_url_with_id(id)
end