class GoCardless::ApiService

GoCardless Enterprise API

Public Class Methods

new(url, token, options = {}) click to toggle source

Initialize an APIService

@param url [String] the URL to make requests to @param key [String] the API Key ID to use @param secret [String] the API key secret to use @param options [Hash] additional options to use when creating the service

# File lib/gocardless-pro/api_service.rb, line 19
def initialize(url, token, options = {})
  @url = url
  root_url, @path_prefix = unpack_url(url)
  http_adapter = options[:http_adapter] || [:net_http]
  @connection = Faraday.new(url: root_url) do |faraday|
    faraday.adapter(*http_adapter)
  end

  @headers = options[:default_headers] || {}
  @headers['Authorization'] = "Bearer #{token}"
end

Public Instance Methods

inspect() click to toggle source

inspect the API Service

# File lib/gocardless-pro/api_service.rb, line 43
def inspect
  url = URI.parse(@url)
  url.password = 'REDACTED' unless url.password.nil?
  "#<GoCardless::Client url=\"#{url}\">"
end
Also aliased as: to_s
make_request(method, path, options = {}, custom_headers = {}) click to toggle source

Make a request to the API

@param method [Symbol] the method to use to make the request @param path [String] the URL (without the base domain) to make the request to @param options [Hash] the options hash - either the query parameters for a GET, or the body if POST/PUT @param custom_headers [Hash] a hash of custom headers to use in the request

# File lib/gocardless-pro/api_service.rb, line 37
def make_request(method, path, options = {}, custom_headers = {})
  fail ArgumentError, 'options must be a hash' unless options.is_a?(Hash)
  Request.new(@connection, method, @path_prefix + path, options, @headers.merge(custom_headers)).request
end
to_s()
Alias for: inspect

Private Instance Methods

unpack_url(url) click to toggle source
# File lib/gocardless-pro/api_service.rb, line 52
def unpack_url(url)
  path = URI.parse(url).path
  [URI.join(url).to_s, path == '/' ? '' : path]
end