Class: GoCardlessPro::ApiService
- Inherits:
-
Object
- Object
- GoCardlessPro::ApiService
- Defined in:
- lib/gocardless_pro/api_service.rb
Overview
GoCardless API
Instance Attribute Summary collapse
-
#on_idempotency_conflict ⇒ Object
readonly
Returns the value of attribute on_idempotency_conflict.
Instance Method Summary collapse
-
#initialize(url, token, options = {}) ⇒ ApiService
constructor
Initialize an APIService.
-
#inspect ⇒ Object
(also: #to_s)
inspect the API Service.
-
#make_request(method, path, options = {}) ⇒ Object
Make a request to the API.
Constructor Details
#initialize(url, token, options = {}) ⇒ ApiService
Initialize an APIService
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gocardless_pro/api_service.rb', line 20 def initialize(url, token, = {}) @url = url root_url, @path_prefix = unpack_url(url) http_adapter = [:http_adapter] || [:net_http] = .fetch(:connection_options, {}) @connection = Faraday.new(root_url, ) do |faraday| faraday.response :raise_gocardless_errors faraday.adapter(*http_adapter) end @headers = [:default_headers] || {} @headers['Authorization'] = "Bearer #{token}" @on_idempotency_conflict = [:on_idempotency_conflict] || :fetch return if %i[fetch raise].include?(@on_idempotency_conflict) raise ArgumentError, 'Unknown mode for :on_idempotency_conflict' end |
Instance Attribute Details
#on_idempotency_conflict ⇒ Object (readonly)
Returns the value of attribute on_idempotency_conflict.
12 13 14 |
# File 'lib/gocardless_pro/api_service.rb', line 12 def on_idempotency_conflict @on_idempotency_conflict end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
inspect the API Service
55 56 57 58 59 |
# File 'lib/gocardless_pro/api_service.rb', line 55 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
46 47 48 49 50 51 52 |
# File 'lib/gocardless_pro/api_service.rb', line 46 def make_request(method, path, = {}) raise ArgumentError, 'options must be a hash' unless .is_a?(Hash) [:headers] ||= {} [:headers] = @headers.merge([:headers]) Request.new(@connection, method, @path_prefix + path, ).request end |