Class: Nombaone::Client
- Inherits:
-
Object
- Object
- Nombaone::Client
- Defined in:
- lib/nombaone/client.rb,
sig/nombaone/client.rbs
Overview
The NombaOne API client. Construct one with your secret key; it derives the host from the key's prefix and exposes every resource as a namespace.
Constant Summary collapse
- BASE_URLS =
Default host per environment. Overridable with the
base_url:option. { "sandbox" => "https://sandbox.api.nombaone.xyz", "live" => "https://api.nombaone.xyz", }.freeze
- DEFAULT_TIMEOUT =
Per-attempt request timeout, in seconds.
30- DEFAULT_MAX_RETRIES =
Automatic retries (3 attempts total). Retried POSTs reuse one idempotency key.
2
Instance Attribute Summary collapse
-
#base_url ⇒ String
readonly
The API origin in use (no
/v1). -
#mode ⇒ String
readonly
The environment this client talks to ("sandbox"/"live"), derived from the key prefix.
Instance Method Summary collapse
-
#coupons ⇒ Resources::Coupons
Reusable discount rules.
-
#customers ⇒ Resources::Customers
The people and businesses you bill.
-
#events ⇒ Resources::Events
The domain-event log — your reconciliation backstop.
-
#initialize(api_key = nil, base_url: nil, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, http: nil, default_headers: nil, sleeper: nil) ⇒ Client
constructor
A new instance of Client.
-
#invoices ⇒ Resources::Invoices
What billing cycles produced (read + void).
-
#mandates ⇒ Resources::Mandates
Direct-debit mandates (async NIBSS consent).
-
#metrics ⇒ Resources::Metrics
Billing KPIs computed from the ledger.
-
#organization ⇒ Resources::Organization
Org settings + billing/dunning policy.
-
#payment_methods ⇒ Resources::PaymentMethods
Cards, mandates, virtual accounts.
-
#plans ⇒ Resources::Plans
Your catalog (prices nest under
plans.prices). -
#prices ⇒ Resources::Prices
Immutable amounts and cadences.
-
#request(method:, path:, query: nil, body: nil, options: nil) ⇒ Object
private
Execute a single-object request and return the wrapped NombaObject.
-
#request_page(method:, path:, query: nil, options: nil) ⇒ Object
private
Execute a list request and return a Page that auto-paginates.
-
#sandbox ⇒ Resources::Sandbox
Sandbox-only simulation instruments.
-
#settlements ⇒ Resources::Settlements
Settlements, refunds, payouts, escrow.
-
#subscriptions ⇒ Resources::Subscriptions
The core billing object.
-
#webhook_endpoints ⇒ Resources::WebhookEndpoints
Webhook endpoint management (REST).
-
#webhooks ⇒ Nombaone::Webhooks
A Webhooks helper bound to this client.
Constructor Details
#initialize(api_key = nil, base_url: nil, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, http: nil, default_headers: nil, sleeper: nil) ⇒ Client
Returns a new instance of Client.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/nombaone/client.rb', line 50 def initialize(api_key = nil, base_url: nil, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, http: nil, default_headers: nil, sleeper: nil) resolved_key = api_key || ENV.fetch("NOMBAONE_API_KEY", nil) if resolved_key.nil? || resolved_key.empty? raise Error, "Missing API key — set the NOMBAONE_API_KEY environment variable, or pass one: " \ 'Nombaone.new("nbo_sandbox_…"). Create keys in the dashboard under API keys.' end derived = derive_mode(resolved_key) if derived.nil? && base_url.nil? raise Error, 'Unrecognized API key format — expected a key starting with "nbo_sandbox_" or ' \ '"nbo_live_". Copy the key exactly as shown in the dashboard, or pass an explicit ' \ "base_url: if you are targeting a custom host." end @mode = derived || "sandbox" @base_url = (base_url || BASE_URLS.fetch(@mode)).sub(%r{/+\z}, "") @http = Internal::HTTPClient.new( api_key: resolved_key, base_url: @base_url, timeout: timeout, max_retries: max_retries, connection: http || Internal::NetHTTPConnection.new, default_headers: default_headers, sleeper: sleeper, ) end |
Instance Attribute Details
#base_url ⇒ String (readonly)
Returns the API origin in use (no /v1).
34 35 36 |
# File 'lib/nombaone/client.rb', line 34 def base_url @base_url end |
#mode ⇒ String (readonly)
Returns the environment this client talks to ("sandbox"/"live"), derived from the key prefix.
32 33 34 |
# File 'lib/nombaone/client.rb', line 32 def mode @mode end |
Instance Method Details
#coupons ⇒ Resources::Coupons
Returns reusable discount rules.
91 92 |
# File 'lib/nombaone/client.rb', line 91 def coupons = @coupons ||= Resources::Coupons.new(self) # @return [Resources::PaymentMethods] cards, mandates, virtual accounts. |
#customers ⇒ Resources::Customers
Returns the people and businesses you bill.
81 82 |
# File 'lib/nombaone/client.rb', line 81 def customers = @customers ||= Resources::Customers.new(self) # @return [Resources::Plans] your catalog (prices nest under `plans.prices`). |
#events ⇒ Resources::Events
Returns the domain-event log — your reconciliation backstop.
101 102 |
# File 'lib/nombaone/client.rb', line 101 def events = @events ||= Resources::Events.new(self) # @return [Resources::Organization] org settings + billing/dunning policy. |
#invoices ⇒ Resources::Invoices
Returns what billing cycles produced (read + void).
89 90 |
# File 'lib/nombaone/client.rb', line 89 def invoices = @invoices ||= Resources::Invoices.new(self) # @return [Resources::Coupons] reusable discount rules. |
#mandates ⇒ Resources::Mandates
Returns direct-debit mandates (async NIBSS consent).
95 96 |
# File 'lib/nombaone/client.rb', line 95 def mandates = @mandates ||= Resources::Mandates.new(self) # @return [Resources::Settlements] settlements, refunds, payouts, escrow. |
#metrics ⇒ Resources::Metrics
Returns billing KPIs computed from the ledger.
105 106 |
# File 'lib/nombaone/client.rb', line 105 def metrics = @metrics ||= Resources::Metrics.new(self) # @return [Resources::Sandbox] sandbox-only simulation instruments. |
#organization ⇒ Resources::Organization
Returns org settings + billing/dunning policy.
103 104 |
# File 'lib/nombaone/client.rb', line 103 def organization = @organization ||= Resources::Organization.new(self) # @return [Resources::Metrics] billing KPIs computed from the ledger. |
#payment_methods ⇒ Resources::PaymentMethods
Returns cards, mandates, virtual accounts.
93 94 |
# File 'lib/nombaone/client.rb', line 93 def payment_methods = @payment_methods ||= Resources::PaymentMethods.new(self) # @return [Resources::Mandates] direct-debit mandates (async NIBSS consent). |
#plans ⇒ Resources::Plans
Returns your catalog (prices nest under plans.prices).
83 84 |
# File 'lib/nombaone/client.rb', line 83 def plans = @plans ||= Resources::Plans.new(self) # @return [Resources::Prices] immutable amounts and cadences. |
#prices ⇒ Resources::Prices
Returns immutable amounts and cadences.
85 86 |
# File 'lib/nombaone/client.rb', line 85 def prices = @prices ||= Resources::Prices.new(self) # @return [Resources::Subscriptions] the core billing object. |
#request(method:, path:, query: nil, body: nil, options: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute a single-object request and return the wrapped NombaObject.
117 118 119 120 |
# File 'lib/nombaone/client.rb', line 117 def request(method:, path:, query: nil, body: nil, options: nil) result = perform(method: method, path: path, query: query, body: body, options: ) wrap_data(result) end |
#request_page(method:, path:, query: nil, options: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute a list request and return a Page that auto-paginates.
124 125 126 127 128 129 130 |
# File 'lib/nombaone/client.rb', line 124 def request_page(method:, path:, query: nil, options: nil) raw_query = query || {} fetcher = lambda do |query_for_page| perform(method: method, path: path, query: query_for_page, options: ) end Page.new(fetcher: fetcher, query: raw_query, result: fetcher.call(raw_query)) end |
#sandbox ⇒ Resources::Sandbox
Returns sandbox-only simulation instruments.
107 |
# File 'lib/nombaone/client.rb', line 107 def sandbox = @sandbox ||= Resources::Sandbox.new(self) |
#settlements ⇒ Resources::Settlements
Returns settlements, refunds, payouts, escrow.
97 98 |
# File 'lib/nombaone/client.rb', line 97 def settlements = @settlements ||= Resources::Settlements.new(self) # @return [Resources::WebhookEndpoints] webhook endpoint management (REST). |
#subscriptions ⇒ Resources::Subscriptions
Returns the core billing object.
87 88 |
# File 'lib/nombaone/client.rb', line 87 def subscriptions = @subscriptions ||= Resources::Subscriptions.new(self) # @return [Resources::Invoices] what billing cycles produced (read + void). |
#webhook_endpoints ⇒ Resources::WebhookEndpoints
Returns webhook endpoint management (REST).
99 100 |
# File 'lib/nombaone/client.rb', line 99 def webhook_endpoints = @webhook_endpoints ||= Resources::WebhookEndpoints.new(self) # @return [Resources::Events] the domain-event log — your reconciliation backstop. |
#webhooks ⇒ Nombaone::Webhooks
A Webhooks helper bound to this client. Verification needs only the signing secret, so Nombaone.webhooks works without a client too.
113 |
# File 'lib/nombaone/client.rb', line 113 def webhooks = @webhooks ||= Webhooks.new |