Class: Hcloud::FloatingIPResource
Instance Attribute Summary
#base_path, #client, #parent
Instance Method Summary
collapse
#each, #initialize, #limit, #mj, #order, #page, #per_page
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
|
#all ⇒ Object
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)
[
j.key?("action") ? Action.new(j["action"], self, client) : nil,
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
|