Class: AbacatePay::Clients::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/abacate_pay/clients/client.rb

Overview

Client class for interacting with the AbacatePay API.

This class handles API requests using Faraday and provides a way to manage authentication and communication with the AbacatePay service.

Constant Summary collapse

RETRIABLE_STATUSES =

Statuses worth retrying. 429 is rate limiting and 5xx are transient — AbacatePay's own reference tells integrators to back off on both.

[429, 500, 502, 503, 504].freeze
RETRIABLE_METHODS =

Only methods that are safe to repeat. POST is excluded: retrying checkouts/create after a timeout could charge a customer twice, and the API exposes no idempotency key to make that safe.

%i[get head options].freeze
RETRIABLE_EXCEPTIONS =

Passing exceptions replaces faraday-retry's defaults rather than adding to them, and Faraday::RetriableResponse is what the middleware raises internally for a retriable status. Omitting it silently disables status-code retries altogether.

[
  Faraday::RetriableResponse,
  Faraday::TimeoutError,
  Faraday::ConnectionFailed,
  Errno::ETIMEDOUT
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(uri, client = nil) ⇒ Client

Returns a new instance of Client.

Parameters:

  • uri (String)

    The specific API endpoint to interact with

  • client (Faraday::Connection, nil) (defaults to: nil)

    Optional Faraday client for custom configurations



35
36
37
# File 'lib/abacate_pay/clients/client.rb', line 35

def initialize(uri, client = nil)
  @client = client || build_client(uri)
end

Instance Method Details

#auto_paging_each(**params) {|Object| ... } ⇒ void

This method returns an undefined value.

Yields every record across every page.

Prefer this over list when the result set can exceed the 100-item page limit.

Parameters:

  • params (Hash)

    Params forwarded to each list call

Yields:

  • (Object)

    Each resource



65
66
67
68
69
# File 'lib/abacate_pay/clients/client.rb', line 65

def auto_paging_each(**params, &)
  return to_enum(:auto_paging_each, **params) unless block_given?

  each_page(**params) { |page| page.each(&) }
end

#each_page(**params) {|AbacatePay::Collection| ... } ⇒ void

This method returns an undefined value.

Yields every page of a list endpoint, following the cursor.

Parameters:

  • params (Hash)

    Params forwarded to each list call

Yields:



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/abacate_pay/clients/client.rb', line 44

def each_page(**params)
  return to_enum(:each_page, **params) unless block_given?

  cursor = params.delete(:after)
  loop do
    page = list(**params, **(cursor ? { after: cursor } : {}))
    yield page
    break unless page.respond_to?(:has_more?) && page.has_more? && page.next_cursor

    cursor = page.next_cursor
  end
end