lib/cfoundry/v2/base.rb in cfoundry-0.3.57 vs lib/cfoundry/v2/base.rb in cfoundry-0.3.58
- old
+ new
@@ -57,11 +57,11 @@
define_method(:"create_#{obj}") do |payload|
post(payload, "v2", plural, :content => :json, :accept => :json)
end
define_method(:"delete_#{obj}") do |guid|
- delete("v2", plural, guid, nil => nil)
+ delete("v2", plural, guid)
true
end
define_method(:"update_#{obj}") do |guid, payload|
put(payload, "v2", plural, guid, :content => :json, :accept => :json)
@@ -129,11 +129,11 @@
def all_pages(paginated)
payload = paginated[:resources]
while next_page = paginated[:next_url]
- paginated = request_path(:get, next_page, nil => :json)
+ paginated = request_path(Net::HTTP::Get, next_page, :accept => :json)
payload += paginated[:resources]
end
payload
end
@@ -157,30 +157,22 @@
parse_json(response.body)
else
response.body
end
- when Net::HTTPBadRequest
- info = parse_json(response.body)
- raise CFoundry::APIError.new(info[:code], info[:description])
-
- when Net::HTTPUnauthorized, Net::HTTPForbidden
- info = parse_json(response.body)
- raise CFoundry::Denied.new(info[:code], info[:description])
-
- when Net::HTTPNotFound
- raise CFoundry::NotFound
-
- when Net::HTTPServerError
+ when Net::HTTPBadRequest, Net::HTTPUnauthorized, Net::HTTPNotFound,
+ Net::HTTPNotImplemented, Net::HTTPServiceUnavailable
begin
info = parse_json(response.body)
- raise CFoundry::APIError.new(info[:code], info[:description])
+ cls = CFoundry::APIError.v2_classes[info[:code]]
+
+ raise (cls || CFoundry::APIError).new(info[:code], info[:description])
rescue MultiJson::DecodeError
- raise CFoundry::BadResponse.new(response.code, response.body)
+ super
end
else
- raise CFoundry::BadResponse.new(response.code, response.body)
+ super
end
end
def log_line(io, data)
io.printf(