Module: NakoPay
- Defined in:
- lib/nakopay/client.rb,
lib/nakopay/errors.rb,
lib/nakopay/version.rb,
lib/nakopay/webhook.rb,
lib/nakopay/resource.rb,
lib/nakopay/resources.rb
Defined Under Namespace
Modules: Credit, Customer, Event, Invoice, Key, Logs, PaymentLink, Rate, Refund, Sandbox, Subscription, SubscriptionPlan, Webhook, WebhookEndpoint Classes: APIError, AuthenticationError, Client, ConnectionError, Error, IdempotencyError, RateLimitError, Resource, SignatureVerificationError
Constant Summary collapse
- VERSION =
"1.0.0"
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.api_version ⇒ Object
Returns the value of attribute api_version.
-
.base_url ⇒ Object
Returns the value of attribute base_url.
-
.max_retries ⇒ Object
Returns the value of attribute max_retries.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
-
.build_api_error(payload, status_code:) ⇒ Object
Maps API error envelope to specialized subclass.
-
.client ⇒ Object
Default singleton client.
-
.reset_client! ⇒ Object
Reset the singleton (used in tests).
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
155 156 157 |
# File 'lib/nakopay/client.rb', line 155 def api_key @api_key end |
.api_version ⇒ Object
Returns the value of attribute api_version.
155 156 157 |
# File 'lib/nakopay/client.rb', line 155 def api_version @api_version end |
.base_url ⇒ Object
Returns the value of attribute base_url.
155 156 157 |
# File 'lib/nakopay/client.rb', line 155 def base_url @base_url end |
.max_retries ⇒ Object
Returns the value of attribute max_retries.
155 156 157 |
# File 'lib/nakopay/client.rb', line 155 def max_retries @max_retries end |
.timeout ⇒ Object
Returns the value of attribute timeout.
155 156 157 |
# File 'lib/nakopay/client.rb', line 155 def timeout @timeout end |
Class Method Details
.build_api_error(payload, status_code:) ⇒ Object
Maps API error envelope to specialized subclass.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/nakopay/errors.rb', line 66 def self.build_api_error(payload, status_code:) code = payload["code"] = payload["message"] common = { code: code, type: payload["type"], param: payload["param"], doc_url: payload["doc_url"], request_id: payload["request_id"], status_code: status_code, } if status_code == 401 || code == "authentication_error" AuthenticationError.new(message: || "Invalid API key", **common) elsif status_code == 429 || code == "rate_limit_error" RateLimitError.new(message: || "Rate limit exceeded", **common) elsif code == "idempotency_error" IdempotencyError.new(message: || "Idempotency conflict", **common) else APIError.new(message: || "Unknown error", **common) end end |
.client ⇒ Object
Default singleton client. Resources call into this; tests may swap it.
158 159 160 |
# File 'lib/nakopay/client.rb', line 158 def client @client ||= Client.new end |
.reset_client! ⇒ Object
Reset the singleton (used in tests).
163 164 165 |
# File 'lib/nakopay/client.rb', line 163 def reset_client! @client = nil end |