hcloud 0.1.0.pre.alpha1 → 0.1.0.pre.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hcloud/action_resource.rb +30 -2
- data/lib/hcloud/client.rb +7 -0
- data/lib/hcloud/server_resource.rb +26 -0
- data/lib/hcloud/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d06f412cafbce3cb4f22d53d04137bcddc19da24
|
4
|
+
data.tar.gz: 1eecd88d2ec332f2f4f9b7845b347d2496a7d287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74cb30970ccdb4d8779240c9190f82562a2af3838d6203af8ce6692e83f406b8e2a176e779a040c26db3c3f29ef0319b648d3e6636d05be9f64d4571c25c71cb
|
7
|
+
data.tar.gz: b39c792472d9d107df2acb86a5c6d510b457854465d6403fd59ec9335cbea6279b165b86f33ad2e3403501189c293be6534521f8091cb64d28a8df58a48edaae
|
@@ -3,11 +3,39 @@ module Hcloud
|
|
3
3
|
class ActionResource < AbstractResource
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
def all
|
7
|
-
Oj.load(request(base_path
|
6
|
+
def all(sort: nil)
|
7
|
+
Oj.load(request(base_path("actions"), q: {sort: sort}).run.body)["actions"].map do |x|
|
8
8
|
Action.new(x, self, client)
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
def find(id)
|
13
|
+
Action.new(
|
14
|
+
Oj.load(request(base_path("actions/#{id.to_i}")).run.body)["action"],
|
15
|
+
self,
|
16
|
+
client
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](arg)
|
21
|
+
find(arg)
|
22
|
+
rescue Error::NotFound
|
23
|
+
end
|
24
|
+
|
25
|
+
def where(status: nil, sort: nil)
|
26
|
+
Oj.load(
|
27
|
+
request(base_path("actions"),
|
28
|
+
q: {status: status, sort: sort}).run.body
|
29
|
+
)["actions"].map do |x|
|
30
|
+
Action.new(x, self, client)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def base_path(ext)
|
37
|
+
[@base_path, ext].reject(&:empty?).join('/')
|
38
|
+
end
|
11
39
|
|
12
40
|
end
|
13
41
|
end
|
data/lib/hcloud/client.rb
CHANGED
@@ -19,12 +19,19 @@ module Hcloud
|
|
19
19
|
ServerResource.new(client: self)
|
20
20
|
end
|
21
21
|
|
22
|
+
def actions
|
23
|
+
ActionResource.new(client: self)
|
24
|
+
end
|
25
|
+
|
22
26
|
def request(path, **options)
|
23
27
|
code = options.delete(:code)
|
24
28
|
if x = options.delete(:j)
|
25
29
|
options[:body] = Oj.dump(x, mode: :compat)
|
26
30
|
options[:method] ||= :post
|
27
31
|
end
|
32
|
+
if x = options.delete(:q)
|
33
|
+
path << "?"+x.to_param
|
34
|
+
end
|
28
35
|
r = Typhoeus::Request.new(
|
29
36
|
"https://api.hetzner.cloud/v1/#{path}",
|
30
37
|
{
|
@@ -26,5 +26,31 @@ module Hcloud
|
|
26
26
|
Server.new(x, self, client)
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def find(id)
|
31
|
+
Server.new(
|
32
|
+
Oj.load(request("servers/#{id.to_i}").run.body)["server"], self, client
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](arg)
|
37
|
+
case arg
|
38
|
+
when Integer
|
39
|
+
begin
|
40
|
+
find(arg)
|
41
|
+
rescue Error::NotFound
|
42
|
+
end
|
43
|
+
when String
|
44
|
+
find_by(name: arg)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_by(name:)
|
49
|
+
x = Oj.load(request("servers", q: {name: name}).run.body)["servers"]
|
50
|
+
return nil if x.none?
|
51
|
+
x.each do |s|
|
52
|
+
return Server.new(s, self, client)
|
53
|
+
end
|
54
|
+
end
|
29
55
|
end
|
30
56
|
end
|
data/lib/hcloud/version.rb
CHANGED