Class: TerminalShop::Client
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"}
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS, Internal::Transport::BaseClient::TerminalShop
Instance Attribute Summary collapse
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary
collapse
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
#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 https://api.terminal.shop
dev corresponds to https://api.dev.terminal.shop
"https://api.example.com/v2/". Defaults to ENV["TERMINAL_BASE_URL"]
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
140
141
142
143
144
145
146
147
148
149
150
|
# 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
message = "environment must be one of #{TerminalShop::Client::ENVIRONMENTS.keys}, got #{environment}"
raise ArgumentError.new(message)
end
if bearer_token.nil?
raise ArgumentError.new("bearer_token is required, and can be set via environ: \"TERMINAL_BEARER_TOKEN\"")
end
= {
"x-terminal-app-id" => (@app_id = app_id&.to_s)
}
= ENV["TERMINAL_CUSTOM_HEADERS"]
unless .nil?
parsed = {}
.split("\n").each do |line|
colon = line.index(":")
unless colon.nil?
parsed[line[0...colon].strip] = line[(colon + 1)..].strip
end
end
= parsed.merge()
end
@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:
)
@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
36
37
38
|
# File 'lib/terminal_shop/client.rb', line 36
def address
@address
end
|
54
55
56
|
# File 'lib/terminal_shop/client.rb', line 54
def app
@app
end
|
#app_id ⇒ String?
27
28
29
|
# File 'lib/terminal_shop/client.rb', line 27
def app_id
@app_id
end
|
#bearer_token ⇒ String
24
25
26
|
# File 'lib/terminal_shop/client.rb', line 24
def bearer_token
@bearer_token
end
|
39
40
41
|
# File 'lib/terminal_shop/client.rb', line 39
def card
@card
end
|
42
43
44
|
# File 'lib/terminal_shop/client.rb', line 42
def cart
@cart
end
|
57
58
59
|
# File 'lib/terminal_shop/client.rb', line 57
def email
@email
end
|
45
46
47
|
# File 'lib/terminal_shop/client.rb', line 45
def order
@order
end
|
30
31
32
|
# File 'lib/terminal_shop/client.rb', line 30
def product
@product
end
|
33
34
35
|
# File 'lib/terminal_shop/client.rb', line 33
def profile
@profile
end
|
48
49
50
|
# File 'lib/terminal_shop/client.rb', line 48
def subscription
@subscription
end
|
51
52
53
|
# File 'lib/terminal_shop/client.rb', line 51
def token
@token
end
|
60
61
62
|
# File 'lib/terminal_shop/client.rb', line 60
def view
@view
end
|