Class: AbacatePay::Clients::Client
- Inherits:
-
Object
- Object
- AbacatePay::Clients::Client
- 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.
Direct Known Subclasses
BillingClient, CheckoutClient, CouponClient, CustomerClient, PaymentLinkClient, PayoutClient, PixClient, ProductClient, StoreClient, SubscriptionClient, TransparentClient, WebhookClient
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/createafter 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
exceptionsreplaces 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
-
#auto_paging_each(**params) {|Object| ... } ⇒ void
Yields every record across every page.
-
#each_page(**params) {|AbacatePay::Collection| ... } ⇒ void
Yields every page of a list endpoint, following the cursor.
-
#initialize(uri, client = nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(uri, client = nil) ⇒ Client
Returns a new instance of Client.
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.
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.
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 |