Class: Hcloud::DatacenterResource
Instance Attribute Summary
#base_path, #client, #parent
Instance Method Summary
collapse
#each, #initialize, #limit, #mj, #order, #page, #per_page
Instance Method Details
#[](arg) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/hcloud/datacenter_resource.rb', line 33
def [](arg)
case arg
when Integer
begin
find(arg)
rescue Error::NotFound
end
when String
find_by(name: arg)
end
end
|
#all ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/hcloud/datacenter_resource.rb', line 5
def all
j = Oj.load(request("datacenters").run.body)
dc = j["datacenters"].map{|x| Datacenter.new(x, self, client) }
dc.reject{|x| x.id == j["recommendation"]}.unshift(
dc.find{|x| x.id == j["recommendation"]}
)
end
|
#find(id) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/hcloud/datacenter_resource.rb', line 17
def find(id)
Datacenter.new(
Oj.load(request("datacenters/#{id}").run.body)["datacenter"],
self,
client
)
end
|
#find_by(name:) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/hcloud/datacenter_resource.rb', line 25
def find_by(name:)
x = Oj.load(request("datacenters", q: {name: name}).run.body)["datacenters"]
return nil if x.none?
x.each do |s|
return Datacenter.new(s, self, client)
end
end
|
#recommended ⇒ Object
13
14
15
|
# File 'lib/hcloud/datacenter_resource.rb', line 13
def recommended
all.first
end
|