Class: Hcloud::FloatingIPResource

Inherits:
AbstractResource show all
Includes:
Enumerable
Defined in:
lib/hcloud/floating_ip_resource.rb

Instance Attribute Summary

Attributes inherited from AbstractResource

#base_path, #client, #parent

Instance Method Summary collapse

Methods inherited from AbstractResource

#each, #initialize, #limit, #mj, #order, #page, #per_page

Constructor Details

This class inherits a constructor from Hcloud::AbstractResource

Instance Method Details

#[](arg) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/hcloud/floating_ip_resource.rb', line 30

def [](arg)
  case arg
  when Integer
   begin
     find(arg)
   rescue Error::NotFound
   end
  end
end

#allObject



5
6
7
8
# File 'lib/hcloud/floating_ip_resource.rb', line 5

def all
  j = Oj.load(request("floating_ips").run.body)
  j["floating_ips"].map{|x| FloatingIP.new(x, self, client) }
end

#create(type:, server: nil, home_location: nil, description: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hcloud/floating_ip_resource.rb', line 10

def create(type:, server: nil, home_location: nil, description: nil)
  query = {}
  method(:create).parameters.inject(query) do |r,x| 
    (var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
  end
  j = Oj.load(request("floating_ips", j: query, code: 200).run.body)
  [
    Action.new(j["action"], self, client),
    FloatingIP.new(j["floating_ip"], self, client),
  ]
end

#find(id) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/hcloud/floating_ip_resource.rb', line 22

def find(id)
  FloatingIP.new(
    Oj.load(request("floating_ips/#{id}").run.body)["floating_ip"],
    self,
    client
  )
end