class Innologix::Storage

Attributes

client[RW]
created_at[RW]
error[RW]
id[RW]
ip[RW]
name[RW]
port[RW]
updated_at[RW]

Public Class Methods

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

Public Instance Methods

create() click to toggle source
# 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
delete() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
update() click to toggle source
# 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