terminal-shop 0.1.0.pre.alpha.6 → 0.1.0.pre.alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/terminal-shop/base_client.rb +11 -7
- data/lib/terminal-shop/base_model.rb +8 -8
- data/lib/terminal-shop/client.rb +5 -3
- data/lib/terminal-shop/models/subscription.rb +78 -1
- data/lib/terminal-shop/resources/subscription.rb +2 -0
- data/lib/terminal-shop/util.rb +13 -20
- data/lib/terminal-shop/version.rb +1 -1
- data/rbi/lib/terminal-shop/base_client.rbi +6 -3
- data/rbi/lib/terminal-shop/client.rbi +26 -14
- data/rbi/lib/terminal-shop/errors.rbi +14 -7
- data/rbi/lib/terminal-shop/models/address.rbi +51 -15
- data/rbi/lib/terminal-shop/models/address_create_params.rbi +45 -14
- data/rbi/lib/terminal-shop/models/address_create_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/address_delete_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/address_list_response.rbi +8 -1
- data/rbi/lib/terminal-shop/models/app.rbi +18 -3
- data/rbi/lib/terminal-shop/models/app_create_response.rbi +20 -3
- data/rbi/lib/terminal-shop/models/app_delete_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/app_get_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/app_list_response.rbi +8 -1
- data/rbi/lib/terminal-shop/models/card.rbi +38 -6
- data/rbi/lib/terminal-shop/models/card_collect_response.rbi +14 -2
- data/rbi/lib/terminal-shop/models/card_create_params.rbi +6 -1
- data/rbi/lib/terminal-shop/models/card_create_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/card_delete_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/card_list_response.rbi +8 -1
- data/rbi/lib/terminal-shop/models/cart.rbi +82 -26
- data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/cart_get_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +6 -1
- data/rbi/lib/terminal-shop/models/cart_set_address_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +6 -1
- data/rbi/lib/terminal-shop/models/cart_set_card_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +12 -2
- data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/email_create_params.rbi +6 -1
- data/rbi/lib/terminal-shop/models/email_create_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/order.rbi +143 -42
- data/rbi/lib/terminal-shop/models/order_get_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/order_list_response.rbi +8 -1
- data/rbi/lib/terminal-shop/models/product.rbi +47 -14
- data/rbi/lib/terminal-shop/models/product_list_response.rbi +8 -1
- data/rbi/lib/terminal-shop/models/product_variant.rbi +18 -3
- data/rbi/lib/terminal-shop/models/profile.rbi +38 -6
- data/rbi/lib/terminal-shop/models/profile_me_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/profile_update_params.rbi +12 -2
- data/rbi/lib/terminal-shop/models/profile_update_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/subscription.rbi +147 -12
- data/rbi/lib/terminal-shop/models/subscription_create_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/subscription_delete_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +8 -1
- data/rbi/lib/terminal-shop/models/token.rbi +24 -4
- data/rbi/lib/terminal-shop/models/token_create_response.rbi +20 -3
- data/rbi/lib/terminal-shop/models/token_delete_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/token_get_response.rbi +6 -1
- data/rbi/lib/terminal-shop/models/token_list_response.rbi +8 -1
- data/rbi/lib/terminal-shop/models/view_init_response.rbi +76 -10
- data/rbi/lib/terminal-shop/request_options.rbi +69 -7
- data/rbi/lib/terminal-shop/resources/subscription.rbi +5 -0
- data/rbi/lib/terminal-shop/util.rbi +6 -1
- data/rbi/lib/terminal-shop/version.rbi +1 -1
- data/sig/terminal-shop/base_client.rbs +13 -13
- data/sig/terminal-shop/base_model.rbs +26 -26
- data/sig/terminal-shop/base_page.rbs +1 -1
- data/sig/terminal-shop/client.rbs +3 -3
- data/sig/terminal-shop/models/address.rbs +3 -3
- data/sig/terminal-shop/models/address_create_params.rbs +3 -3
- data/sig/terminal-shop/models/address_list_response.rbs +3 -3
- data/sig/terminal-shop/models/app_list_response.rbs +3 -3
- data/sig/terminal-shop/models/card_list_response.rbs +3 -3
- data/sig/terminal-shop/models/cart.rbs +11 -9
- data/sig/terminal-shop/models/order.rbs +12 -12
- data/sig/terminal-shop/models/order_list_response.rbs +3 -3
- data/sig/terminal-shop/models/product.rbs +14 -14
- data/sig/terminal-shop/models/product_list_response.rbs +3 -3
- data/sig/terminal-shop/models/subscription.rbs +52 -4
- data/sig/terminal-shop/models/subscription_list_response.rbs +3 -3
- data/sig/terminal-shop/models/token_list_response.rbs +3 -3
- data/sig/terminal-shop/models/view_init_response.rbs +21 -21
- data/sig/terminal-shop/request_options.rbs +9 -9
- data/sig/terminal-shop/resources/address.rbs +4 -3
- data/sig/terminal-shop/resources/app.rbs +4 -4
- data/sig/terminal-shop/resources/card.rbs +4 -4
- data/sig/terminal-shop/resources/cart.rbs +6 -5
- data/sig/terminal-shop/resources/email.rbs +1 -1
- data/sig/terminal-shop/resources/order.rbs +2 -2
- data/sig/terminal-shop/resources/product.rbs +1 -1
- data/sig/terminal-shop/resources/profile.rbs +3 -2
- data/sig/terminal-shop/resources/subscription.rbs +4 -3
- data/sig/terminal-shop/resources/token.rbs +4 -4
- data/sig/terminal-shop/resources/view.rbs +1 -1
- data/sig/terminal-shop/util.rbs +12 -12
- data/sig/terminal-shop/version.rbs +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7302bc4cca8faceca8577dce4b9b10362963e1d51e24657389a8c663376299e
|
4
|
+
data.tar.gz: 2fd2e9b55fc3c9ba9f4038a44e6bf71e18a49d1d4186a44031ffbe2e43be1fe7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f8be58ee44eddefe127293b9423358e625982a33a00d83076f23acfcb5845bb27633e0ee6820fe1b7c7915bfdad29a9b40db3a971cf74490082e5cc0573189d
|
7
|
+
data.tar.gz: 6bff5193dcd2072b584d1a6ff52d4bf7173c66ff6d2568665fcd1c1a7a73e536718fd90c4f393574c579f8a368afeb547ff83bb2475493c25de5917a4d753280
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ require "terminal-shop"
|
|
41
41
|
|
42
42
|
terminal = TerminalShop::Client.new(
|
43
43
|
bearer_token: "My Bearer Token", # defaults to ENV["TERMINAL_BEARER_TOKEN"]
|
44
|
-
environment: "
|
44
|
+
environment: "dev" # defaults to "production"
|
45
45
|
)
|
46
46
|
|
47
47
|
product = terminal.product.list
|
@@ -126,10 +126,16 @@ module TerminalShop
|
|
126
126
|
|
127
127
|
path = TerminalShop::Util.interpolate_path(uninterpolated_path)
|
128
128
|
|
129
|
+
query = TerminalShop::Util.deep_merge(
|
130
|
+
req[:query].to_h,
|
131
|
+
opts[:extra_query].to_h
|
132
|
+
)
|
133
|
+
|
129
134
|
headers = TerminalShop::Util.normalized_headers(
|
130
135
|
@headers,
|
131
136
|
auth_headers,
|
132
|
-
|
137
|
+
req[:headers].to_h,
|
138
|
+
opts[:extra_headers].to_h
|
133
139
|
)
|
134
140
|
|
135
141
|
if @idempotency_header &&
|
@@ -157,7 +163,7 @@ module TerminalShop
|
|
157
163
|
TerminalShop::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
|
158
164
|
end
|
159
165
|
|
160
|
-
url = TerminalShop::Util.join_parsed_uri(@base_url, {**req, path: path})
|
166
|
+
url = TerminalShop::Util.join_parsed_uri(@base_url, {**req, path: path, query: query})
|
161
167
|
headers, encoded = TerminalShop::Util.encode_content(headers, body)
|
162
168
|
max_retries = opts.fetch(:max_retries, @max_retries)
|
163
169
|
{method: method, url: url, headers: headers, body: encoded, max_retries: max_retries, timeout: timeout}
|
@@ -387,12 +393,10 @@ module TerminalShop
|
|
387
393
|
parsed = TerminalShop::Util.decode_content(response)
|
388
394
|
unwrapped = TerminalShop::Util.dig(parsed, req[:unwrap])
|
389
395
|
|
390
|
-
|
391
|
-
|
392
|
-
case [page, model]
|
393
|
-
in [Class, Class | TerminalShop::Converter | nil]
|
396
|
+
case [req[:page], req.fetch(:model, TerminalShop::Unknown)]
|
397
|
+
in [Class => page, _]
|
394
398
|
page.new(client: self, req: req, headers: response, unwrapped: unwrapped)
|
395
|
-
in [nil, Class | TerminalShop::Converter]
|
399
|
+
in [nil, Class | TerminalShop::Converter => model]
|
396
400
|
TerminalShop::Converter.coerce(model, unwrapped)
|
397
401
|
in [nil, nil]
|
398
402
|
unwrapped
|
@@ -586,7 +586,7 @@ module TerminalShop
|
|
586
586
|
case other
|
587
587
|
in Array
|
588
588
|
# rubocop:disable Style/CaseEquality
|
589
|
-
other.all? {
|
589
|
+
other.all? { type === _1 }
|
590
590
|
# rubocop:enable Style/CaseEquality
|
591
591
|
else
|
592
592
|
false
|
@@ -609,7 +609,7 @@ module TerminalShop
|
|
609
609
|
type = item_type
|
610
610
|
case value
|
611
611
|
in Enumerable unless value.is_a?(Hash)
|
612
|
-
value.map {
|
612
|
+
value.map { TerminalShop::Converter.coerce(type, _1) }
|
613
613
|
else
|
614
614
|
value
|
615
615
|
end
|
@@ -625,7 +625,7 @@ module TerminalShop
|
|
625
625
|
type = item_type
|
626
626
|
case value
|
627
627
|
in Enumerable unless value.is_a?(Hash)
|
628
|
-
value.map {
|
628
|
+
value.map { TerminalShop::Converter.dump(type, _1) }.to_a
|
629
629
|
else
|
630
630
|
value
|
631
631
|
end
|
@@ -906,7 +906,7 @@ module TerminalShop
|
|
906
906
|
setter = "#{name_sym}="
|
907
907
|
|
908
908
|
if known_fields.key?(name_sym)
|
909
|
-
[name_sym, setter].each {
|
909
|
+
[name_sym, setter].each { undef_method(_1) }
|
910
910
|
end
|
911
911
|
|
912
912
|
known_fields[name_sym] = {mode: @mode, key: key, required: required, type_fn: type_fn}
|
@@ -1015,8 +1015,8 @@ module TerminalShop
|
|
1015
1015
|
# @return [TerminalShop::BaseModel, Object]
|
1016
1016
|
#
|
1017
1017
|
def self.coerce(value)
|
1018
|
-
case
|
1019
|
-
in Hash
|
1018
|
+
case TerminalShop::Util.coerce_hash(value)
|
1019
|
+
in Hash => coerced
|
1020
1020
|
new(coerced)
|
1021
1021
|
else
|
1022
1022
|
value
|
@@ -1166,8 +1166,8 @@ module TerminalShop
|
|
1166
1166
|
# @param data [Hash{Symbol=>Object}, TerminalShop::BaseModel]
|
1167
1167
|
#
|
1168
1168
|
def initialize(data = {})
|
1169
|
-
case
|
1170
|
-
in Hash
|
1169
|
+
case TerminalShop::Util.coerce_hash(data)
|
1170
|
+
in Hash => coerced
|
1171
1171
|
@data = coerced.transform_keys(&:to_sym)
|
1172
1172
|
else
|
1173
1173
|
raise ArgumentError.new("Expected a #{Hash} or #{TerminalShop::BaseModel}, got #{data.inspect}")
|
data/lib/terminal-shop/client.rb
CHANGED
@@ -16,7 +16,7 @@ module TerminalShop
|
|
16
16
|
DEFAULT_MAX_RETRY_DELAY = 8.0
|
17
17
|
|
18
18
|
# rubocop:disable Style/MutableConstant
|
19
|
-
ENVIRONMENTS = {production: "https://api.terminal.shop/",
|
19
|
+
ENVIRONMENTS = {production: "https://api.terminal.shop/", dev: "https://api.dev.terminal.shop/"}
|
20
20
|
# rubocop:enable Style/MutableConstant
|
21
21
|
|
22
22
|
# Client option
|
@@ -61,17 +61,19 @@ module TerminalShop
|
|
61
61
|
# @return [Hash{String=>String}]
|
62
62
|
#
|
63
63
|
private def auth_headers
|
64
|
+
return {} if @bearer_token.nil?
|
65
|
+
|
64
66
|
{"Authorization" => "Bearer #{@bearer_token}"}
|
65
67
|
end
|
66
68
|
|
67
69
|
# Creates and returns a new client for interacting with the API.
|
68
70
|
#
|
69
|
-
# @param environment [:production, :
|
71
|
+
# @param environment [:production, :dev, nil] Specifies the environment to use for the API.
|
70
72
|
#
|
71
73
|
# Each environment maps to a different base URL:
|
72
74
|
#
|
73
75
|
# - `production` corresponds to `https://api.terminal.shop/`
|
74
|
-
# - `
|
76
|
+
# - `dev` corresponds to `https://api.dev.terminal.shop/`
|
75
77
|
#
|
76
78
|
# @param base_url [String, nil] Override the default base URL for the API, e.g., `"https://api.example.com/v2/"`
|
77
79
|
#
|
@@ -60,6 +60,16 @@ module TerminalShop
|
|
60
60
|
# # @return [String]
|
61
61
|
# attr_writer :next_
|
62
62
|
|
63
|
+
# @!attribute [r] schedule
|
64
|
+
# Schedule of the subscription.
|
65
|
+
#
|
66
|
+
# @return [TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly, nil]
|
67
|
+
optional :schedule, union: -> { TerminalShop::Models::SubscriptionAPI::Schedule }
|
68
|
+
|
69
|
+
# @!parse
|
70
|
+
# # @return [TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly]
|
71
|
+
# attr_writer :schedule
|
72
|
+
|
63
73
|
# @!parse
|
64
74
|
# # Subscription to a Terminal shop product.
|
65
75
|
# #
|
@@ -70,8 +80,9 @@ module TerminalShop
|
|
70
80
|
# # @param product_variant_id [String]
|
71
81
|
# # @param quantity [Integer]
|
72
82
|
# # @param next_ [String]
|
83
|
+
# # @param schedule [TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly]
|
73
84
|
# #
|
74
|
-
# def initialize(id:, address_id:, card_id:, frequency:, product_variant_id:, quantity:, next_: nil, **) = super
|
85
|
+
# def initialize(id:, address_id:, card_id:, frequency:, product_variant_id:, quantity:, next_: nil, schedule: nil, **) = super
|
75
86
|
|
76
87
|
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
77
88
|
|
@@ -108,6 +119,72 @@ module TerminalShop
|
|
108
119
|
# #
|
109
120
|
# def self.values; end
|
110
121
|
end
|
122
|
+
|
123
|
+
# @abstract
|
124
|
+
#
|
125
|
+
# Schedule of the subscription.
|
126
|
+
#
|
127
|
+
# @example
|
128
|
+
# ```ruby
|
129
|
+
# case schedule
|
130
|
+
# in TerminalShop::Models::SubscriptionAPI::Schedule::Fixed
|
131
|
+
# # ...
|
132
|
+
# in TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
133
|
+
# # ...
|
134
|
+
# end
|
135
|
+
# ```
|
136
|
+
class Schedule < TerminalShop::Union
|
137
|
+
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Fixed }
|
138
|
+
|
139
|
+
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Weekly }
|
140
|
+
|
141
|
+
# @example
|
142
|
+
# ```ruby
|
143
|
+
# fixed => {
|
144
|
+
# type: :fixed
|
145
|
+
# }
|
146
|
+
# ```
|
147
|
+
class Fixed < TerminalShop::BaseModel
|
148
|
+
# @!attribute type
|
149
|
+
#
|
150
|
+
# @return [Symbol, :fixed]
|
151
|
+
required :type, const: :fixed
|
152
|
+
|
153
|
+
# @!parse
|
154
|
+
# # @param type [Symbol, :fixed]
|
155
|
+
# #
|
156
|
+
# def initialize(type: :fixed, **) = super
|
157
|
+
|
158
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
159
|
+
end
|
160
|
+
|
161
|
+
# @example
|
162
|
+
# ```ruby
|
163
|
+
# weekly => {
|
164
|
+
# interval: Integer,
|
165
|
+
# type: :weekly
|
166
|
+
# }
|
167
|
+
# ```
|
168
|
+
class Weekly < TerminalShop::BaseModel
|
169
|
+
# @!attribute interval
|
170
|
+
#
|
171
|
+
# @return [Integer]
|
172
|
+
required :interval, Integer
|
173
|
+
|
174
|
+
# @!attribute type
|
175
|
+
#
|
176
|
+
# @return [Symbol, :weekly]
|
177
|
+
required :type, const: :weekly
|
178
|
+
|
179
|
+
# @!parse
|
180
|
+
# # @param interval [Integer]
|
181
|
+
# # @param type [Symbol, :weekly]
|
182
|
+
# #
|
183
|
+
# def initialize(interval:, type: :weekly, **) = super
|
184
|
+
|
185
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
186
|
+
end
|
187
|
+
end
|
111
188
|
end
|
112
189
|
end
|
113
190
|
end
|
@@ -21,6 +21,8 @@ module TerminalShop
|
|
21
21
|
#
|
22
22
|
# @option params [String] :next_ Next shipment and billing date for the subscription.
|
23
23
|
#
|
24
|
+
# @option params [TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly] :schedule Schedule of the subscription.
|
25
|
+
#
|
24
26
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
25
27
|
#
|
26
28
|
# @return [TerminalShop::Models::SubscriptionCreateResponse]
|
data/lib/terminal-shop/util.rb
CHANGED
@@ -48,8 +48,8 @@ module TerminalShop
|
|
48
48
|
# @return [Boolean, nil]
|
49
49
|
#
|
50
50
|
def self.coerce_boolean!(input)
|
51
|
-
case
|
52
|
-
in true | false | nil
|
51
|
+
case coerce_boolean(input)
|
52
|
+
in true | false | nil => coerced
|
53
53
|
coerced
|
54
54
|
else
|
55
55
|
raise ArgumentError.new("Unable to coerce #{input.inspect} into boolean value")
|
@@ -159,25 +159,20 @@ module TerminalShop
|
|
159
159
|
# @return [Object]
|
160
160
|
#
|
161
161
|
private_class_method def self.deep_merge_lr(lhs, rhs, concat: false)
|
162
|
-
|
163
|
-
case rhs
|
164
|
-
in Hash
|
165
|
-
rhs.reject { |_, value| value == OMIT }
|
166
|
-
else
|
167
|
-
rhs
|
168
|
-
end
|
169
|
-
|
170
|
-
case [lhs, rhs_cleaned, concat]
|
162
|
+
case [lhs, rhs, concat]
|
171
163
|
in [Hash, Hash, _]
|
164
|
+
# rubocop:disable Style/YodaCondition
|
165
|
+
rhs_cleaned = rhs.reject { |_, val| OMIT == val }
|
172
166
|
lhs
|
173
|
-
.reject { |key, _| rhs[key]
|
167
|
+
.reject { |key, _| OMIT == rhs[key] }
|
174
168
|
.merge(rhs_cleaned) do |_, old_val, new_val|
|
175
169
|
deep_merge_lr(old_val, new_val, concat: concat)
|
176
170
|
end
|
171
|
+
# rubocop:enable Style/YodaCondition
|
177
172
|
in [Array, Array, true]
|
178
|
-
lhs.concat(
|
173
|
+
lhs.concat(rhs)
|
179
174
|
else
|
180
|
-
|
175
|
+
rhs
|
181
176
|
end
|
182
177
|
end
|
183
178
|
|
@@ -235,7 +230,7 @@ module TerminalShop
|
|
235
230
|
in []
|
236
231
|
""
|
237
232
|
in [String, *interpolations]
|
238
|
-
encoded = interpolations.map {
|
233
|
+
encoded = interpolations.map { ERB::Util.url_encode(_1) }
|
239
234
|
path.first % encoded
|
240
235
|
end
|
241
236
|
end
|
@@ -297,8 +292,6 @@ module TerminalShop
|
|
297
292
|
#
|
298
293
|
# @option rhs [Hash{String=>Array<String>}] :query
|
299
294
|
#
|
300
|
-
# @option rhs [Hash{String=>Array<String>}] :extra_query
|
301
|
-
#
|
302
295
|
# @return [URI::Generic]
|
303
296
|
#
|
304
297
|
def self.join_parsed_uri(lhs, rhs)
|
@@ -312,7 +305,7 @@ module TerminalShop
|
|
312
305
|
query = deep_merge(
|
313
306
|
joined.path == base_path ? base_query : {},
|
314
307
|
parsed_query,
|
315
|
-
|
308
|
+
rhs[:query].to_h,
|
316
309
|
concat: true
|
317
310
|
)
|
318
311
|
|
@@ -332,12 +325,12 @@ module TerminalShop
|
|
332
325
|
|
333
326
|
# @private
|
334
327
|
#
|
335
|
-
# @param query [Hash{String=>Array<String>, String, nil}]
|
328
|
+
# @param query [Hash{String=>Array<String>, String, nil}, nil]
|
336
329
|
#
|
337
330
|
# @return [String, nil]
|
338
331
|
#
|
339
332
|
def self.encode_query(query)
|
340
|
-
query.empty? ? nil : URI.encode_www_form(query)
|
333
|
+
query.to_h.empty? ? nil : URI.encode_www_form(query)
|
341
334
|
end
|
342
335
|
|
343
336
|
# @private
|
@@ -35,10 +35,13 @@ module TerminalShop
|
|
35
35
|
def self.validate!(req)
|
36
36
|
end
|
37
37
|
|
38
|
-
# @private
|
39
|
-
#
|
40
38
|
sig { returns(T.anything) }
|
41
|
-
|
39
|
+
def requester
|
40
|
+
end
|
41
|
+
|
42
|
+
sig { params(_: T.anything).returns(T.anything) }
|
43
|
+
def requester=(_)
|
44
|
+
end
|
42
45
|
|
43
46
|
sig do
|
44
47
|
params(
|
@@ -11,47 +11,59 @@ module TerminalShop
|
|
11
11
|
DEFAULT_MAX_RETRY_DELAY = T.let(8.0, Float)
|
12
12
|
|
13
13
|
ENVIRONMENTS = T.let(
|
14
|
-
{production: "https://api.terminal.shop/",
|
14
|
+
{production: "https://api.terminal.shop/", dev: "https://api.dev.terminal.shop/"},
|
15
15
|
T::Hash[Symbol, String]
|
16
16
|
)
|
17
17
|
|
18
18
|
sig { returns(String) }
|
19
|
-
|
19
|
+
def bearer_token
|
20
|
+
end
|
20
21
|
|
21
22
|
sig { returns(TerminalShop::Resources::Product) }
|
22
|
-
|
23
|
+
def product
|
24
|
+
end
|
23
25
|
|
24
26
|
sig { returns(TerminalShop::Resources::Profile) }
|
25
|
-
|
27
|
+
def profile
|
28
|
+
end
|
26
29
|
|
27
30
|
sig { returns(TerminalShop::Resources::Address) }
|
28
|
-
|
31
|
+
def address
|
32
|
+
end
|
29
33
|
|
30
34
|
sig { returns(TerminalShop::Resources::Card) }
|
31
|
-
|
35
|
+
def card
|
36
|
+
end
|
32
37
|
|
33
38
|
sig { returns(TerminalShop::Resources::Cart) }
|
34
|
-
|
39
|
+
def cart
|
40
|
+
end
|
35
41
|
|
36
42
|
sig { returns(TerminalShop::Resources::Order) }
|
37
|
-
|
43
|
+
def order
|
44
|
+
end
|
38
45
|
|
39
46
|
sig { returns(TerminalShop::Resources::Subscription) }
|
40
|
-
|
47
|
+
def subscription
|
48
|
+
end
|
41
49
|
|
42
50
|
sig { returns(TerminalShop::Resources::Token) }
|
43
|
-
|
51
|
+
def token
|
52
|
+
end
|
44
53
|
|
45
54
|
sig { returns(TerminalShop::Resources::App) }
|
46
|
-
|
55
|
+
def app
|
56
|
+
end
|
47
57
|
|
48
58
|
sig { returns(TerminalShop::Resources::Email) }
|
49
|
-
|
59
|
+
def email
|
60
|
+
end
|
50
61
|
|
51
62
|
sig { returns(TerminalShop::Resources::View) }
|
52
|
-
|
63
|
+
def view
|
64
|
+
end
|
53
65
|
|
54
|
-
sig { returns(T::Hash[String, String]) }
|
66
|
+
sig { override.returns(T::Hash[String, String]) }
|
55
67
|
private def auth_headers
|
56
68
|
end
|
57
69
|
|
@@ -3,7 +3,8 @@
|
|
3
3
|
module TerminalShop
|
4
4
|
class Error < StandardError
|
5
5
|
sig { returns(T.nilable(StandardError)) }
|
6
|
-
|
6
|
+
def cause
|
7
|
+
end
|
7
8
|
end
|
8
9
|
|
9
10
|
class ConversionError < TerminalShop::Error
|
@@ -11,13 +12,16 @@ module TerminalShop
|
|
11
12
|
|
12
13
|
class APIError < TerminalShop::Error
|
13
14
|
sig { returns(URI::Generic) }
|
14
|
-
|
15
|
+
def url
|
16
|
+
end
|
15
17
|
|
16
18
|
sig { returns(T.nilable(Integer)) }
|
17
|
-
|
19
|
+
def status
|
20
|
+
end
|
18
21
|
|
19
22
|
sig { returns(T.nilable(T.anything)) }
|
20
|
-
|
23
|
+
def body
|
24
|
+
end
|
21
25
|
|
22
26
|
sig do
|
23
27
|
params(
|
@@ -35,10 +39,12 @@ module TerminalShop
|
|
35
39
|
|
36
40
|
class APIConnectionError < TerminalShop::APIError
|
37
41
|
sig { void }
|
38
|
-
|
42
|
+
def status
|
43
|
+
end
|
39
44
|
|
40
45
|
sig { void }
|
41
|
-
|
46
|
+
def body
|
47
|
+
end
|
42
48
|
|
43
49
|
sig do
|
44
50
|
params(
|
@@ -83,7 +89,8 @@ module TerminalShop
|
|
83
89
|
end
|
84
90
|
|
85
91
|
sig { returns(Integer) }
|
86
|
-
|
92
|
+
def status
|
93
|
+
end
|
87
94
|
|
88
95
|
sig do
|
89
96
|
params(
|
@@ -4,40 +4,76 @@ module TerminalShop
|
|
4
4
|
module Models
|
5
5
|
class AddressAPI < TerminalShop::BaseModel
|
6
6
|
sig { returns(String) }
|
7
|
-
|
7
|
+
def id
|
8
|
+
end
|
9
|
+
|
10
|
+
sig { params(_: String).returns(String) }
|
11
|
+
def id=(_)
|
12
|
+
end
|
8
13
|
|
9
14
|
sig { returns(String) }
|
10
|
-
|
15
|
+
def city
|
16
|
+
end
|
17
|
+
|
18
|
+
sig { params(_: String).returns(String) }
|
19
|
+
def city=(_)
|
20
|
+
end
|
11
21
|
|
12
22
|
sig { returns(String) }
|
13
|
-
|
23
|
+
def country
|
24
|
+
end
|
25
|
+
|
26
|
+
sig { params(_: String).returns(String) }
|
27
|
+
def country=(_)
|
28
|
+
end
|
14
29
|
|
15
30
|
sig { returns(String) }
|
16
|
-
|
31
|
+
def name
|
32
|
+
end
|
33
|
+
|
34
|
+
sig { params(_: String).returns(String) }
|
35
|
+
def name=(_)
|
36
|
+
end
|
17
37
|
|
18
38
|
sig { returns(String) }
|
19
|
-
|
39
|
+
def street1
|
40
|
+
end
|
41
|
+
|
42
|
+
sig { params(_: String).returns(String) }
|
43
|
+
def street1=(_)
|
44
|
+
end
|
20
45
|
|
21
46
|
sig { returns(String) }
|
22
|
-
|
47
|
+
def zip
|
48
|
+
end
|
49
|
+
|
50
|
+
sig { params(_: String).returns(String) }
|
51
|
+
def zip=(_)
|
52
|
+
end
|
23
53
|
|
24
54
|
sig { returns(T.nilable(String)) }
|
25
|
-
|
55
|
+
def phone
|
56
|
+
end
|
26
57
|
|
27
|
-
sig { params(
|
28
|
-
|
58
|
+
sig { params(_: String).returns(String) }
|
59
|
+
def phone=(_)
|
60
|
+
end
|
29
61
|
|
30
62
|
sig { returns(T.nilable(String)) }
|
31
|
-
|
63
|
+
def province
|
64
|
+
end
|
32
65
|
|
33
|
-
sig { params(
|
34
|
-
|
66
|
+
sig { params(_: String).returns(String) }
|
67
|
+
def province=(_)
|
68
|
+
end
|
35
69
|
|
36
70
|
sig { returns(T.nilable(String)) }
|
37
|
-
|
71
|
+
def street2
|
72
|
+
end
|
38
73
|
|
39
|
-
sig { params(
|
40
|
-
|
74
|
+
sig { params(_: String).returns(String) }
|
75
|
+
def street2=(_)
|
76
|
+
end
|
41
77
|
|
42
78
|
sig do
|
43
79
|
params(
|
@@ -7,37 +7,68 @@ module TerminalShop
|
|
7
7
|
include TerminalShop::RequestParameters
|
8
8
|
|
9
9
|
sig { returns(String) }
|
10
|
-
|
10
|
+
def city
|
11
|
+
end
|
12
|
+
|
13
|
+
sig { params(_: String).returns(String) }
|
14
|
+
def city=(_)
|
15
|
+
end
|
11
16
|
|
12
17
|
sig { returns(String) }
|
13
|
-
|
18
|
+
def country
|
19
|
+
end
|
20
|
+
|
21
|
+
sig { params(_: String).returns(String) }
|
22
|
+
def country=(_)
|
23
|
+
end
|
14
24
|
|
15
25
|
sig { returns(String) }
|
16
|
-
|
26
|
+
def name
|
27
|
+
end
|
28
|
+
|
29
|
+
sig { params(_: String).returns(String) }
|
30
|
+
def name=(_)
|
31
|
+
end
|
17
32
|
|
18
33
|
sig { returns(String) }
|
19
|
-
|
34
|
+
def street1
|
35
|
+
end
|
36
|
+
|
37
|
+
sig { params(_: String).returns(String) }
|
38
|
+
def street1=(_)
|
39
|
+
end
|
20
40
|
|
21
41
|
sig { returns(String) }
|
22
|
-
|
42
|
+
def zip
|
43
|
+
end
|
44
|
+
|
45
|
+
sig { params(_: String).returns(String) }
|
46
|
+
def zip=(_)
|
47
|
+
end
|
23
48
|
|
24
49
|
sig { returns(T.nilable(String)) }
|
25
|
-
|
50
|
+
def phone
|
51
|
+
end
|
26
52
|
|
27
|
-
sig { params(
|
28
|
-
|
53
|
+
sig { params(_: String).returns(String) }
|
54
|
+
def phone=(_)
|
55
|
+
end
|
29
56
|
|
30
57
|
sig { returns(T.nilable(String)) }
|
31
|
-
|
58
|
+
def province
|
59
|
+
end
|
32
60
|
|
33
|
-
sig { params(
|
34
|
-
|
61
|
+
sig { params(_: String).returns(String) }
|
62
|
+
def province=(_)
|
63
|
+
end
|
35
64
|
|
36
65
|
sig { returns(T.nilable(String)) }
|
37
|
-
|
66
|
+
def street2
|
67
|
+
end
|
38
68
|
|
39
|
-
sig { params(
|
40
|
-
|
69
|
+
sig { params(_: String).returns(String) }
|
70
|
+
def street2=(_)
|
71
|
+
end
|
41
72
|
|
42
73
|
sig do
|
43
74
|
params(
|