Class: Cradlepoint::NetDevice

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CradlepointObject

build_new_url, #build_new_url, #build_url, build_url, ecm_object_blob?, #ecm_object_blob?, #params, #successful_response?, successful_response?

Constructor Details

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

Returns a new instance of NetDevice.



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

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.



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

def bytes_in
  @bytes_in
end

#bytes_outObject

Returns the value of attribute bytes_out.



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

def bytes_out
  @bytes_out
end

#carrierObject

Returns the value of attribute carrier.



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

def carrier
  @carrier
end

#connection_stateObject

Returns the value of attribute connection_state.



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

def connection_state
  @connection_state
end

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#dns0Object

Returns the value of attribute dns0.



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

def dns0
  @dns0
end

#dns1Object

Returns the value of attribute dns1.



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

def dns1
  @dns1
end

#esnObject

Returns the value of attribute esn.



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

def esn
  @esn
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#imeiObject

Returns the value of attribute imei.



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

def imei
  @imei
end

#infoObject

Returns the value of attribute info.



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

def info
  @info
end

#ip_addressObject

Returns the value of attribute ip_address.



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

def ip_address
  @ip_address
end

#ip_modeObject

Returns the value of attribute ip_mode.



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

def ip_mode
  @ip_mode
end

#macObject

Returns the value of attribute mac.



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

def mac
  @mac
end

#modeObject

Returns the value of attribute mode.



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

def mode
  @mode
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#netmaskObject

Returns the value of attribute netmask.



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

def netmask
  @netmask
end

#routerObject

Returns the value of attribute router.



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

def router
  @router
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#uptimeObject

Returns the value of attribute uptime.



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

def uptime
  @uptime
end

Class Method Details

.rel_urlObject



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

def self.rel_url
  '/net_devices'
end

.rel_url_from_router(router_id) ⇒ Object



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

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

.rel_url_with_id(id) ⇒ Object



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

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

Instance Method Details

#assign_attributes_from_blob(blob = {}) ⇒ Object



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

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

  self.data = blob
  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



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

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



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

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

#get_all_from_router_as_hashObject



43
44
45
# File 'lib/cradlepoint/net_device.rb', line 43

def get_all_from_router_as_hash
  Cradlepoint.make_request(:get, build_url(rel_url_from_router))
end

#rel_urlObject



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

def rel_url
  Cradlepoint::NetDevice.rel_url
end

#rel_url_from_routerObject



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

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

#rel_url_with_idObject



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

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