Class: Innologix::Storage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h = {}) ⇒ Storage

Returns a new instance of Storage.



13
14
15
16
# File 'lib/innologix/storage.rb', line 13

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.



10
11
12
# File 'lib/innologix/storage.rb', line 10

def client
  @client
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#errorObject

Returns the value of attribute error.



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

def error
  @error
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#ipObject

Returns the value of attribute ip.



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

def ip
  @ip
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

#updated_atObject

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

Instance Method Details

#createObject



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

def create
  path = '/storages'
  method = 'post'
  form_params = {name: name, ip: ip, port: port}
  options = {form_params: {storage: form_params}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end

#deleteObject



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

def delete
  path = '/storages/' + 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



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

def from_hash(attributes)
  storage = Innologix::Storage.new
  storage.id = attributes[:id]
  storage.name = attributes[:name]
  storage.ip = attributes[:ip]
  storage.port = attributes[:port]
  storage.created_at = attributes[:created_at]
  storage.updated_at = attributes[:updated_at]
  storage
end

#get(id) ⇒ Object



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

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



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

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

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

#updateObject



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

def update
  path = '/storages/' + id.to_s
  method = 'put'
  form_params = {name: name, ip: ip, port: port}
  options = {form_params: {storage: form_params}}
  result = client.call_api(path, method, options)
  if result[:error].nil?
    from_hash(result)
  else
    RequestError.new(result)
  end
end