cfoundry 0.3.46 → 0.3.47

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.
@@ -1,4 +1,5 @@
1
- require "restclient"
1
+ require "net/https"
2
+ require "net/http/post/multipart"
2
3
  require "multi_json"
3
4
  require "fileutils"
4
5
 
@@ -16,22 +17,9 @@ module CFoundry
16
17
  @log = false
17
18
  end
18
19
 
19
- def request_path(method, path, types = {}, options = {})
20
+ def request_path(method, path, options = {})
20
21
  path = url(path) if path.is_a?(Array)
21
22
 
22
- unless types.empty?
23
- if params = types.delete(:params)
24
- options[:params] = params
25
- end
26
-
27
- if types.size > 1
28
- raise "request types must contain only one Content-Type => Accept"
29
- end
30
-
31
- options[:type] = types.keys.first
32
- options[:accept] = types.values.first
33
- end
34
-
35
23
  request(method, path, options)
36
24
  end
37
25
 
@@ -60,10 +48,20 @@ module CFoundry
60
48
  end
61
49
 
62
50
  def request(method, path, options = {})
51
+ request_uri(URI.parse(@target + path), method, options)
52
+ end
53
+
54
+ def request_uri(uri, method, options = {})
55
+ uri = URI.parse(@target + uri.to_s) unless uri.host
56
+
57
+ # keep original options in case there's a redirect to follow
58
+ original_options = options.dup
59
+
63
60
  accept = options.delete(:accept)
64
- type = options.delete(:type)
61
+ content = options.delete(:content)
65
62
  payload = options.delete(:payload)
66
63
  params = options.delete(:params)
64
+ return_headers = options.delete(:return_headers)
67
65
 
68
66
  headers = {}
69
67
  headers["Authorization"] = @token if @token
@@ -73,12 +71,12 @@ module CFoundry
73
71
  headers["Accept"] = accept_type
74
72
  end
75
73
 
76
- if content_type = mimetype(type)
74
+ if content_type = mimetype(content)
77
75
  headers["Content-Type"] = content_type
78
76
  end
79
77
 
80
78
  unless payload.is_a?(String)
81
- case type
79
+ case content
82
80
  when :json
83
81
  payload = MultiJson.dump(payload)
84
82
  when :form
@@ -86,35 +84,62 @@ module CFoundry
86
84
  end
87
85
  end
88
86
 
89
- headers["Content-Length"] = payload ? payload.size : 0
87
+ if payload.is_a?(String)
88
+ headers["Content-Length"] = payload.size
89
+ elsif !payload
90
+ headers["Content-Length"] = 0
91
+ end
90
92
 
91
93
  headers.merge!(options[:headers]) if options[:headers]
92
94
 
93
95
  if params
94
- uri = URI.parse(path)
95
- path += (uri.query ? "&" : "?") + encode_params(params)
96
+ if uri.query
97
+ uri.query += "&" + encode_params(params)
98
+ else
99
+ uri.query = encode_params(params)
100
+ end
101
+ end
102
+
103
+ if payload && payload.is_a?(Hash)
104
+ multipart = method.const_get(:Multipart)
105
+ request = multipart.new(uri.request_uri, payload)
106
+ else
107
+ request = method.new(uri.request_uri)
108
+ request.body = payload if payload
96
109
  end
97
110
 
98
- req = options.dup
99
- req[:method] = method
100
- req[:url] = @target + path
101
- req[:headers] = headers
102
- req[:payload] = payload
111
+ request["Authorization"] = @token if @token
112
+ request["Proxy-User"] = @proxy if @proxy
103
113
 
104
- json = accept == :json
114
+ headers.each do |k, v|
115
+ request[k] = v
116
+ end
105
117
 
106
- before = Time.now
118
+ # TODO: test http proxies
119
+ http = Net::HTTP.new(uri.host, uri.port)
120
+
121
+ if uri.is_a?(URI::HTTPS)
122
+ http.use_ssl = true
123
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
124
+ end
107
125
 
108
- RestClient::Request.execute(req) do |response, request, result, &block|
126
+ print_request(request) if @trace
127
+
128
+ before = Time.now
129
+ http.start do
130
+ response = http.request(request)
109
131
  time = Time.now - before
