lib/gocardless/client.rb
# Send a request to the GoCardless API servers
#
# @param [Symbol] method the HTTP method to use (e.g. +:get+, +:post+)
# @param [String] path the path fragment of the URL
# @option [Hash] opts query string parameters
Send a request to the GoCardless API servers
Send a request to the GoCardless API servers
def request(method, path, opts = {})
      raise ClientError, 'Access token missing' unless @access_token
      opts[:headers] = {} if opts[:headers].nil?
      opts[:headers]['Accept'] = 'application/json'
      opts[:headers]['Content-Type'] = 'application/json' unless method == :get
      opts[:headers]['User-Agent'] = user_agent
      opts[:body] = MultiJson.encode(opts[:data]) if !opts[:data].nil?
      path = URI.encode(path)
      @oauth_client.site = base_url
      header_keys = opts[:headers].keys.map(&:to_s)
      if header_keys.map(&:downcase).include?('authorization')
        @oauth_client.request(method, path, opts)
      else
        @access_token.send(method, path, opts)
      end
    rescue OAuth2::Error => err
      raise GoCardless::ApiError.new(err.response)
    end
def request ( method , path , opts = { } ) raise ClientError , 'Access token missing' unless @access_token opts [ :headers ] = { } if opts [ :headers ] . nil? opts [ :headers ] [ 'Accept' ] = 'application/json' opts [ :headers ] [ 'Content-Type' ] = 'application/json' unless method == :get opts [ :headers ] [ 'User-Agent' ] = user_agent opts [ :body ] = MultiJson . encode ( opts [ :data ] ) if ! opts [ :data ] . nil? path = URI . encode ( path ) @oauth_client . site = base_url header_keys = opts [ :headers ] . keys . map ( & :to_s ) if header_keys . map ( & :downcase ) . include? ( 'authorization' ) @oauth_client . request ( method , path , opts ) else @access_token . send ( method , path , opts ) end rescue OAuth2 :: Error => err raise GoCardless :: ApiError . new ( err . response ) end
Send a request to the GoCardless API servers
Send a request to the GoCardless API servers
# Reset the URL in case the environment / base URL has been changed.
method
<not_specific>
path
<not_specific>
opts
<not_specific>
<not_specific>
opts query string parameters
opts query string parameters