terminal-shop 1.8.0 → 2.0.0
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 +14 -0
- data/lib/terminal-shop/base_client.rb +11 -10
- data/lib/terminal-shop/base_model.rb +257 -244
- data/lib/terminal-shop/base_page.rb +19 -20
- data/lib/terminal-shop/client.rb +1 -0
- data/lib/terminal-shop/models/product.rb +7 -3
- data/lib/terminal-shop/models/region.rb +7 -3
- data/lib/terminal-shop/models/subscription.rb +5 -7
- data/lib/terminal-shop/pooled_net_requester.rb +12 -1
- data/lib/terminal-shop/request_options.rb +1 -1
- data/lib/terminal-shop/util.rb +16 -7
- data/lib/terminal-shop/version.rb +1 -1
- data/lib/terminal-shop.rb +15 -0
- data/rbi/lib/terminal-shop/base_client.rbi +40 -41
- data/rbi/lib/terminal-shop/base_model.rbi +139 -116
- data/rbi/lib/terminal-shop/base_page.rbi +0 -2
- data/rbi/lib/terminal-shop/client.rbi +18 -30
- data/rbi/lib/terminal-shop/errors.rbi +7 -42
- data/rbi/lib/terminal-shop/models/address.rbi +15 -51
- data/rbi/lib/terminal-shop/models/address_create_params.rbi +15 -46
- data/rbi/lib/terminal-shop/models/address_create_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/address_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/address_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/address_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/address_get_response.rbi +7 -6
- data/rbi/lib/terminal-shop/models/address_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/address_list_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/app.rbi +4 -24
- data/rbi/lib/terminal-shop/models/app_create_params.rbi +3 -13
- data/rbi/lib/terminal-shop/models/app_create_response.rbi +8 -20
- data/rbi/lib/terminal-shop/models/app_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/app_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/app_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/app_get_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/app_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/app_list_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/card.rbi +14 -36
- data/rbi/lib/terminal-shop/models/card_collect_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/card_collect_response.rbi +7 -14
- data/rbi/lib/terminal-shop/models/card_create_params.rbi +2 -7
- data/rbi/lib/terminal-shop/models/card_create_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/card_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/card_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/card_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/card_get_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/card_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/card_list_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/cart.rbi +34 -88
- data/rbi/lib/terminal-shop/models/cart_clear_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/cart_clear_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/cart_convert_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/cart_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/cart_get_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +2 -7
- data/rbi/lib/terminal-shop/models/cart_set_address_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +2 -7
- data/rbi/lib/terminal-shop/models/cart_set_card_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +3 -13
- data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/email_create_params.rbi +2 -7
- data/rbi/lib/terminal-shop/models/email_create_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/order.rbi +52 -139
- data/rbi/lib/terminal-shop/models/order_create_params.rbi +4 -19
- data/rbi/lib/terminal-shop/models/order_create_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/order_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/order_get_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/order_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/order_list_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/product.rbi +43 -77
- data/rbi/lib/terminal-shop/models/product_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/product_get_response.rbi +7 -6
- data/rbi/lib/terminal-shop/models/product_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/product_list_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/product_variant.rbi +3 -18
- data/rbi/lib/terminal-shop/models/profile.rbi +12 -36
- data/rbi/lib/terminal-shop/models/profile_me_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/profile_me_response.rbi +7 -6
- data/rbi/lib/terminal-shop/models/profile_update_params.rbi +3 -13
- data/rbi/lib/terminal-shop/models/profile_update_response.rbi +7 -6
- data/rbi/lib/terminal-shop/models/region.rbi +10 -5
- data/rbi/lib/terminal-shop/models/subscription.rbi +28 -75
- data/rbi/lib/terminal-shop/models/subscription_create_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/subscription_create_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/subscription_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/subscription_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/subscription_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/subscription_get_response.rbi +7 -6
- data/rbi/lib/terminal-shop/models/subscription_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +3 -8
- data/rbi/lib/terminal-shop/models/token.rbi +3 -18
- data/rbi/lib/terminal-shop/models/token_create_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/token_create_response.rbi +8 -20
- data/rbi/lib/terminal-shop/models/token_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/token_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/token_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/token_get_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/token_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/token_list_response.rbi +4 -6
- data/rbi/lib/terminal-shop/models/view_init_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/view_init_response.rbi +32 -81
- data/rbi/lib/terminal-shop/pooled_net_requester.rbi +14 -3
- data/rbi/lib/terminal-shop/request_options.rbi +11 -55
- data/rbi/lib/terminal-shop/resources/address.rbi +4 -4
- data/rbi/lib/terminal-shop/resources/app.rbi +4 -4
- data/rbi/lib/terminal-shop/resources/card.rbi +5 -5
- data/rbi/lib/terminal-shop/resources/cart.rbi +6 -6
- data/rbi/lib/terminal-shop/resources/email.rbi +1 -1
- data/rbi/lib/terminal-shop/resources/order.rbi +3 -3
- data/rbi/lib/terminal-shop/resources/product.rbi +2 -2
- data/rbi/lib/terminal-shop/resources/profile.rbi +2 -2
- data/rbi/lib/terminal-shop/resources/subscription.rbi +5 -4
- data/rbi/lib/terminal-shop/resources/token.rbi +4 -4
- data/rbi/lib/terminal-shop/resources/view.rbi +1 -1
- data/rbi/lib/terminal-shop/util.rbi +24 -13
- data/rbi/lib/terminal-shop/version.rbi +1 -1
- data/sig/terminal-shop/base_client.rbs +14 -14
- data/sig/terminal-shop/base_model.rbs +34 -18
- data/sig/terminal-shop/client.rbs +8 -8
- data/sig/terminal-shop/errors.rbs +17 -17
- data/sig/terminal-shop/models/address.rbs +11 -15
- data/sig/terminal-shop/models/address_create_params.rbs +11 -16
- data/sig/terminal-shop/models/address_create_response.rbs +1 -6
- data/sig/terminal-shop/models/address_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/address_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/address_get_params.rbs +1 -6
- data/sig/terminal-shop/models/address_get_response.rbs +1 -6
- data/sig/terminal-shop/models/address_list_params.rbs +1 -6
- data/sig/terminal-shop/models/address_list_response.rbs +1 -6
- data/sig/terminal-shop/models/app.rbs +6 -5
- data/sig/terminal-shop/models/app_create_params.rbs +5 -10
- data/sig/terminal-shop/models/app_create_response.rbs +4 -12
- data/sig/terminal-shop/models/app_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/app_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/app_get_params.rbs +1 -5
- data/sig/terminal-shop/models/app_get_response.rbs +1 -5
- data/sig/terminal-shop/models/app_list_params.rbs +1 -5
- data/sig/terminal-shop/models/app_list_response.rbs +1 -6
- data/sig/terminal-shop/models/card.rbs +7 -16
- data/sig/terminal-shop/models/card_collect_params.rbs +1 -6
- data/sig/terminal-shop/models/card_collect_response.rbs +4 -12
- data/sig/terminal-shop/models/card_create_params.rbs +4 -6
- data/sig/terminal-shop/models/card_create_response.rbs +1 -6
- data/sig/terminal-shop/models/card_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/card_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/card_get_params.rbs +1 -5
- data/sig/terminal-shop/models/card_get_response.rbs +1 -6
- data/sig/terminal-shop/models/card_list_params.rbs +1 -5
- data/sig/terminal-shop/models/card_list_response.rbs +1 -6
- data/sig/terminal-shop/models/cart.rbs +20 -34
- data/sig/terminal-shop/models/cart_clear_params.rbs +1 -6
- data/sig/terminal-shop/models/cart_clear_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_convert_params.rbs +1 -6
- data/sig/terminal-shop/models/cart_convert_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_get_params.rbs +1 -5
- data/sig/terminal-shop/models/cart_get_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_set_address_params.rbs +4 -9
- data/sig/terminal-shop/models/cart_set_address_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_set_card_params.rbs +4 -6
- data/sig/terminal-shop/models/cart_set_card_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_set_item_params.rbs +5 -10
- data/sig/terminal-shop/models/cart_set_item_response.rbs +1 -6
- data/sig/terminal-shop/models/email_create_params.rbs +4 -6
- data/sig/terminal-shop/models/email_create_response.rbs +1 -6
- data/sig/terminal-shop/models/order.rbs +31 -50
- data/sig/terminal-shop/models/order_create_params.rbs +6 -11
- data/sig/terminal-shop/models/order_create_response.rbs +1 -6
- data/sig/terminal-shop/models/order_get_params.rbs +1 -5
- data/sig/terminal-shop/models/order_get_response.rbs +1 -6
- data/sig/terminal-shop/models/order_list_params.rbs +1 -6
- data/sig/terminal-shop/models/order_list_response.rbs +1 -6
- data/sig/terminal-shop/models/product.rbs +20 -27
- data/sig/terminal-shop/models/product_get_params.rbs +1 -6
- data/sig/terminal-shop/models/product_get_response.rbs +1 -6
- data/sig/terminal-shop/models/product_list_params.rbs +1 -6
- data/sig/terminal-shop/models/product_list_response.rbs +1 -6
- data/sig/terminal-shop/models/product_variant.rbs +1 -5
- data/sig/terminal-shop/models/profile.rbs +8 -17
- data/sig/terminal-shop/models/profile_me_params.rbs +1 -6
- data/sig/terminal-shop/models/profile_me_response.rbs +1 -6
- data/sig/terminal-shop/models/profile_update_params.rbs +5 -10
- data/sig/terminal-shop/models/profile_update_response.rbs +1 -6
- data/sig/terminal-shop/models/region.rbs +4 -2
- data/sig/terminal-shop/models/subscription.rbs +15 -27
- data/sig/terminal-shop/models/subscription_create_params.rbs +1 -6
- data/sig/terminal-shop/models/subscription_create_response.rbs +1 -6
- data/sig/terminal-shop/models/subscription_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/subscription_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/subscription_get_params.rbs +1 -6
- data/sig/terminal-shop/models/subscription_get_response.rbs +1 -6
- data/sig/terminal-shop/models/subscription_list_params.rbs +1 -6
- data/sig/terminal-shop/models/subscription_list_response.rbs +3 -6
- data/sig/terminal-shop/models/token.rbs +1 -5
- data/sig/terminal-shop/models/token_create_params.rbs +1 -6
- data/sig/terminal-shop/models/token_create_response.rbs +4 -12
- data/sig/terminal-shop/models/token_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/token_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/token_get_params.rbs +1 -5
- data/sig/terminal-shop/models/token_get_response.rbs +1 -6
- data/sig/terminal-shop/models/token_list_params.rbs +1 -6
- data/sig/terminal-shop/models/token_list_response.rbs +1 -6
- data/sig/terminal-shop/models/view_init_params.rbs +1 -5
- data/sig/terminal-shop/models/view_init_response.rbs +15 -23
- data/sig/terminal-shop/pooled_net_requester.rbs +3 -1
- data/sig/terminal-shop/request_options.rbs +2 -2
- data/sig/terminal-shop/resources/address.rbs +22 -41
- data/sig/terminal-shop/resources/app.rbs +16 -34
- data/sig/terminal-shop/resources/card.rbs +18 -40
- data/sig/terminal-shop/resources/cart.rbs +22 -47
- data/sig/terminal-shop/resources/email.rbs +4 -8
- data/sig/terminal-shop/resources/order.rbs +13 -26
- data/sig/terminal-shop/resources/product.rbs +7 -16
- data/sig/terminal-shop/resources/profile.rbs +8 -16
- data/sig/terminal-shop/resources/subscription.rbs +21 -43
- data/sig/terminal-shop/resources/token.rbs +14 -32
- data/sig/terminal-shop/resources/view.rbs +3 -7
- data/sig/terminal-shop/util.rbs +5 -5
- data/sig/terminal-shop/version.rbs +1 -1
- metadata +2 -2
@@ -2,32 +2,29 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
# @example
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# end
|
9
|
-
# ```
|
5
|
+
# if page.has_next?
|
6
|
+
# page = page.next_page
|
7
|
+
# end
|
10
8
|
#
|
11
9
|
# @example
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# end
|
16
|
-
# ```
|
10
|
+
# page.auto_paging_each do |product|
|
11
|
+
# puts(product)
|
12
|
+
# end
|
17
13
|
#
|
18
14
|
# @example
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
15
|
+
# products =
|
16
|
+
# page
|
17
|
+
# .to_enum
|
18
|
+
# .lazy
|
19
|
+
# .select { _1.object_id.even? }
|
20
|
+
# .map(&:itself)
|
21
|
+
# .take(2)
|
22
|
+
# .to_a
|
27
23
|
#
|
28
|
-
#
|
29
|
-
# ```
|
24
|
+
# products => Array
|
30
25
|
module BasePage
|
26
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
27
|
+
|
31
28
|
# @return [Boolean]
|
32
29
|
def next_page? = (raise NotImplementedError)
|
33
30
|
|
@@ -56,5 +53,7 @@ module TerminalShop
|
|
56
53
|
@req = req
|
57
54
|
super()
|
58
55
|
end
|
56
|
+
|
57
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
59
58
|
end
|
60
59
|
end
|
data/lib/terminal-shop/client.rb
CHANGED
@@ -16,6 +16,7 @@ module TerminalShop
|
|
16
16
|
DEFAULT_MAX_RETRY_DELAY = 8.0
|
17
17
|
|
18
18
|
# rubocop:disable Style/MutableConstant
|
19
|
+
# @type [Hash{Symbol=>String}]
|
19
20
|
ENVIRONMENTS = {production: "https://api.terminal.shop/", dev: "https://api.dev.terminal.shop/"}
|
20
21
|
# rubocop:enable Style/MutableConstant
|
21
22
|
|
@@ -72,14 +72,18 @@ module TerminalShop
|
|
72
72
|
|
73
73
|
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
74
74
|
|
75
|
-
# @abstract
|
76
|
-
#
|
77
75
|
# Whether the product must be or can be subscribed to.
|
78
|
-
|
76
|
+
module Subscription
|
77
|
+
extend TerminalShop::Enum
|
78
|
+
|
79
79
|
ALLOWED = :allowed
|
80
80
|
REQUIRED = :required
|
81
81
|
|
82
82
|
finalize!
|
83
|
+
|
84
|
+
# @!parse
|
85
|
+
# # @return [Array<Symbol>]
|
86
|
+
# def self.values; end
|
83
87
|
end
|
84
88
|
|
85
89
|
class Tags < TerminalShop::BaseModel
|
@@ -2,14 +2,18 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
module Models
|
5
|
-
# @abstract
|
6
|
-
#
|
7
5
|
# A Terminal shop user's region.
|
8
|
-
|
6
|
+
module Region
|
7
|
+
extend TerminalShop::Enum
|
8
|
+
|
9
9
|
EU = :eu
|
10
10
|
NA = :na
|
11
11
|
|
12
12
|
finalize!
|
13
|
+
|
14
|
+
# @!parse
|
15
|
+
# # @return [Array<Symbol>]
|
16
|
+
# def self.values; end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -68,10 +68,10 @@ module TerminalShop
|
|
68
68
|
|
69
69
|
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
70
70
|
|
71
|
-
# @abstract
|
72
|
-
#
|
73
71
|
# Schedule of the subscription.
|
74
|
-
|
72
|
+
module Schedule
|
73
|
+
extend TerminalShop::Union
|
74
|
+
|
75
75
|
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Fixed }
|
76
76
|
|
77
77
|
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Weekly }
|
@@ -111,10 +111,8 @@ module TerminalShop
|
|
111
111
|
end
|
112
112
|
|
113
113
|
# @!parse
|
114
|
-
#
|
115
|
-
#
|
116
|
-
# def variants; end
|
117
|
-
# end
|
114
|
+
# # @return [Array(TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly)]
|
115
|
+
# def self.variants; end
|
118
116
|
end
|
119
117
|
end
|
120
118
|
end
|
@@ -3,6 +3,10 @@
|
|
3
3
|
module TerminalShop
|
4
4
|
# @api private
|
5
5
|
class PooledNetRequester
|
6
|
+
# from the golang stdlib
|
7
|
+
# https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
|
8
|
+
KEEP_ALIVE_TIMEOUT = 30
|
9
|
+
|
6
10
|
class << self
|
7
11
|
# @api private
|
8
12
|
#
|
@@ -47,6 +51,7 @@ module TerminalShop
|
|
47
51
|
#
|
48
52
|
# @param blk [Proc]
|
49
53
|
#
|
54
|
+
# @yieldparam [String]
|
50
55
|
# @return [Net::HTTPGenericRequest]
|
51
56
|
def build_request(request, &)
|
52
57
|
method, url, headers, body = request.fetch_values(:method, :url, :headers, :body)
|
@@ -82,6 +87,9 @@ module TerminalShop
|
|
82
87
|
# @param url [URI::Generic]
|
83
88
|
# @param deadline [Float]
|
84
89
|
# @param blk [Proc]
|
90
|
+
#
|
91
|
+
# @raise [Timeout::Error]
|
92
|
+
# @yieldparam [Net::HTTP]
|
85
93
|
private def with_pool(url, deadline:, &blk)
|
86
94
|
origin = TerminalShop::Util.uri_origin(url)
|
87
95
|
timeout = deadline - TerminalShop::Util.monotonic_secs
|
@@ -124,7 +132,10 @@ module TerminalShop
|
|
124
132
|
end
|
125
133
|
|
126
134
|
self.class.calibrate_socket_timeout(conn, deadline)
|
127
|
-
|
135
|
+
unless conn.started?
|
136
|
+
conn.keep_alive_timeout = self.class::KEEP_ALIVE_TIMEOUT
|
137
|
+
conn.start
|
138
|
+
end
|
128
139
|
|
129
140
|
self.class.calibrate_socket_timeout(conn, deadline)
|
130
141
|
conn.request(req) do |rsp|
|
@@ -83,7 +83,7 @@ module TerminalShop
|
|
83
83
|
# Extra data to send with the request. These are deep merged into any data
|
84
84
|
# generated as part of the normal request.
|
85
85
|
#
|
86
|
-
# @return [
|
86
|
+
# @return [Object, nil]
|
87
87
|
optional :extra_body, TerminalShop::HashOf[TerminalShop::Unknown]
|
88
88
|
|
89
89
|
# @!attribute max_retries
|
data/lib/terminal-shop/util.rb
CHANGED
@@ -367,13 +367,14 @@ module TerminalShop
|
|
367
367
|
# @return [Hash{String=>String}]
|
368
368
|
def normalized_headers(*headers)
|
369
369
|
{}.merge(*headers.compact).to_h do |key, val|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
370
|
+
value =
|
371
|
+
case val
|
372
|
+
in Array
|
373
|
+
val.map { _1.to_s.strip }.join(", ")
|
374
|
+
else
|
375
|
+
val&.to_s&.strip
|
376
|
+
end
|
377
|
+
[key.downcase, value]
|
377
378
|
end
|
378
379
|
end
|
379
380
|
end
|
@@ -428,6 +429,8 @@ module TerminalShop
|
|
428
429
|
#
|
429
430
|
# @param stream [String, IO, StringIO, Enumerable]
|
430
431
|
# @param blk [Proc]
|
432
|
+
#
|
433
|
+
# @yieldparam [String]
|
431
434
|
def initialize(stream, &blk)
|
432
435
|
@stream = stream.is_a?(String) ? StringIO.new(stream) : stream
|
433
436
|
@buf = String.new.b
|
@@ -438,6 +441,7 @@ module TerminalShop
|
|
438
441
|
class << self
|
439
442
|
# @param blk [Proc]
|
440
443
|
#
|
444
|
+
# @yieldparam [Enumerator::Yielder]
|
441
445
|
# @return [Enumerable]
|
442
446
|
def string_io(&blk)
|
443
447
|
Enumerator.new do |y|
|
@@ -452,6 +456,8 @@ module TerminalShop
|
|
452
456
|
end
|
453
457
|
|
454
458
|
class << self
|
459
|
+
# rubocop:disable Naming/MethodParameterName
|
460
|
+
|
455
461
|
# @api private
|
456
462
|
#
|
457
463
|
# @param y [Enumerator::Yielder]
|
@@ -490,6 +496,8 @@ module TerminalShop
|
|
490
496
|
y << "\r\n"
|
491
497
|
end
|
492
498
|
|
499
|
+
# rubocop:enable Naming/MethodParameterName
|
500
|
+
|
493
501
|
# @api private
|
494
502
|
#
|
495
503
|
# @param body [Object]
|
@@ -628,6 +636,7 @@ module TerminalShop
|
|
628
636
|
# @param enum [Enumerable, nil]
|
629
637
|
# @param blk [Proc]
|
630
638
|
#
|
639
|
+
# @yieldparam [Enumerator::Yielder]
|
631
640
|
# @return [Enumerable]
|
632
641
|
def chain_fused(enum, &blk)
|
633
642
|
iter = Enumerator.new { blk.call(_1) }
|
data/lib/terminal-shop.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# We already ship the preferred sorbet manifests in the package itself.
|
4
|
+
# `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
|
5
|
+
if Object.const_defined?(:Tapioca) && caller_locations.any? { _1.path.end_with?("tapioca/cli.rb") }
|
6
|
+
Warning.warn(
|
7
|
+
<<~WARN
|
8
|
+
\n
|
9
|
+
⚠️ skipped loading of "terminal-shop" gem under `tapioca`.
|
10
|
+
|
11
|
+
This message is normal and expected if you are running a `tapioca` command, and does not impact `.rbi` generation.
|
12
|
+
\n
|
13
|
+
WARN
|
14
|
+
)
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
3
18
|
# Standard libraries.
|
4
19
|
require "cgi"
|
5
20
|
require "date"
|
@@ -5,41 +5,44 @@ module TerminalShop
|
|
5
5
|
class BaseClient
|
6
6
|
abstract!
|
7
7
|
|
8
|
-
RequestComponentsShape =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
T
|
15
|
-
|
16
|
-
T.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
8
|
+
RequestComponentsShape =
|
9
|
+
T.type_alias do
|
10
|
+
{
|
11
|
+
method: Symbol,
|
12
|
+
path: T.any(String, T::Array[String]),
|
13
|
+
query: T.nilable(T::Hash[String, T.nilable(T.any(T::Array[String], String))]),
|
14
|
+
headers: T.nilable(
|
15
|
+
T::Hash[String,
|
16
|
+
T.nilable(
|
17
|
+
T.any(
|
18
|
+
String,
|
19
|
+
Integer,
|
20
|
+
T::Array[T.nilable(T.any(String, Integer))]
|
21
|
+
)
|
22
|
+
)]
|
23
|
+
),
|
24
|
+
body: T.nilable(T.anything),
|
25
|
+
unwrap: T.nilable(Symbol),
|
26
|
+
page: T.nilable(T::Class[TerminalShop::BasePage[TerminalShop::BaseModel]]),
|
27
|
+
stream: T.nilable(T::Class[T.anything]),
|
28
|
+
model: T.nilable(TerminalShop::Converter::Input),
|
29
|
+
options: T.nilable(T.any(TerminalShop::RequestOptions, TerminalShop::Util::AnyHash))
|
30
|
+
}
|
31
|
+
end
|
31
32
|
|
32
|
-
RequestInputShape =
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
RequestInputShape =
|
34
|
+
T.type_alias do
|
35
|
+
{
|
36
|
+
method: Symbol,
|
37
|
+
url: URI::Generic,
|
38
|
+
headers: T::Hash[String, String],
|
39
|
+
body: T.anything,
|
40
|
+
max_retries: Integer,
|
41
|
+
timeout: Float
|
42
|
+
}
|
43
|
+
end
|
42
44
|
|
45
|
+
# from whatwg fetch spec
|
43
46
|
MAX_REDIRECTS = 20
|
44
47
|
|
45
48
|
PLATFORM_HEADERS = T::Hash[String, String]
|
@@ -81,13 +84,9 @@ module TerminalShop
|
|
81
84
|
end
|
82
85
|
end
|
83
86
|
|
87
|
+
# @api private
|
84
88
|
sig { returns(T.anything) }
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
sig { params(_: T.anything).returns(T.anything) }
|
89
|
-
def requester=(_)
|
90
|
-
end
|
89
|
+
attr_accessor :requester
|
91
90
|
|
92
91
|
# @api private
|
93
92
|
sig do
|
@@ -127,7 +126,7 @@ module TerminalShop
|
|
127
126
|
# @api private
|
128
127
|
sig do
|
129
128
|
overridable
|
130
|
-
.params(req: TerminalShop::BaseClient::RequestComponentsShape, opts:
|
129
|
+
.params(req: TerminalShop::BaseClient::RequestComponentsShape, opts: TerminalShop::Util::AnyHash)
|
131
130
|
.returns(TerminalShop::BaseClient::RequestInputShape)
|
132
131
|
end
|
133
132
|
private def build_request(req, opts)
|
@@ -173,7 +172,7 @@ module TerminalShop
|
|
173
172
|
page: T.nilable(T::Class[TerminalShop::BasePage[TerminalShop::BaseModel]]),
|
174
173
|
stream: T.nilable(T::Class[T.anything]),
|
175
174
|
model: T.nilable(TerminalShop::Converter::Input),
|
176
|
-
options: T.nilable(T.any(TerminalShop::RequestOptions,
|
175
|
+
options: T.nilable(T.any(TerminalShop::RequestOptions, TerminalShop::Util::AnyHash))
|
177
176
|
)
|
178
177
|
.returns(T.anything)
|
179
178
|
end
|