110
132
 
111
- print_trace(request, response, caller) if @trace
133
+ print_response(response) if @trace
134
+ print_backtrace(caller) if @trace
135
+
112
136
  log_request(time, request, response)
113
137
 
114
- if [:get, :head].include?(method) && \
115
- [301, 302, 307].include?(response.code) && \
116
- accept != :headers
117
- response.follow_redirection(request, result, &block)
138
+ if return_headers
139
+ sane_headers(response)
140
+ elsif [Net::HTTP::Get, Net::HTTP::Head].include?(method) && \
141
+ response.is_a?(Net::HTTPRedirection)
142
+ request_uri(URI.parse(response["location"]), method, original_options)
118
143
  else
119
144
  handle_response(response, accept)
120
145
  end
@@ -123,10 +148,10 @@ module CFoundry
123
148
  raise TargetRefused, e.message
124
149
  end
125
150
 
126
- def mimetype(type)
127
- case type
151
+ def mimetype(content)
152
+ case content
128
153
  when String
129
- type
154
+ content
130
155
  when :json
131
156
  "application/json"
132
157
  when :form
@@ -134,10 +159,8 @@ module CFoundry
134
159
  when nil
135
160
  nil
136
161
  # return request headers (not really Accept)
137
- when :headers
138
- nil
139
162
  else
140
- raise "unknown mimetype #{type.inspect}"
163
+ raise "unknown mimetype #{content.inspect}"
141
164
  end
142
165
  end
143
166
 
@@ -150,28 +173,26 @@ module CFoundry
150
173
  end.join("&")
151
174
  end
152
175
 
153
- def request_with_types(method, path, options = {})
154
- if path.last.is_a?(Hash)
155
- types = path.pop
156
- end
176
+ def request_with_options(method, path, options = {})
177
+ options.merge!(path.pop) if path.last.is_a?(Hash)
157
178
 
158
- request_path(method, url(path), types || {}, options)
179
+ request_path(method, url(path), options)
159
180
  end
160
181
 
161
182
  def get(*path)
162
- request_with_types(:get, path)
183
+ request_with_options(Net::HTTP::Get, path)
163
184
  end
164
185
 
165
186
  def delete(*path)
166
- request_with_types(:delete, path)
187
+ request_with_options(Net::HTTP::Delete, path)
167
188
  end
168
189
 
169
190
  def post(payload, *path)
170
- request_with_types(:post, path, :payload => payload)
191
+ request_with_options(Net::HTTP::Post, path, :payload => payload)
171
192
  end
172
193
 
173
194
  def put(payload, *path)
174
- request_with_types(:put, path, :payload => payload)
195
+ request_with_options(Net::HTTP::Put, path, :payload => payload)
175
196
  end
176
197
 
177
198
  def url(segments)
@@ -188,12 +209,12 @@ module CFoundry
188
209
  { :time => time,
189
210
  :request => {
190
211
  :method => request.method,
191
- :url => request.url,
192
- :headers => request.headers
212
+ :url => request.path,
213
+ :headers => sane_headers(request)
193
214
  },
194
215
  :response => {
195
216
  :code => response.code,
196
- :headers => response.headers
217
+ :headers => sane_headers(response)
197
218
  }
198
219
  }
199
220
  end
@@ -243,20 +264,22 @@ module CFoundry
243
264
  end
244
265
  end
245
266
 
246
- def print_trace(request, response, locs)
267
+ def print_request(request)
247
268
  $stderr.puts ">>>"
248
- $stderr.puts "PROXY: #{RestClient.proxy}" if RestClient.proxy
249
- $stderr.puts "REQUEST: #{request.method} #{request.url}"
250
- $stderr.puts "RESPONSE_HEADERS:"
251
- response.headers.each do |key, value|
252
- $stderr.puts " #{key} : #{value}"
253
- end
269
+ $stderr.puts "REQUEST: #{request.method} #{request.path}"
254
270
  $stderr.puts "REQUEST_HEADERS:"
255
- request.headers.each do |key, value|
256
- $stderr.puts " #{key} : #{value}"
271
+ request.each_header do |key, value|
272
+ $stderr.puts " #{key} : #{value}"
257
273
  end
