lib/gap_intelligence/client/requestable.rb
# Makes a request to a specified endpoint
#
# @param [Symbol] method one of :get, :post, :put, :delete
# @param [String] path URL path of request
# @param [Hash] options the options to make the request with
# @yield [req] The Faraday request
# @raise [RequestError] If raise_errors set true and request fails for any reason
Makes a request to a specified endpoint
Makes a request to a specified endpoint
def perform_request(method, path, options = {}, &block)
      record_class = options.delete(:record_class)
      raise_error = options.fetch(:raise_errors, raise_errors)
      options[:headers] = headers
      options[:raise_errors] = false
      options[:init_with_response_body] = options.fetch(:init_with_response_body, false)
      response = connection.request(method, path, options, &block)
      if response.error
        error = RequestError.new(parse_error_message(response))
        raise(error) if raise_error
        return nil
      end
      return instantiate_record(record_class, response_body: response.body) if options[:init_with_response_body]
      hash = response.parsed
      data = hash['data']
      case data
      when Array
        objects = record_class.nil? ? data : data.collect{ |object| record_class.new(object) }
        RecordSet.new(objects, meta: hash.fetch('meta', {}))
      when Hash
        instantiate_record(record_class, data)
      end
    end
def perform_request ( method , path , options = { } , & block ) record_class = options . delete ( :record_class ) raise_error = options . fetch ( :raise_errors , raise_errors ) options [ :headers ] = headers options [ :raise_errors ] = false options [ :init_with_response_body ] = options . fetch ( :init_with_response_body , false ) response = connection . request ( method , path , options , & block ) if response . error error = RequestError . new ( parse_error_message ( response ) ) raise ( error ) if raise_error return nil end return instantiate_record ( record_class , response_body : response . body ) if options [ :init_with_response_body ] hash = response . parsed data = hash [ 'data' ] case data when Array objects = record_class . nil? ? data : data . collect { | object | record_class . new ( object ) } RecordSet . new ( objects , meta : hash . fetch ( 'meta' , { } ) ) when Hash instantiate_record ( record_class , data ) end end
Makes a request to a specified endpoint
Makes a request to a specified endpoint
[RequestError] If raise_errors set true and request fails for any reason
[ RequestError ] If raise_errors set true and request fails for any reason
method
path
options
block
options the options to make the request with
options the options to make the request with
]
The Faraday request
The Faraday request