Class: TerminalShop::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- TerminalShop::Client
- Defined in:
- lib/terminal_shop/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- ENVIRONMENTS =
rubocop:disable Style/MutableConstant
{production: "https://api.terminal.shop", dev: "https://api.dev.terminal.shop"}
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
- #address ⇒ TerminalShop::Resources::Address readonly
- #app ⇒ TerminalShop::Resources::App readonly
- #app_id ⇒ String? readonly
- #bearer_token ⇒ String readonly
- #card ⇒ TerminalShop::Resources::Card readonly
- #cart ⇒ TerminalShop::Resources::Cart readonly
- #email ⇒ TerminalShop::Resources::Email readonly
- #order ⇒ TerminalShop::Resources::Order readonly
- #product ⇒ TerminalShop::Resources::Product readonly
- #profile ⇒ TerminalShop::Resources::Profile readonly
- #subscription ⇒ TerminalShop::Resources::Subscription readonly
- #token ⇒ TerminalShop::Resources::Token readonly
- #view ⇒ TerminalShop::Resources::View 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(bearer_token: ENV["TERMINAL_BEARER_TOKEN"], app_id: nil, environment: nil, base_url: ENV["TERMINAL_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) ⇒ 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(bearer_token: ENV["TERMINAL_BEARER_TOKEN"], app_id: nil, environment: nil, base_url: ENV["TERMINAL_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) ⇒ Client
Creates and returns a new client for interacting with the API.
Each environment maps to a different base URL:
-
‘production` corresponds to `api.terminal.shop`
-
‘dev` corresponds to `api.dev.terminal.shop`
‘“api.example.com/v2/”`. Defaults to `ENV`
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 137 138 139 |
# File 'lib/terminal_shop/client.rb', line 94 def initialize( bearer_token: ENV["TERMINAL_BEARER_TOKEN"], app_id: nil, environment: nil, base_url: ENV["TERMINAL_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 ) base_url ||= TerminalShop::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do = "environment must be one of #{TerminalShop::Client::ENVIRONMENTS.keys}, got #{environment}" raise ArgumentError.new() end if bearer_token.nil? raise ArgumentError.new("bearer_token is required, and can be set via environ: \"TERMINAL_BEARER_TOKEN\"") end headers = { "x-terminal-app-id" => (@app_id = app_id&.to_s) } @bearer_token = bearer_token.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 ) @product = TerminalShop::Resources::Product.new(client: self) @profile = TerminalShop::Resources::Profile.new(client: self) @address = TerminalShop::Resources::Address.new(client: self) @card = TerminalShop::Resources::Card.new(client: self) @cart = TerminalShop::Resources::Cart.new(client: self) @order = TerminalShop::Resources::Order.new(client: self) @subscription = TerminalShop::Resources::Subscription.new(client: self) @token = TerminalShop::Resources::Token.new(client: self) @app = TerminalShop::Resources::App.new(client: self) @email = TerminalShop::Resources::Email.new(client: self) @view = TerminalShop::Resources::View.new(client: self) end |
Instance Attribute Details
#address ⇒ TerminalShop::Resources::Address (readonly)
36 37 38 |
# File 'lib/terminal_shop/client.rb', line 36 def address @address end |
#app ⇒ TerminalShop::Resources::App (readonly)
54 55 56 |
# File 'lib/terminal_shop/client.rb', line 54 def app @app end |
#app_id ⇒ String? (readonly)
27 28 29 |
# File 'lib/terminal_shop/client.rb', line 27 def app_id @app_id end |
#bearer_token ⇒ String (readonly)
24 25 26 |
# File 'lib/terminal_shop/client.rb', line 24 def bearer_token @bearer_token end |
#card ⇒ TerminalShop::Resources::Card (readonly)
39 40 41 |
# File 'lib/terminal_shop/client.rb', line 39 def card @card end |
#cart ⇒ TerminalShop::Resources::Cart (readonly)
42 43 44 |
# File 'lib/terminal_shop/client.rb', line 42 def cart @cart end |
#email ⇒ TerminalShop::Resources::Email (readonly)
57 58 59 |
# File 'lib/terminal_shop/client.rb', line 57 def email @email end |
#order ⇒ TerminalShop::Resources::Order (readonly)
45 46 47 |
# File 'lib/terminal_shop/client.rb', line 45 def order @order end |
#product ⇒ TerminalShop::Resources::Product (readonly)
30 31 32 |
# File 'lib/terminal_shop/client.rb', line 30 def product @product end |
#profile ⇒ TerminalShop::Resources::Profile (readonly)
33 34 35 |
# File 'lib/terminal_shop/client.rb', line 33 def profile @profile end |
#subscription ⇒ TerminalShop::Resources::Subscription (readonly)
48 49 50 |
# File 'lib/terminal_shop/client.rb', line 48 def subscription @subscription end |
#token ⇒ TerminalShop::Resources::Token (readonly)
51 52 53 |
# File 'lib/terminal_shop/client.rb', line 51 def token @token end |
#view ⇒ TerminalShop::Resources::View (readonly)
60 61 62 |
# File 'lib/terminal_shop/client.rb', line 60 def view @view end |