258
- $stderr.puts "REQUEST_BODY: #{request.payload}" if request.payload
274
+ $stderr.puts "REQUEST_BODY: #{request.body}" if request.body
275
+ end
276
+
277
+ def print_response(response)
259
278
  $stderr.puts "RESPONSE: [#{response.code}]"
279
+ $stderr.puts "RESPONSE_HEADERS:"
280
+ response.each_header do |key, value|
281
+ $stderr.puts " #{key} : #{value}"
282
+ end
260
283
  begin
261
284
  parsed_body = MultiJson.load(response.body)
262
285
  $stderr.puts MultiJson.dump(parsed_body, :pretty => true)
@@ -264,7 +287,9 @@ module CFoundry
264
287
  $stderr.puts "#{response.body}"
265
288
  end
266
289
  $stderr.puts "<<<"
290
+ end
267
291
 
292
+ def print_backtrace(locs)
268
293
  return unless @backtrace
269
294
 
270
295
  interesting_locs = locs.drop_while { |loc|
@@ -285,30 +310,34 @@ module CFoundry
285
310
  end
286
311
 
287
312
  def handle_response(response, accept)
288
- json = accept == :json
289
-
290
- case response.code
291
- when 200, 201, 204, 301, 302, 307
292
- if accept == :headers
293
- return response.headers
294
- end
295
-
296
- if json
297
- if response.code == 204
313
+ case response
314
+ when Net::HTTPSuccess, Net::HTTPRedirection
315
+ if accept == :json
316
+ if response.is_a?(Net::HTTPNoContent)
298
317
  raise "Expected JSON response, got 204 No Content"
299
318
  end
300
319
 
301
- parse_json(response)
320
+ parse_json(response.body)
302
321
  else
303
- response
322
+ response.body
304
323
  end
305
324
 
306
- when 404
325
+ when Net::HTTPNotFound
307
326
  raise CFoundry::NotFound
308
327
 
309
328
  else
310
- raise CFoundry::BadResponse.new(response.code, response)
329
+ raise CFoundry::BadResponse.new(response.code, response.body)
311
330
  end
312
331
  end
332
+
333
+ def sane_headers(obj)
334
+ hds = {}
335
+
336
+ obj.each_header do |k, v|
337
+ hds[k] = v
338
+ end
339
+
340
+ hds
341
+ end
313
342
  end
314
343
  end
@@ -19,7 +19,7 @@ module CFoundry
19
19
  end
20
20
 
21
21
  def info
22
- get("info", nil => :json)
22
+ get("info", :accept => :json)
23
23
  end
24
24
  end
25
25
  end
@@ -13,7 +13,7 @@ module CFoundry
13
13
  end
14
14
 
15
15
  def prompts
16
- get("login", nil => :json)[:prompts]
16
+ get("login", :accept => :json)[:prompts]
17
17
  end
18
18
 
19
19
  def authorize(credentials)
@@ -27,12 +27,14 @@ module CFoundry
27
27
  post(
28
28
  { :credentials => credentials },
29
29
  "oauth", "authorize",
30
- :form => :headers,
31
- :params => query)[:location])
30
+ :return_headers => true,
31
+ :content => :form,
32
+ :accept => :json,
33
+ :params => query)["location"])
32
34
  end
33
35
 
34
36
  def users
35
- get("Users", nil => :json)
37
+ get("Users", :accept => :json)
36
38
  end
37
39
 
38
40
  def change_password(guid, new, old)
@@ -42,54 +44,44 @@ module CFoundry
42
44
  :oldPassword => old
43
45
  },
44
46
  "User", guid, "password",
45
- :json => nil)
47
+ :content => :json)
46
48
  end
47
49
 
48
50
  private
49
51
 
50
52
  def handle_response(response, accept)
51
- json = accept == :json
52
-
53
- case response.code
54
- when 200, 204, 302
55
- if accept == :headers
56
- return response.headers
57
- end
58
-
59
- if json
60
- if response.code == 204
53
+ case response
54
+ when Net::HTTPSuccess, Net::HTTPRedirection
55
+ if accept == :json
56
+ if response.is_a?(Net::HTTPNoContent)
61
57
  raise "Expected JSON response, got 204 No Content"
