deis_client 1.5.1.dev2 → 1.5.1.dev3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/deis_client.rb +42 -13
- 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: 91244b20bfcb418319c9b9fcbb5d7bd799bd3017
|
4
|
+
data.tar.gz: 1f86918cc17e74dcc8b29c6554bacc0b15235445
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3813b2230e0dc6a09048da2f6153a4fbf429f1bc7f5d4a0f48ba462c0c0a6e76752fa4793793df355b11efe4c5fcc57c80dfd13d9b460bbfd4f61bccfe8fa60d
|
7
|
+
data.tar.gz: d6cc27ac19b18d8954ebdd31cebba766a328d24bf5573707a26f161e42e55ec05e0131cb2076f25ec4e10914fe5c6a8072a4d0378970cb1139009b9cba23e06b
|
data/lib/deis_client.rb
CHANGED
@@ -1,6 +1,32 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
3
|
module Deis
|
4
|
+
class Error < StandardError
|
5
|
+
def initialize(http_status = nil, message = nil, data = nil)
|
6
|
+
@status = http_status
|
7
|
+
@message = message
|
8
|
+
@data = data
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ClientError < Error; end
|
13
|
+
|
14
|
+
class ServerError < Error; end
|
15
|
+
|
16
|
+
# the following two errors are just convenience for better rescuing
|
17
|
+
class AuthorizationError < ClientError
|
18
|
+
def initialize(message = nil, data = nil)
|
19
|
+
super(401, message, data)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class NotFound < ClientError
|
24
|
+
def initialize(message = nil, data = nil)
|
25
|
+
super(404, message, data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
4
30
|
class ApiWrapper
|
5
31
|
include HTTParty
|
6
32
|
format :json
|
@@ -30,20 +56,20 @@ module Deis
|
|
30
56
|
@@methods = {
|
31
57
|
# method => HTTP-verb, path
|
32
58
|
login: [:post, '/auth/login/'],
|
33
|
-
apps: [:get, '/apps
|
59
|
+
apps: [:get, '/apps'],
|
34
60
|
create_app: [:post, '/apps/'],
|
35
61
|
delete_app: [:delete, '/apps/:app/'],
|
36
62
|
app: [:get, '/apps/:app/'],
|
37
63
|
app_logs: [:get, '/apps/:app/logs/'],
|
38
64
|
app_run: [:post, '/apps/:app/run/'],
|
39
65
|
containers: [:get, '/apps/:app/containers/'],
|
40
|
-
config: [:get, '/apps/:app/config'],
|
41
|
-
domains: [:get, '/apps/:app/domains'],
|
42
|
-
builds: [:get, '/apps/:app/builds'],
|
43
|
-
create_build: [:post, '/apps/:app/builds'],
|
44
|
-
releases: [:get, '/apps/:app/releases'],
|
45
|
-
release: [:get, '/apps/:app/releases/:release'],
|
46
|
-
rollback_release: [:post, '/apps/:app/releases/rollback']
|
66
|
+
config: [:get, '/apps/:app/config/'],
|
67
|
+
domains: [:get, '/apps/:app/domains/'],
|
68
|
+
builds: [:get, '/apps/:app/builds/'],
|
69
|
+
create_build: [:post, '/apps/:app/builds/'],
|
70
|
+
releases: [:get, '/apps/:app/releases/'],
|
71
|
+
release: [:get, '/apps/:app/releases/:release/'],
|
72
|
+
rollback_release: [:post, '/apps/:app/releases/rollback/']
|
47
73
|
}
|
48
74
|
|
49
75
|
def initialize(deis_url, username, password)
|
@@ -55,7 +81,7 @@ module Deis
|
|
55
81
|
def login
|
56
82
|
response = @http.post('/auth/login/', {body: @auth})
|
57
83
|
|
58
|
-
|
84
|
+
raise AuthorizationError.new unless response.code == 200
|
59
85
|
|
60
86
|
@token = response['token']
|
61
87
|
@headers['Authorization'] = "token #{@token}"
|
@@ -124,7 +150,6 @@ module Deis
|
|
124
150
|
|
125
151
|
protected
|
126
152
|
|
127
|
-
# TODO: use own, meaningful exceptions expecially in this method
|
128
153
|
def perform(method_sym, body={}, try_twice=true)
|
129
154
|
login unless @token
|
130
155
|
|
@@ -143,13 +168,17 @@ module Deis
|
|
143
168
|
when 200...300
|
144
169
|
response.parsed_response
|
145
170
|
when 401 # authentification required
|
146
|
-
raise
|
171
|
+
raise AuthorizationError.new unless try_twice
|
147
172
|
login
|
148
173
|
perform method_sym, options, false
|
149
174
|
when 404
|
150
|
-
|
175
|
+
raise NotFound
|
176
|
+
when 400...500
|
177
|
+
raise ClientError.new response.code, response.message, response: response
|
178
|
+
when 500...600
|
179
|
+
raise ServerError.new response.code, response.message, response: response
|
151
180
|
else
|
152
|
-
raise
|
181
|
+
raise Error.new response.code, response.message, response: response
|
153
182
|
end
|
154
183
|
end
|
155
184
|
|