lib/cfoundry/v2/base.rb in cfoundry-0.3.60 vs lib/cfoundry/v2/base.rb in cfoundry-0.3.61
- old
+ new
@@ -99,10 +99,35 @@
def files(guid, instance, *path)
get("v2", "apps", guid, "instances", instance, "files", *path)
end
alias :file :files
+ def stream_file(guid, instance, *path)
+ redirect =
+ request_with_options(
+ Net::HTTP::Get,
+ ["v2", "apps", guid, "instances", instance, "files", *path],
+ :return_response => true)
+
+ if loc = redirect["location"]
+ uri = URI.parse(loc + "&tail")
+
+ Net::HTTP.start(uri.host, uri.port) do |http|
+ req = Net::HTTP::Get.new(uri.request_uri)
+ req["Authorization"] = @token
+
+ http.request(req) do |response|
+ response.read_body do |chunk|
+ yield chunk
+ end
+ end
+ end
+ else
+ yield redirect.body
+ end
+ end
+
def instances(guid)
get("v2", "apps", guid, "instances", :accept => :json)
end
def crashes(guid)
@@ -161,9 +186,11 @@
when Net::HTTPBadRequest, Net::HTTPUnauthorized, Net::HTTPNotFound,
Net::HTTPNotImplemented, Net::HTTPServiceUnavailable
begin
info = parse_json(response.body)
+ return super unless info[:code]
+
cls = CFoundry::APIError.v2_classes[info[:code]]
raise (cls || CFoundry::APIError).new(info[:code], info[:description])
rescue MultiJson::DecodeError
super