62
58
  end
63
59
 
64
- parse_json(response)
60
+ parse_json(response.body)
65
61
  else
66
- response
62
+ response.body
67
63
  end
68
64
 
69
- when 400, 403
70
- info = parse_json(response)
71
- raise Denied.new(403, info[:error_description])
72
-
73
- when 401
74
- info = parse_json(response)
75
- raise Denied.new(401, info[:error_description])
65
+ when Net::HTTPBadRequest, Net::HTTPUnauthorized, Net::HTTPForbidden
66
+ info = parse_json(response.body)
67
+ raise Denied.new(response.code, info[:error_description])
76
68
 
77
- when 404
69
+ when Net::HTTPNotFound
78
70
  raise NotFound
79
71
 
80
- when 409
81
- info = parse_json(response)
82
- raise CFoundry::Denied.new(409, info[:message])
72
+ when Net::HTTPConflict
73
+ info = parse_json(response.body)
74
+ raise CFoundry::Denied.new(response.code, info[:message])
83
75
 
84
- when 411, 500, 504
76
+ when Net::HTTPServerError
85
77
  begin
86
- raise_error(parse_json(response))
78
+ raise_error(parse_json(response.body))
87
79
  rescue MultiJson::DecodeError
88
- raise BadResponse.new(response.code, response)
80
+ raise BadResponse.new(response.code, response.body)
89
81
  end
90
82
 
91
83
  else
92
- raise BadResponse.new(response.code, response)
84
+ raise BadResponse.new(response.code, response.body)
93
85
  end
94
86
  end
95
87
 
@@ -34,62 +34,63 @@ module CFoundry::V1
34
34
 
35
35
  # Cloud metadata
36
36
  def info
37
- get("info", nil => :json)
37
+ get("info", :accept => :json)
38
38
  end
39
39
 
40
40
  def system_services
41
- get("info", "services", nil => :json)
41
+ get("info", "services", :accept => :json)
42
42
  end
43
43
 
44
44
  def system_runtimes
45
- get("info", "runtimes", nil => :json)
45
+ get("info", "runtimes", :accept => :json)
46
46
  end
47
47
 
48
48
  # Users
49
49
  def users
50
- get("users", nil => :json)
50
+ get("users", :accept => :json)
51
51
  end
52
52
 
53
53
  def create_user(payload)
54
- post(payload, "users", :json => nil)
54
+ post(payload, "users", :content => :json)
55
55
  end
56
56
 
57
57
  def user(email)
58
- get("users", email, nil => :json)
58
+ get("users", email, :accept => :json)
59
59
  end
60
60
 
61
61
  def delete_user(email)
62
- delete("users", email, nil => :json)
62
+ delete("users", email, :accept => :json)
63
63
  true
64
64
  end
65
65
 
66
66
  def update_user(email, payload)
67
- put(payload, "users", email, :json => nil)
67
+ put(payload, "users", email, :content => :json)
68
68
  end
69
69
 
70
70
  def create_token(payload, email)
71
- post(payload, "users", email, "tokens", :json => :json)
71
+ post(payload, "users", email, "tokens",
72
+ :content => :json, :accept => :json)
72
73
  end
73
74
 
74
75
  # Applications
75
76
  def apps
76
- get("apps", nil => :json)
77
+ get("apps", :accept => :json)
77
78
  end
78
79
 
79
80
  def create_app(payload)
80
- post(payload, "apps", :json => :json)
81
+ post(payload, "apps", :content => :json, :accept => :json)
81
82
  end
82
83
 
83
84
  def app(name)
84
- get("apps", name, nil => :json)
85
+ get("apps", name, :accept => :json)
85
86
  end
86
87
 
87
88
  def instances(name)
88
- get("apps", name, "instances", nil => :json)[:instances]
89
+ get("apps", name, "instances", :accept => :json)[:instances]
89
90
  end
90
91
 
91
92
  def crashes(name)
92
- get("apps", name, "crashes", nil => :json)[:crashes]
93
+ get("apps", name, "crashes", :accept => :json)[:crashes]
93
94
  end
94
95
 
