Class: Orb::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/orb/client.rb

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::PLATFORM_HEADERS

Instance Attribute Summary collapse

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

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"], 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.

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • api_key (String, nil) (defaults to: ENV["ORB_API_KEY"])

    Defaults to ‘ENV`

  • base_url (String, nil) (defaults to: ENV["ORB_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)
  • idempotency_header (String) (defaults to: "Idempotency-Key")


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/orb/client.rb', line 94

def initialize(
  api_key: ENV["ORB_API_KEY"],
  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

  @api_key = api_key.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,
    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)
end

Instance Attribute Details

#alertsOrb::Resources::Alerts (readonly)



61
62
63
# File 'lib/orb/client.rb', line 61

def alerts
  @alerts
end

#api_keyString (readonly)

Returns:

  • (String)


19
20
21
# File 'lib/orb/client.rb', line 19

def api_key
  @api_key
end

#betaOrb::Resources::Beta (readonly)



25
26
27
# File 'lib/orb/client.rb', line 25

def beta
  @beta
end

#couponsOrb::Resources::Coupons (readonly)



28
29
30
# File 'lib/orb/client.rb', line 28

def coupons
  @coupons
end

#credit_notesOrb::Resources::CreditNotes (readonly)



31
32
33
# File 'lib/orb/client.rb', line 31

def credit_notes
  @credit_notes
end

#customersOrb::Resources::Customers (readonly)



34
35
36
# File 'lib/orb/client.rb', line 34

def customers
  @customers
end

#dimensional_price_groupsOrb::Resources::DimensionalPriceGroups (readonly)



64
65
66
# File 'lib/orb/client.rb', line 64

def dimensional_price_groups
  @dimensional_price_groups
end

#eventsOrb::Resources::Events (readonly)



37
38
39
# File 'lib/orb/client.rb', line 37

def events
  @events
end

#invoice_line_itemsOrb::Resources::InvoiceLineItems (readonly)



40
41
42
# File 'lib/orb/client.rb', line 40

def invoice_line_items
  @invoice_line_items
end

#invoicesOrb::Resources::Invoices (readonly)



43
44
45
# File 'lib/orb/client.rb', line 43

def invoices
  @invoices
end

#itemsOrb::Resources::Items (readonly)



46
47
48
# File 'lib/orb/client.rb', line 46

def items
  @items
end

#metricsOrb::Resources::Metrics (readonly)



49
50
51
# File 'lib/orb/client.rb', line 49

def metrics
  @metrics
end

#plansOrb::Resources::Plans (readonly)



52
53
54
# File 'lib/orb/client.rb', line 52

def plans
  @plans
end

#pricesOrb::Resources::Prices (readonly)



55
56
57
# File 'lib/orb/client.rb', line 55

def prices
  @prices
end

#subscription_changesOrb::Resources::SubscriptionChanges (readonly)



67
68
69
# File 'lib/orb/client.rb', line 67

def subscription_changes
  @subscription_changes
end

#subscriptionsOrb::Resources::Subscriptions (readonly)



58
59
60
# File 'lib/orb/client.rb', line 58

def subscriptions
  @subscriptions
end

#top_levelOrb::Resources::TopLevel (readonly)



22
23
24
# File 'lib/orb/client.rb', line 22

def top_level
  @top_level
end