Class: GoCardlessPro::ApiService

Inherits:
Object
  • Object
show all
Defined in:
lib/gocardless_pro/api_service.rb

Overview

GoCardless API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, token, options = {}) ⇒ ApiService

Initialize an APIService

Parameters:

  • url (String)

    the URL to make requests to

  • key (String)

    the API Key ID to use

  • secret (String)

    the API key secret to use

  • options (Hash) (defaults to: {})

    additional options to use when creating the service



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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[: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
end

Instance Attribute Details

#on_idempotency_conflictObject (readonly)

Returns the value of attribute on_idempotency_conflict.



14
15
16
# File 'lib/gocardless_pro/api_service.rb', line 14

def on_idempotency_conflict
  @on_idempotency_conflict
end

Instance Method Details

#inspectObject Also known as: to_s

inspect the API Service



52
53
54
55
56
# File 'lib/gocardless_pro/api_service.rb', line 52

def inspect
  url = URI.parse(@url)
  url.password = 'REDACTED' unless url.password.nil?
  "#<GoCardlessPro::Client url=\"#{url}\">"
end

#make_request(method, path, options = {}) ⇒ Object

Make a request to the API

Parameters:

  • method (Symbol)

    the method to use to make the request

  • path (String)

    the URL (without the base domain) to make the request to

  • options (Hash) (defaults to: {})

    the options hash

Raises:

  • (ArgumentError)


44
45
46
47
48
49
# File 'lib/gocardless_pro/api_service.rb', line 44

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