95
96
  def files(name, instance, *path)
@@ -98,7 +99,7 @@ module CFoundry::V1
98
99
  alias :file :files
99
100
 
100
101
  def update_app(name, payload)
101
- put(payload, "apps", name, :json => nil)
102
+ put(payload, "apps", name, :content => :json)
102
103
  end
103
104
 
104
105
  def delete_app(name)
@@ -107,86 +108,81 @@ module CFoundry::V1
107
108
  end
108
109
 
109
110
  def stats(name)
110
- get("apps", name, "stats", nil => :json)
111
+ get("apps", name, "stats", :accept => :json)
111
112
  end
112
113
 
113
114
  def check_resources(fingerprints)
114
- post(fingerprints, "resources", :json => :json)
115
+ post(fingerprints, "resources", :content => :json, :accept => :json)
115
116
  end
116
117
 
117
118
  def upload_app(name, zipfile, resources = [])
118
119
  payload = {
119
120
  :_method => "put",
120
121
  :resources => MultiJson.dump(resources),
121
- :multipart => true,
122
122
  :application =>
123
- if zipfile.is_a? File
124
- zipfile
125
- elsif zipfile.is_a? String
126
- File.new(zipfile, "rb")
127
- end
123
+ UploadIO.new(
124
+ if zipfile.is_a? File
125
+ zipfile
126
+ elsif zipfile.is_a? String
127
+ File.new(zipfile, "rb")
128
+ end,
129
+ "application/zip")
128
130
  }
129
131
 
130
132
  post(payload, "apps", name, "application")
131
- rescue RestClient::ServerBrokeConnection
133
+ rescue EOFError
132
134
  retry
133
135
  end
134
136
 
135
137
  # Services
136
138
  def services
137
- get("services", nil => :json)
139
+ get("services", :accept => :json)
138
140
  end
139
141
 
140
142
  def create_service(manifest)
141
- post(manifest, "services", :json => :json)
143
+ post(manifest, "services", :content => :json, :accept => :json)
142
144
  end
143
145
 
144
146
  def service(name)
145
- get("services", name, nil => :json)
147
+ get("services", name, :accept => :json)
146
148
  end
147
149
 
148
150
  def delete_service(name)
149
- delete("services", name, nil => :json)
151
+ delete("services", name, :accept => :json)
150
152
  true
151
153
  end
152
154
 
153
155
  private
154
156
 
155
157
  def handle_response(response, accept)
156
- json = accept == :json
157
-
158
- case response.code
159
- when 200, 201, 204, 301, 302, 307
160
- if accept == :headers
161
- return response.headers
162
- end
163
-
164
- if json
165
- if response.code == 204
158
+ case response
159
+ when Net::HTTPSuccess, Net::HTTPRedirection
160
+ if accept == :json
161
+ if response.is_a?(Net::HTTPNoContent)
166
162
  raise "Expected JSON response, got 204 No Content"
167
163
  end
168
164
 
169
- parse_json(response)
165
+ parse_json(response.body)
170
166
  else
171
- response
167
+ response.body
172
168
  end
173
169
 
174
- when 400, 403
175
- info = parse_json(response)
170
+ when Net::HTTPBadRequest, Net::HTTPForbidden
171
+ info = parse_json(response.body)
176
172
  raise CFoundry::Denied.new(403, info[:description])
177
173
 
178
- when 404
174
+ when Net::HTTPNotFound
179
175
  raise CFoundry::NotFound
180
176
 
181
- when 411, 500, 504
177
+ when Net::HTTPServerError
182
178
  begin
183
- raise_error(parse_json(response))
179
+ raise_error(parse_json(response.body))
184
180
  rescue MultiJson::DecodeError
185
- raise CFoundry::BadResponse.new(response.code, response)
181
+ raise CFoundry::BadResponse.new(response.code, response.body)
186
182
  end
187
183
 
188
184
  else
189
- raise CFoundry::BadResponse.new(response.code, response)
185
+ raise CFoundry::BadResponse.new(response.code, response.body)
190
186
  end
191
187
  end
192
188
 
@@ -35,7 +35,7 @@ module CFoundry::V2
35
35
 
36
36
  # Cloud metadata
