class GoCardlessPro::ApiService
GoCardless API
Attributes
on_idempotency_conflict[R]
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 22 def initialize(url, token, options = {}) @url = url root_url, @path_prefix = unpack_url(url) http_adapter = options[:http_adapter] || [:net_http] connection_options = options.fetch(:connection_options, {}) @connection = Faraday.new(root_url, connection_options) do |faraday| faraday.response :raise_gocardless_errors faraday.adapter(*http_adapter) end @headers = options[:default_headers] || {} @headers['Authorization'] = "Bearer #{token}" @on_idempotency_conflict = options[:on_idempotency_conflict] || :fetch unless %i[fetch raise].include?(@on_idempotency_conflict) raise ArgumentError, 'Unknown mode for :on_idempotency_conflict' end end
Public Instance Methods
inspect()
click to toggle source
inspect the API Service
# File lib/gocardless_pro/api_service.rb, line 56 def inspect url = URI.parse(@url) url.password = 'REDACTED' unless url.password.nil? "#<GoCardlessPro::Client url=\"#{url}\">" end
Also aliased as: to_s
make_request(method, path, options = {})
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
# File lib/gocardless_pro/api_service.rb, line 48 def make_request(method, path, options = {}) raise ArgumentError, 'options must be a hash' unless options.is_a?(Hash) options[:headers] ||= {} options[:headers] = @headers.merge(options[:headers]) Request.new(@connection, method, @path_prefix + path, options).request end
Private Instance Methods
unpack_url(url)
click to toggle source
# File lib/gocardless_pro/api_service.rb, line 65 def unpack_url(url) path = URI.parse(url).path [URI.join(url).to_s, path == '/' ? '' : path] end