lib/vmc/client.rb in af-0.3.12.3 vs lib/vmc/client.rb in af-0.3.13.beta.5

- old
+ new

@@ -23,11 +23,11 @@ attr_reader :target, :host, :user, :proxy, :auth_token attr_accessor :trace # Error codes - VMC_HTTP_ERROR_CODES = [ 400, 403, 404, 500 ] + VMC_HTTP_ERROR_CODES = [ 400, 500 ] # Errors class BadTarget < RuntimeError; end class AuthError < RuntimeError; end class TargetError < RuntimeError; end @@ -61,10 +61,14 @@ def services_info check_login_status json_get(VMC::GLOBAL_SERVICES_PATH) end + def runtimes_info + json_get(VMC::GLOBAL_RUNTIMES_PATH) + end + ###################################################### # Apps ###################################################### def apps @@ -363,22 +367,26 @@ headers['Accept'] = content_type end req = { :method => method, :url => "#{@target}#{path}", - :payload => payload, :headers => headers + :payload => payload, :headers => headers, :multipart => true } status, body, response_headers = perform_http_request(req) - if VMC_HTTP_ERROR_CODES.include?(status) + if request_failed?(status) # FIXME, old cc returned 400 on not found for file access err = (status == 404 || status == 400) ? NotFound : TargetError raise err, parse_error_message(status, body) else return status, body, response_headers end rescue URI::Error, SocketError, Errno::ECONNREFUSED => e raise BadTarget, "Cannot access target (%s)" % [ e.message ] + end + + def request_failed?(status) + VMC_HTTP_ERROR_CODES.detect{|error_code| status >= error_code} end def perform_http_request(req) proxy_uri = URI.parse(req[:url]).find_proxy() RestClient.proxy = proxy_uri.to_s if proxy_uri