37
37
  def info
38
- get("info", nil => :json)
38
+ get("info", :accept => :json)
39
39
  end
40
40
 
41
41
 
@@ -51,11 +51,11 @@ module CFoundry::V2
51
51
 
52
52
  params = { :"inline-relations-depth" => depth }
53
53
 
54
- get("v2", plural, guid, nil => :json, :params => params)
54
+ get("v2", plural, guid, :accept => :json, :params => params)
55
55
  end
56
56
 
57
57
  define_method(:"create_#{obj}") do |payload|
58
- post(payload, "v2", plural, :json => :json)
58
+ post(payload, "v2", plural, :content => :json, :accept => :json)
59
59
  end
60
60
 
61
61
  define_method(:"delete_#{obj}") do |guid|
@@ -64,34 +64,38 @@ module CFoundry::V2
64
64
  end
65
65
 
66
66
  define_method(:"update_#{obj}") do |guid, payload|
67
- put(payload, "v2", plural, guid, :json => :json)
67
+ put(payload, "v2", plural, guid, :content => :json, :accept => :json)
68
68
  end
69
69
 
70
70
  define_method(plural) do |*args|
71
+ params = params_from(args)
72
+
71
73
  all_pages(
72
- get("v2", plural, nil => :json, :params => params_from(args)))
74
+ params,
75
+ get("v2", plural, :accept => :json, :params => params))
73
76
  end
74
-
75
77
  end
76
78
 
77
79
  def resource_match(fingerprints)
78
- put(fingerprints, "v2", "resource_match", :json => :json)
80
+ put(fingerprints, "v2", "resource_match",
81
+ :content => :json, :accept => :json)
79
82
  end
80
83
 
81
84
  def upload_app(guid, zipfile, resources = [])
82
85
  payload = {
83
86
  :resources => MultiJson.dump(resources),
84
- :multipart => true,
85
87
  :application =>
86
- if zipfile.is_a? File
87
- zipfile
88
- elsif zipfile.is_a? String
89
- File.new(zipfile, "rb")
90
- end
88
+ UploadIO.new(
89
+ if zipfile.is_a? File
90
+ zipfile
91
+ elsif zipfile.is_a? String
92
+ File.new(zipfile, "rb")
93
+ end,
94
+ "application/zip")
91
95
  }
92
96
 
93
97
  put(payload, "v2", "apps", guid, "bits")
94
- rescue RestClient::ServerBrokeConnection
98
+ rescue EOFError
95
99
  retry
96
100
  end
97
101
 
@@ -101,15 +105,15 @@ module CFoundry::V2
101
105
  alias :file :files
102
106
 
103
107
  def instances(guid)
104
- get("v2", "apps", guid, "instances", nil => :json)
108
+ get("v2", "apps", guid, "instances", :accept => :json)
105
109
  end
106
110
 
107
111
  def crashes(guid)
108
- get("v2", "apps", guid, "crashes", nil => :json)
112
+ get("v2", "apps", guid, "crashes", :accept => :json)
109
113
  end
110
114
 
111
115
  def stats(guid)
112
- get("v2", "apps", guid, "stats", nil => :json)
116
+ get("v2", "apps", guid, "stats", :accept => :json)
113
117
  end
114
118
 
115
119
 
@@ -126,11 +130,13 @@ module CFoundry::V2
126
130
  params
127
131
  end
128
132
 
129
- def all_pages(paginated)
133
+ def all_pages(params, paginated)
130
134
  payload = paginated[:resources]
131
135
 
132
136
  while next_page = paginated[:next_url]
133
- paginated = request_path(:get, next_page, nil => :json)
137
+ paginated = request_path(
138
+ Net::HTTP::Get, next_page, :accept => :json, :params => params)
139
+
134
140
  payload += paginated[:resources]
135
141
  end
136
142
 
@@ -140,45 +146,43 @@ module CFoundry::V2
140
146
  private
141
147
 
142
148
  def handle_response(response, accept)
143
- json = accept == :json
144
-
145
- case response.code
146
- when 200, 201, 204, 301, 302, 307
149
+ case response
150
+ when Net::HTTPSuccess, Net::HTTPRedirection
147
151
  if accept == :headers
