Class: Innologix::DeviceType

Inherits:
Object
  • Object
show all
Defined in:
lib/innologix/device_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h = {}) ⇒ DeviceType

Returns a new instance of DeviceType.



14
15
16
17
# File 'lib/innologix/device_type.rb', line 14

def initialize(h = {})
  h.each { |k, v| public_send("#{k}=", v) }
  @client = Client.default
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



11
12
13
# File 'lib/innologix/device_type.rb', line 11

def client
  @client
end

#created_atObject

Returns the value of attribute created_at.



8
9
10
# File 'lib/innologix/device_type.rb', line 8

def created_at
  @created_at
end

#errorObject

Returns the value of attribute error.



12
13
14
# File 'lib/innologix/device_type.rb', line 12

def error
  @error
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/innologix/device_type.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/innologix/device_type.rb', line 4

def name
  @name
end

#protocolObject

Returns the value of attribute protocol.



6
7
8
# File 'lib/innologix/device_type.rb', line 6

def protocol
  @protocol
end

#supervisor_idObject

Returns the value of attribute supervisor_id.



5
6
7
# File 'lib/innologix/device_type.rb', line 5

def supervisor_id
  @supervisor_id
end

#tagsObject

Returns the value of attribute tags.



7
8
9
# File 'lib/innologix/device_type.rb', line 7

def tags
  @tags
end

#updated_atObject

Returns the value of attribute updated_at.



9
10
11
# File 'lib/innologix/device_type.rb', line 9

def updated_at
  @updated_at
end

Instance Method Details

#createObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/innologix/device_type.rb', line 54

def create
  path = '/device_types'
  method = 'post'
  options = {form_params: {device_type: {name: name, supervisor_id: supervisor_id, protocol: protocol, tags: tags}}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end

#deleteObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/innologix/device_type.rb', line 78

def delete
  path = '/device_types/' + id.to_s
  method = 'delete'
  result = client.call_api(path, method)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end

#from_hash(attributes) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/innologix/device_type.rb', line 89

def from_hash(attributes)
  device_type = Innologix::DeviceType.new
  device_type.id = attributes[:id]
  device_type.name = attributes[:name]
  device_type.supervisor_id = attributes[:supervisor_id]
  device_type.protocol = attributes[:protocol]
  device_type.tags = attributes[:tags]
  device_type.created_at = attributes[:created_at]
  device_type.updated_at = attributes[:updated_at]
  device_type
end

#get(id) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/innologix/device_type.rb', line 43

def get(id)
  path = '/device_types/' + 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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/innologix/device_type.rb', line 19

def list(offset = 0, limit = 10)
  path = '/device_types'
  method = 'get'
  options = {query_params: {offset: offset, limit: limit}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    list =[]
    result[:device_types].each do |device_type|
      list.push(from_hash(device_type))
    end
    meta = OpenStruct.new
    meta.offset = result[:meta][:offset]
    meta.limit = result[:meta][:limit]
    meta.total = result[:meta][:total]

    result = OpenStruct.new
    result.device_types = list
    result.meta = meta
    result
  else
    RequestError.new(result)
  end
end

#updateObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/innologix/device_type.rb', line 66

def update
  path = '/device_types/' + id.to_s
  method = 'put'
  options = {form_params: {device_type: {name: name, supervisor_id: supervisor_id, protocol: protocol, tags: tags}}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end