Method: PulpContainerClient::ApiClient#call_api
- Defined in:
- lib/pulp_container_client/api_client.rb
#call_api(http_method, path, opts = {}) ⇒ Array<(Object, Integer, Hash)>
Call an API with given options.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pulp_container_client/api_client.rb', line 53 def call_api(http_method, path, opts = {}) stream = nil begin response = connection(opts).public_send(http_method.to_sym.downcase) do |req| request = build_request(http_method, path, req, opts) stream = download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary' end if config.debugging config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" end unless response.success? if response.status == 0 && response.respond_to?(:return_message) # Errors from libcurl will be made visible here fail ApiError.new(code: 0, message: response.) else fail ApiError.new(code: response.status, response_headers: response.headers, response_body: response.body), response.reason_phrase end end rescue Faraday::TimeoutError fail ApiError.new('Connection timed out') rescue Faraday::ConnectionFailed fail ApiError.new('Connection failed') end if opts[:return_type] == 'File' || opts[:return_type] == 'Binary' data = deserialize_file(response, stream) elsif opts[:return_type] data = deserialize(response, opts[:return_type]) else data = nil end return data, response.status, response.headers end |