148
- return response.headers
152
+ return sane_headers(response)
149
153
  end
150
154
 
151
- if json
152
- if response.code == 204
155
+ if accept == :json
156
+ if response.is_a?(Net::HTTPNoContent)
153
157
  raise "Expected JSON response, got 204 No Content"
154
158
  end
155
159
 
156
- parse_json(response)
160
+ parse_json(response.body)
157
161
  else
158
- response
162
+ response.body
159
163
  end
160
164
 
161
- when 400
162
- info = parse_json(response)
165
+ when Net::HTTPBadRequest
166
+ info = parse_json(response.body)
163
167
  raise CFoundry::APIError.new(info[:code], info[:description])
164
168
 
165
- when 401, 403
166
- info = parse_json(response)
169
+ when Net::HTTPUnauthorized, Net::HTTPForbidden
170
+ info = parse_json(response.body)
167
171
  raise CFoundry::Denied.new(info[:code], info[:description])
168
172
 
169
- when 404
173
+ when Net::HTTPNotFound
170
174
  raise CFoundry::NotFound
171
175
 
172
- when 411, 500, 504
176
+ when Net::HTTPServerError
173
177
  begin
174
- info = parse_json(response)
178
+ info = parse_json(response.body)
175
179
  raise CFoundry::APIError.new(info[:code], info[:description])
176
180
  rescue MultiJson::DecodeError
177
- raise CFoundry::BadResponse.new(response.code, response)
181
+ raise CFoundry::BadResponse.new(response.code, response.body)
178
182
  end
179
183
 
180
184
  else
181
- raise CFoundry::BadResponse.new(response.code, response)
185
+ raise CFoundry::BadResponse.new(response.code, response.body)
182
186
  end
183
187
  end
184
188
 
@@ -212,19 +212,22 @@ module CFoundry::V2
212
212
  send(
213
213
  :"make_#{singular}",
214
214
  @base.request_path(
215
- :get,
215
+ Net::HTTP::Get,
216
216
  path,
217
- nil => :json,
217
+ :accept => :json,
218
218
  :params => @base.params_from(args)))
219
219
  end
220
220
 
221
221
  define_method(:"#{plural}_from") do |path, *args|
222
+ params = @base.params_from(args)
223
+
222
224
  objs = @base.all_pages(
225
+ params,
223
226
  @base.request_path(
224
- :get,
227
+ Net::HTTP::Get,
225
228
  path,
226
- nil => :json,
227
- :params => @base.params_from(args)))
229
+ :accept => :json,
230
+ :params => params))
228
231
 
229
232
  objs.collect do |json|
230
233
  send(:"make_#{singular}", json)
@@ -145,9 +145,9 @@ module CFoundry::V2
145
145
  Model.validate_type(x, CFoundry::V2.const_get(kls))
146
146
 
147
147
  @client.base.request_path(
148
- :put,
148
+ Net::HTTP::Put,
149
149
  ["v2", "#{object_name}s", @guid, plural, x.guid],
150
- nil => :json)
150
+ :accept => :json)
151
151
  }
152
152
 
153
153
  define_method(:"remove_#{singular}") { |x|
@@ -155,9 +155,9 @@ module CFoundry::V2
155
155
  Model.validate_type(x, CFoundry::V2.const_get(kls))
156
156
 
157
157
  @client.base.request_path(
158
- :delete,
158
+ Net::HTTP::Delete,
159
159
  ["v2", "#{object_name}s", @guid, plural, x.guid],
160
- nil => :json)
160
+ :accept => :json)
161
161
  }
162
162
 
163
163
  define_method(:"#{plural}=") { |xs|
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.46"
3
+ VERSION = "0.3.47"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 79
4
+ hash: 77
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 46
10
- version: 0.3.46
9
+ - 47
10
+ version: 0.3.47
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,22 +15,22 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-18 00:00:00 Z
18
+ date: 2012-10-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rest-client
21
+ name: multipart-post
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 13
28
+ hash: 19
29
29
  segments:
30
30
  - 1
31
- - 6
32
31
  - 1
33
- version: 1.6.1
32
+ - 0
33
+ version: 1.1.0
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency