def call_api(http_method, path, opts = {})
      request = build_request(http_method, path, opts)
      response = request.run

      if @config.debugging
        @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
      end

      unless response.success?
        if response.timed_out?
          fail ApiError.new('Connection timed out')
        elsif response.code == 0
          # Errors from libcurl will be made visible here
          fail ApiError.new(:code => 0,
                            :message => response.return_message)
        else
          exception_message = nil
          response_json = JSON.parse(response.body) rescue nil
          if response_json.is_a? Hash
            if response_json['errors'].is_a? Array
              response_errors = response_json['errors'].join(', ')
            elsif response_json['error']
              response_errors = response_json['error']
            end
            if response_errors
              exception_message = "#{response.status_message}: #{response_errors}"
            end
          end

          unless exception_message
            exception_message = "#{response.status_message}: [Could not parse errors from response body]"
          end

          fail ApiError.new(:code => response.code,
                            :response_headers => response.headers,
                            :response_body => response.body),
               exception_message
        end
      end

      if opts[:return_type]
        data = deserialize(response, opts[:return_type])
      else
        data = nil
      end
      return data, response.code, response.headers
    end
def call_api(http_method, path, opts = {})
      request = build_request(http_method, path, opts)
      response = request.run

      if @config.debugging
        @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
      end

      unless response.success?
        if response.timed_out?
          fail ApiError.new('Connection timed out')
        elsif response.code == 0
          # Errors from libcurl will be made visible here
          fail ApiError.new(:code => 0,
                            :message => response.return_message)
        else
          exception_message = nil
          response_json = JSON.parse(response.body) rescue nil
          if response_json.is_a? Hash
            if response_json['errors'].is_a? Array
              response_errors = response_json['errors'].join(', ')
            elsif response_json['error']
              response_errors = response_json['error']
            end
            if response_errors
              exception_message = "#{response.status_message}: #{response_errors}"
            end
          end

          unless exception_message
            exception_message = "#{response.status_message}: [Could not parse errors from response body]"
          end

          fail ApiError.new(:code => response.code,
                            :response_headers => response.headers,
                            :response_body => response.body),
               exception_message
        end
      end

      if opts[:return_type]
        data = deserialize(response, opts[:return_type])
      else
        data = nil
      end
      return data, response.code, response.headers
    end
Call an API with given options.

 @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
   the data deserialized from response body (could be nil), response status code and response headers.