deis_client 1.5.1.dev6 → 1.5.1.dev7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/deis_client.rb +37 -31
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45e38bb17af945d3e2eafad363063ec5c2dcc8b4
4
- data.tar.gz: 628afe55fa4b4f66d6ca0e2669ac563fbb461b1b
3
+ metadata.gz: 294b35c08130abe5681462bae18dc4cb6ec50f75
4
+ data.tar.gz: e4fd3eb53719b74fc8108b2ae005a85859c07342
5
5
  SHA512:
6
- metadata.gz: 9c3469f5e167a31c65532ca64c5b2795362c65e823ecf81b643fd820f93503eb5418327c20941e626c5201f202ce9a7103ee036abe6f16577efd2a30f6eb7169
7
- data.tar.gz: 01e135fb77fef9e06b4c8b26bbe9364f8fd2d265cb65932885a95ec9520d07188a24e3a01d74f9f772c742e38cac2c7a7ddcd966bf332d8a24a7ed92a31455fc
6
+ metadata.gz: 77d1663bbeee22927188a812536265f0672ff85fd77a0a9dc51af1bdad4d192ee02b7e71226a01c886268ed2d1ed74a36a4b2a4ddf3c838b5dc5c8f1f9707388
7
+ data.tar.gz: 1ee7e7c7283876966cfce733c5fefbaee2e6b5c682c14c7ab1a35a7640d6a0758bad4e3416db85774469fe06e1f86be0b496daa160ea16236bd040a42b561c67
data/lib/deis_client.rb CHANGED
@@ -77,12 +77,13 @@ module Deis
77
77
 
78
78
  def initialize(deis_url, username, password)
79
79
  @http = Deis::ApiWrapper.new deis_url
80
- @headers = {}
81
- @auth = {username: username, password: password}
80
+ @headers = {'Content-Type' => 'application/json'}
81
+ @auth = { username: username, password: password }
82
82
  end
83
83
 
84
84
  def login
85
- response = @http.post('/auth/login/', {body: @auth})
85
+ verb, path = @@methods[:login]
86
+ response = @http.public_send(verb, path, body: @auth)
86
87
 
87
88
  raise AuthorizationError.new unless response.code == 200
88
89
 
@@ -95,91 +96,96 @@ module Deis
95
96
  perform :apps
96
97
  end
97
98
 
98
- def create_app(id=nil)
99
+ def create_app(id = nil)
99
100
  if id
100
- perform :create_app, {id: id}
101
+ perform :create_app, {}, id: id
101
102
  else
102
103
  perform :create_app
103
104
  end
104
105
  end
105
106
 
106
107
  def delete_app(id)
107
- perform :delete_app, {app: id}
108
+ perform :delete_app, app: id
108
109
  end
109
110
 
110
111
  def app(id)
111
- perform :app, {app: id}
112
+ perform :app, app: id
112
113
  end
113
114
 
114
115
  def app_logs(id)
115
- perform :app_logs, {app: id}
116
+ perform :app_logs, app: id
116
117
  end
117
118
 
118
119
  def app_run(id, command)
119
- perform :app_run, {app: id, command: command}
120
+ perform :app_run, { app: id }, command: command
120
121
  end
121
122
 
122
123
  def containers(app_id)
123
- perform :containers, {app: app_id}
124
+ perform :containers, app: app_id
124
125
  end
125
126
 
126
127
  def scale(app_id, type_number_hash)
127
- perform :scale, type_number_hash.merge({app: app_id})
128
+ perform :scale, { app: app_id }, type_number_hash
128
129
  end
129
130
 
130
131
  def config(app_id)
131
- perform :config, {app: app_id}
132
+ perform :config, app: app_id
132
133
  end
133
134
 
134
135
  def domains(app_id)
135
- perform :domains, {app: app_id}
136
+ perform :domains, app: app_id
136
137
  end
137
138
 
138
139
  def builds(app_id)
139
- perform :builds, {app: app_id}
140
+ perform :builds, app: app_id
140
141
  end
141
142
 
142
143
  def create_build(app_id, image)
143
- perform :create_build, {app: app_id, image: image}
144
+ perform :create_build, { app: app_id }, image: image
144
145
  end
145
146
 
146
147
  def releases(app_id)
147
- perform :releases, {app: app_id}
148
+ perform :releases, app: app_id
148
149
  end
149
150
 
150
151
  def release(app_id, release)
151
- perform :releases, {app: app_id, release: release}
152
+ perform :releases, app: app_id, release: release
152
153
  end
153
154
 
154
155
  def rollback_release(app_id, release)
155
- perform :rollback_release, {app: app_id, release: release}
156
+ perform :rollback_release, { app: app_id }, release: release
156
157
  end
157
158
 
158
159
  protected
159
160
 
160
- def perform(method_sym, body={}, try_twice=true)
161
+ def perform(method_sym, interpolations = {}, body = {}, try_twice = true)
161
162
  login unless @token
162
163
 
163
164
  verb, path = @@methods[method_sym]
164
- path = interpolate_path(path, body)
165
+ path = interpolate_path(path, interpolations)
165
166
 
166
167
  options = {
167
168
  headers: @headers,
168
- body: body
169
+ body: body.to_json
169
170
  }
170
- handle @http.public_send(verb, path, options), try_twice
171
+
172
+ begin
173
+ handle @http.public_send(verb, path, options)
174
+ rescue AuthorizationError => e
175
+ raise e unless try_twice
176
+ login
177
+ handle @http.public_send(verb, path, options)
178
+ end
171
179
  end
172
180
 
173
- def handle(response, try_twice)
181
+ def handle(response)
174
182
  case response.code
175
183
  when 200...300
176
184
  response.parsed_response
177
- when 401 # authentification required
178
- raise AuthorizationError.new unless try_twice
179
- login
180
- perform method_sym, options, false
185
+ when 401
186
+ raise AuthorizationError.new
181
187
  when 404
182
- raise NotFound
188
+ raise NotFound.new
183
189
  when 400...500
184
190
  raise ClientError.new response.code, response.message, response: response
185
191
  when 500...600
@@ -189,15 +195,15 @@ module Deis
189
195
  end
190
196
  end
191
197
 
192
- def interpolate_path(path, body)
198
+ def interpolate_path(path, interpolations)
193
199
  %r{/:(?<key>\w+)/?} =~ path
194
200
  return path unless key
195
201
 
196
- value = body[key.to_sym]
202
+ value = interpolations[key.to_sym]
197
203
  path[':' + key] = value
198
204
 
199
205
  # this catched only one occurance of an key, so call recursively until nothing is found anymore
200
- interpolate_path path, body
206
+ interpolate_path path, interpolations
201
207
  end
202
208
  end
203
209
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deis_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1.dev6
4
+ version: 1.5.1.dev7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franz Liedke