Class: Orb::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- Orb::Client
- Defined in:
- lib/orb/client.rb,
sig/orb/client.rbs
Constant Summary collapse
- DEFAULT_MAX_RETRIES =
Default max number of retries to attempt after a failed retryable request.
2- DEFAULT_TIMEOUT_IN_SECONDS =
Default per-request timeout.
60.0- DEFAULT_INITIAL_RETRY_DELAY =
Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.
0.5- DEFAULT_MAX_RETRY_DELAY =
Default max retry delay in seconds.
8.0
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::Orb, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
-
#alerts ⇒ Orb::Resources::Alerts
readonly
Alerts within Orb monitor spending, usage, or credit balance and trigger webhooks when a threshold is exceeded.
- #api_key ⇒ String readonly
-
#beta ⇒ Orb::Resources::Beta
readonly
The Plan resource represents a plan that can be subscribed to by a customer.
-
#coupons ⇒ Orb::Resources::Coupons
readonly
A coupon represents a reusable discount configuration that can be applied either as a fixed or percentage amount to an invoice or subscription.
-
#credit_blocks ⇒ Orb::Resources::CreditBlocks
readonly
The Credit Ledger Entry resource models prepaid credits within Orb.
-
#credit_notes ⇒ Orb::Resources::CreditNotes
readonly
The Credit Note resource represents a credit that has been applied to a particular invoice.
-
#customers ⇒ Orb::Resources::Customers
readonly
A customer is a buyer of your products, and the other party to the billing relationship.
- #dimensional_price_groups ⇒ Orb::Resources::DimensionalPriceGroups readonly
-
#events ⇒ Orb::Resources::Events
readonly
The Event resource represents a usage event that has been created for a customer.
-
#invoice_line_items ⇒ Orb::Resources::InvoiceLineItems
readonly
An
Invoiceis a fundamental billing entity, representing the request for payment for a single subscription. -
#invoices ⇒ Orb::Resources::Invoices
readonly
An
Invoiceis a fundamental billing entity, representing the request for payment for a single subscription. -
#items ⇒ Orb::Resources::Items
readonly
The Item resource represents a sellable product or good.
-
#license_types ⇒ Orb::Resources::LicenseTypes
readonly
The LicenseType resource represents a type of license that can be assigned to users.
- #licenses ⇒ Orb::Resources::Licenses readonly
-
#metrics ⇒ Orb::Resources::Metrics
readonly
The Metric resource represents a calculation of a quantity based on events.
-
#plans ⇒ Orb::Resources::Plans
readonly
The Plan resource represents a plan that can be subscribed to by a customer.
-
#prices ⇒ Orb::Resources::Prices
readonly
The Price resource represents a price that can be billed on a subscription, resulting in a charge on an invoice in the form of an invoice line item.
- #subscription_changes ⇒ Orb::Resources::SubscriptionChanges readonly
- #subscriptions ⇒ Orb::Resources::Subscriptions readonly
- #top_level ⇒ Orb::Resources::TopLevel readonly
- #webhook_secret ⇒ String? readonly
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary collapse
-
#initialize(api_key: ENV["ORB_API_KEY"], webhook_secret: ENV["ORB_WEBHOOK_SECRET"], base_url: ENV["ORB_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, idempotency_header: "Idempotency-Key") ⇒ Client
constructor
Creates and returns a new client for interacting with the API.
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(api_key: ENV["ORB_API_KEY"], webhook_secret: ENV["ORB_WEBHOOK_SECRET"], base_url: ENV["ORB_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, idempotency_header: "Idempotency-Key") ⇒ Client
Creates and returns a new client for interacting with the API.
"https://api.example.com/v2/". Defaults to ENV["ORB_BASE_URL"]
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/orb/client.rb', line 180 def initialize( api_key: ENV["ORB_API_KEY"], webhook_secret: ENV["ORB_WEBHOOK_SECRET"], base_url: ENV["ORB_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, idempotency_header: "Idempotency-Key" ) base_url ||= "https://api.withorb.com/v1" if api_key.nil? raise ArgumentError.new("api_key is required, and can be set via environ: \"ORB_API_KEY\"") end headers = {} custom_headers_env = ENV["ORB_CUSTOM_HEADERS"] unless custom_headers_env.nil? parsed = {} custom_headers_env.split("\n").each do |line| colon = line.index(":") unless colon.nil? parsed[line[0...colon].strip] = line[(colon + 1)..].strip end end headers = parsed.merge(headers) end @api_key = api_key.to_s @webhook_secret = webhook_secret&.to_s super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, headers: headers, idempotency_header: idempotency_header ) @top_level = Orb::Resources::TopLevel.new(client: self) @beta = Orb::Resources::Beta.new(client: self) @coupons = Orb::Resources::Coupons.new(client: self) @credit_notes = Orb::Resources::CreditNotes.new(client: self) @customers = Orb::Resources::Customers.new(client: self) @events = Orb::Resources::Events.new(client: self) @invoice_line_items = Orb::Resources::InvoiceLineItems.new(client: self) @invoices = Orb::Resources::Invoices.new(client: self) @items = Orb::Resources::Items.new(client: self) @metrics = Orb::Resources::Metrics.new(client: self) @plans = Orb::Resources::Plans.new(client: self) @prices = Orb::Resources::Prices.new(client: self) @subscriptions = Orb::Resources::Subscriptions.new(client: self) @alerts = Orb::Resources::Alerts.new(client: self) @dimensional_price_groups = Orb::Resources::DimensionalPriceGroups.new(client: self) @subscription_changes = Orb::Resources::SubscriptionChanges.new(client: self) @credit_blocks = Orb::Resources::CreditBlocks.new(client: self) @license_types = Orb::Resources::LicenseTypes.new(client: self) @licenses = Orb::Resources::Licenses.new(client: self) end |
Instance Attribute Details
#alerts ⇒ Orb::Resources::Alerts (readonly)
Alerts within Orb monitor spending, usage, or credit balance and trigger webhooks when a threshold is exceeded.
Alerts created through the API can be scoped to either customers or subscriptions.
131 132 133 |
# File 'lib/orb/client.rb', line 131 def alerts @alerts end |
#api_key ⇒ String (readonly)
19 20 21 |
# File 'lib/orb/client.rb', line 19 def api_key @api_key end |
#beta ⇒ Orb::Resources::Beta (readonly)
The Plan resource represents a plan that can be subscribed to by a customer. Plans define the billing behavior of the subscription. You can see more about how to configure prices in the Price resource.
32 33 34 |
# File 'lib/orb/client.rb', line 32 def beta @beta end |
#coupons ⇒ Orb::Resources::Coupons (readonly)
A coupon represents a reusable discount configuration that can be applied either as a fixed or percentage amount to an invoice or subscription. Coupons are activated using a redemption code, which applies the discount to a subscription or invoice. The duration of a coupon determines how long it remains available for use by end users.
40 41 42 |
# File 'lib/orb/client.rb', line 40 def coupons @coupons end |
#credit_blocks ⇒ Orb::Resources::CreditBlocks (readonly)
The Credit Ledger Entry resource models prepaid credits within Orb.
142 143 144 |
# File 'lib/orb/client.rb', line 142 def credit_blocks @credit_blocks end |
#credit_notes ⇒ Orb::Resources::CreditNotes (readonly)
The Credit Note resource represents a credit that has been applied to a particular invoice.
45 46 47 |
# File 'lib/orb/client.rb', line 45 def credit_notes @credit_notes end |
#customers ⇒ Orb::Resources::Customers (readonly)
A customer is a buyer of your products, and the other party to the billing relationship.
In Orb, customers are assigned system generated identifiers automatically, but
it's often desirable to have these match existing identifiers in your system. To
avoid having to denormalize Orb ID information, you can pass in an
external_customer_id with your own identifier. See
Customer ID Aliases for further
information about how these aliases work in Orb.
In addition to having an identifier in your system, a customer may exist in a
payment provider solution like Stripe. Use the payment_provider_id and the
payment_provider enum field to express this mapping.
A customer also has a timezone (from the standard IANA timezone database), which defaults to your account's timezone. See Timezone localization for information on what this timezone parameter influences within Orb.
66 67 68 |
# File 'lib/orb/client.rb', line 66 def customers @customers end |
#dimensional_price_groups ⇒ Orb::Resources::DimensionalPriceGroups (readonly)
134 135 136 |
# File 'lib/orb/client.rb', line 134 def dimensional_price_groups @dimensional_price_groups end |
#events ⇒ Orb::Resources::Events (readonly)
The Event resource represents a usage event that has been created for a customer. Events are the core of Orb's usage-based billing model, and are used to calculate the usage charges for a given billing period.
72 73 74 |
# File 'lib/orb/client.rb', line 72 def events @events end |
#invoice_line_items ⇒ Orb::Resources::InvoiceLineItems (readonly)
An Invoice is a fundamental billing entity,
representing the request for payment for a single subscription. This includes a
set of line items, which correspond to prices in the subscription's plan and can
represent fixed recurring fees or usage-based fees. They are generated at the
end of a billing period, or as the result of an action, such as a cancellation.
80 81 82 |
# File 'lib/orb/client.rb', line 80 def invoice_line_items @invoice_line_items end |
#invoices ⇒ Orb::Resources::Invoices (readonly)
An Invoice is a fundamental billing entity,
representing the request for payment for a single subscription. This includes a
set of line items, which correspond to prices in the subscription's plan and can
represent fixed recurring fees or usage-based fees. They are generated at the
end of a billing period, or as the result of an action, such as a cancellation.
88 89 90 |
# File 'lib/orb/client.rb', line 88 def invoices @invoices end |
#items ⇒ Orb::Resources::Items (readonly)
The Item resource represents a sellable product or good. Items are associated with all line items, billable metrics, and prices and are used for defining external sync behavior for invoices and tax calculation purposes.
94 95 96 |
# File 'lib/orb/client.rb', line 94 def items @items end |
#license_types ⇒ Orb::Resources::LicenseTypes (readonly)
The LicenseType resource represents a type of license that can be assigned to users. License types are used during billing by grouping metrics on the configured grouping key.
148 149 150 |
# File 'lib/orb/client.rb', line 148 def license_types @license_types end |
#licenses ⇒ Orb::Resources::Licenses (readonly)
151 152 153 |
# File 'lib/orb/client.rb', line 151 def licenses @licenses end |
#metrics ⇒ Orb::Resources::Metrics (readonly)
The Metric resource represents a calculation of a quantity based on events. Metrics are defined by the query that transforms raw usage events into meaningful values for your customers.
100 101 102 |
# File 'lib/orb/client.rb', line 100 def metrics @metrics end |
#plans ⇒ Orb::Resources::Plans (readonly)
The Plan resource represents a plan that can be subscribed to by a customer. Plans define the billing behavior of the subscription. You can see more about how to configure prices in the Price resource.
107 108 109 |
# File 'lib/orb/client.rb', line 107 def plans @plans end |
#prices ⇒ Orb::Resources::Prices (readonly)
The Price resource represents a price that can be billed on a subscription, resulting in a charge on an invoice in the form of an invoice line item. Prices take a quantity and determine an amount to bill.
Orb supports a few different pricing models out of the box. Each of these models is serialized differently in a given Price object. The model_type field determines the key for the configuration object that is present.
For more on the types of prices, see the core concepts documentation
120 121 122 |
# File 'lib/orb/client.rb', line 120 def prices @prices end |
#subscription_changes ⇒ Orb::Resources::SubscriptionChanges (readonly)
137 138 139 |
# File 'lib/orb/client.rb', line 137 def subscription_changes @subscription_changes end |
#subscriptions ⇒ Orb::Resources::Subscriptions (readonly)
123 124 125 |
# File 'lib/orb/client.rb', line 123 def subscriptions @subscriptions end |
#top_level ⇒ Orb::Resources::TopLevel (readonly)
25 26 27 |
# File 'lib/orb/client.rb', line 25 def top_level @top_level end |
#webhook_secret ⇒ String? (readonly)
22 23 24 |
# File 'lib/orb/client.rb', line 22 def webhook_secret @webhook_secret end |