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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 864f8cc69037ab4a88ff373bc5a89fb89176dc32
4
- data.tar.gz: e4da295f210321c4021414a50d100edda921b741
3
+ metadata.gz: d06f412cafbce3cb4f22d53d04137bcddc19da24
4
+ data.tar.gz: 1eecd88d2ec332f2f4f9b7845b347d2496a7d287
5
5
  SHA512:
6
- metadata.gz: 800337279a9b7d2c0c8a8aace03da6e2ca9b352ce33061533ab79096dd726c709b5c904d79c37754b54eb4f039f0e9728bbd4ca5ffcd3970319370445a0641a1
7
- data.tar.gz: 4879ddfb318509306ae1bde0a588935d6086bd613c4306dec4c3f913f82ce4ec02c11b4fd8b08bd236beea7af8802994c43b7fee4f8dfe77c9cca38afc129216
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 + "/actions").run.body)["actions"].map do |x|
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
@@ -1,3 +1,3 @@
1
1
  module Hcloud
2
- VERSION = "0.1.0-alpha1"
2
+ VERSION = "0.1.0-alpha2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.alpha1
4
+ version: 0.1.0.pre.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Foerster