terminal-shop 0.1.0.pre.alpha.7 → 0.1.0.pre.alpha.10
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/lib/terminal-shop/models/subscription.rb +11 -11
- data/lib/terminal-shop/pooled_net_requester.rb +69 -38
- data/lib/terminal-shop/resources/subscription.rb +1 -1
- data/lib/terminal-shop/version.rb +1 -1
- data/rbi/lib/terminal-shop/models/subscription.rbi +14 -14
- data/rbi/lib/terminal-shop/resources/subscription.rbi +2 -2
- data/rbi/lib/terminal-shop/version.rbi +1 -1
- data/sig/terminal-shop/models/subscription.rbs +11 -11
- 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: e49f5a72c701e7a5a68d1b537d9910a95d385966dcab6788a080c0d7cfefc503
|
4
|
+
data.tar.gz: c94a21a6fc772735aedd857c5f592b5ab0eb7344419814d593f7bec71b96b5e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b5237266009ebbfb3019971b882c5c92076931ee011fbad8023c8ac806a89bd58eeb1373aa38ee60374d8af66913bacd8f00afd5f809bec5e682cabdb70dced
|
7
|
+
data.tar.gz: 882c016a8b85b9ce829fb952eb63cccf295595f64c500863a8550243946e5164b0308af9699f618cfd768a812831d4d2953af97a1ef12c7e3dc3bc9ab0f5c8b8
|
@@ -63,11 +63,11 @@ module TerminalShop
|
|
63
63
|
# @!attribute [r] schedule
|
64
64
|
# Schedule of the subscription.
|
65
65
|
#
|
66
|
-
# @return [TerminalShop::Models::SubscriptionAPI::Schedule::
|
66
|
+
# @return [TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly, nil]
|
67
67
|
optional :schedule, union: -> { TerminalShop::Models::SubscriptionAPI::Schedule }
|
68
68
|
|
69
69
|
# @!parse
|
70
|
-
# # @return [TerminalShop::Models::SubscriptionAPI::Schedule::
|
70
|
+
# # @return [TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly]
|
71
71
|
# attr_writer :schedule
|
72
72
|
|
73
73
|
# @!parse
|
@@ -80,7 +80,7 @@ module TerminalShop
|
|
80
80
|
# # @param product_variant_id [String]
|
81
81
|
# # @param quantity [Integer]
|
82
82
|
# # @param next_ [String]
|
83
|
-
# # @param schedule [TerminalShop::Models::SubscriptionAPI::Schedule::
|
83
|
+
# # @param schedule [TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly]
|
84
84
|
# #
|
85
85
|
# def initialize(id:, address_id:, card_id:, frequency:, product_variant_id:, quantity:, next_: nil, schedule: nil, **) = super
|
86
86
|
|
@@ -127,24 +127,24 @@ module TerminalShop
|
|
127
127
|
# @example
|
128
128
|
# ```ruby
|
129
129
|
# case schedule
|
130
|
-
# in TerminalShop::Models::SubscriptionAPI::Schedule::
|
130
|
+
# in TerminalShop::Models::SubscriptionAPI::Schedule::Fixed
|
131
131
|
# # ...
|
132
|
-
# in TerminalShop::Models::SubscriptionAPI::Schedule::
|
132
|
+
# in TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
133
133
|
# # ...
|
134
134
|
# end
|
135
135
|
# ```
|
136
136
|
class Schedule < TerminalShop::Union
|
137
|
-
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::
|
137
|
+
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Fixed }
|
138
138
|
|
139
|
-
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::
|
139
|
+
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Weekly }
|
140
140
|
|
141
141
|
# @example
|
142
142
|
# ```ruby
|
143
|
-
#
|
143
|
+
# fixed => {
|
144
144
|
# type: :fixed
|
145
145
|
# }
|
146
146
|
# ```
|
147
|
-
class
|
147
|
+
class Fixed < TerminalShop::BaseModel
|
148
148
|
# @!attribute type
|
149
149
|
#
|
150
150
|
# @return [Symbol, :fixed]
|
@@ -160,12 +160,12 @@ module TerminalShop
|
|
160
160
|
|
161
161
|
# @example
|
162
162
|
# ```ruby
|
163
|
-
#
|
163
|
+
# weekly => {
|
164
164
|
# interval: Integer,
|
165
165
|
# type: :weekly
|
166
166
|
# }
|
167
167
|
# ```
|
168
|
-
class
|
168
|
+
class Weekly < TerminalShop::BaseModel
|
169
169
|
# @!attribute interval
|
170
170
|
#
|
171
171
|
# @return [Integer]
|
@@ -12,29 +12,58 @@ module TerminalShop
|
|
12
12
|
# @private
|
13
13
|
#
|
14
14
|
# @param url [URL::Generic]
|
15
|
-
# @param
|
15
|
+
# @param blk [Proc]
|
16
16
|
#
|
17
17
|
# @return [ConnectionPool]
|
18
18
|
#
|
19
|
-
private def
|
19
|
+
private def with_pool(url, &blk)
|
20
20
|
origin = TerminalShop::Util.uri_origin(url)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
key = :"#{self.class.name}-connection_in_use_for_#{origin}"
|
22
|
+
|
23
|
+
return blk.call(make_conn(url)) if Thread.current[key]
|
24
|
+
|
25
|
+
pool =
|
26
|
+
@mutex.synchronize do
|
27
|
+
@pools[origin] ||= ConnectionPool.new(size: Etc.nprocessors) do
|
28
|
+
make_conn(url)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
pool.with do |conn|
|
33
|
+
Thread.current[key] = true
|
34
|
+
|
35
|
+
blk.call(conn)
|
36
|
+
# rubocop:disable Lint/RescueException
|
37
|
+
rescue Exception => e
|
38
|
+
# rubocop:enable Lint/RescueException
|
39
|
+
# should close connection on all errors to ensure no invalid state persists
|
40
|
+
conn.finish if conn.started?
|
41
|
+
raise e
|
42
|
+
ensure
|
43
|
+
Thread.current[key] = nil
|
44
|
+
end
|
45
|
+
end
|
32
46
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
47
|
+
# @private
|
48
|
+
#
|
49
|
+
# @param url [URI::Generic]
|
50
|
+
#
|
51
|
+
# @return [Net::HTTP]
|
52
|
+
#
|
53
|
+
private def make_conn(url)
|
54
|
+
port =
|
55
|
+
case [url.port, url.scheme]
|
56
|
+
in [Integer, _]
|
57
|
+
url.port
|
58
|
+
in [nil, "http" | "ws"]
|
59
|
+
Net::HTTP.http_default_port
|
60
|
+
in [nil, "https" | "wss"]
|
61
|
+
Net::HTTP.https_default_port
|
37
62
|
end
|
63
|
+
|
64
|
+
Net::HTTP.new(url.host, port).tap do
|
65
|
+
_1.use_ssl = %w[https wss].include?(url.scheme)
|
66
|
+
_1.max_retries = 0
|
38
67
|
end
|
39
68
|
end
|
40
69
|
|
@@ -44,7 +73,7 @@ module TerminalShop
|
|
44
73
|
# @option req [Symbol] :method
|
45
74
|
# @option req [URI::Generic] :url
|
46
75
|
# @option req [Hash{String => String}] :headers
|
47
|
-
# @option req [String, Hash] :body
|
76
|
+
# @option req [String, Hash, IO, StringIO] :body
|
48
77
|
# @option req [Float] :timeout
|
49
78
|
#
|
50
79
|
# @return [Net::HTTPResponse]
|
@@ -55,7 +84,7 @@ module TerminalShop
|
|
55
84
|
request = Net::HTTPGenericRequest.new(
|
56
85
|
method.to_s.upcase,
|
57
86
|
!body.nil?,
|
58
|
-
|
87
|
+
method != :head,
|
59
88
|
url.to_s
|
60
89
|
)
|
61
90
|
|
@@ -67,28 +96,30 @@ module TerminalShop
|
|
67
96
|
request.body_stream = body
|
68
97
|
end
|
69
98
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
99
|
+
with_pool(url) do |conn|
|
100
|
+
make_request(conn, request, timeout)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# @private
|
105
|
+
#
|
106
|
+
# @param conn [Net::HTTP]
|
107
|
+
# @param request [Net::HTTPGenericRequest]
|
108
|
+
# @param timeout [Float]
|
109
|
+
#
|
110
|
+
# @return [Net::HTTPResponse]
|
111
|
+
#
|
112
|
+
private def make_request(conn, request, timeout)
|
113
|
+
unless conn.started?
|
75
114
|
conn.open_timeout = timeout
|
76
|
-
conn.
|
77
|
-
|
78
|
-
conn.continue_timeout = timeout
|
115
|
+
conn.start
|
116
|
+
end
|
79
117
|
|
80
|
-
|
118
|
+
conn.read_timeout = timeout
|
119
|
+
conn.write_timeout = timeout
|
120
|
+
conn.continue_timeout = timeout
|
81
121
|
|
82
|
-
|
83
|
-
# rubocop:disable Lint/RescueException
|
84
|
-
rescue Exception => e
|
85
|
-
# rubocop:enable Lint/RescueException
|
86
|
-
# should close connection on all errors to ensure no invalid state persists
|
87
|
-
conn.finish if conn.started?
|
88
|
-
raise e
|
89
|
-
end
|
90
|
-
rescue ConnectionPool::TimeoutError
|
91
|
-
raise TerminalShop::APITimeoutError.new(url: url)
|
122
|
+
conn.request(request)
|
92
123
|
end
|
93
124
|
end
|
94
125
|
end
|
@@ -21,7 +21,7 @@ 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::
|
24
|
+
# @option params [TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly] :schedule Schedule of the subscription.
|
25
25
|
#
|
26
26
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
27
27
|
#
|
@@ -63,8 +63,8 @@ module TerminalShop
|
|
63
63
|
returns(
|
64
64
|
T.nilable(
|
65
65
|
T.any(
|
66
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
67
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
66
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Fixed,
|
67
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
68
68
|
)
|
69
69
|
)
|
70
70
|
)
|
@@ -75,12 +75,12 @@ module TerminalShop
|
|
75
75
|
sig do
|
76
76
|
params(
|
77
77
|
_: T.any(
|
78
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
79
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
78
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Fixed,
|
79
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
80
80
|
)
|
81
81
|
).returns(T.any(
|
82
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
83
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
82
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Fixed,
|
83
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
84
84
|
))
|
85
85
|
end
|
86
86
|
def schedule=(_)
|
@@ -96,8 +96,8 @@ module TerminalShop
|
|
96
96
|
quantity: Integer,
|
97
97
|
next_: String,
|
98
98
|
schedule: T.any(
|
99
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
100
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
99
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Fixed,
|
100
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
101
101
|
)
|
102
102
|
).void
|
103
103
|
end
|
@@ -124,8 +124,8 @@ module TerminalShop
|
|
124
124
|
quantity: Integer,
|
125
125
|
next_: String,
|
126
126
|
schedule: T.any(
|
127
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
128
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
127
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Fixed,
|
128
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
129
129
|
)
|
130
130
|
}
|
131
131
|
)
|
@@ -150,7 +150,7 @@ module TerminalShop
|
|
150
150
|
class Schedule < TerminalShop::Union
|
151
151
|
abstract!
|
152
152
|
|
153
|
-
class
|
153
|
+
class Fixed < TerminalShop::BaseModel
|
154
154
|
sig { returns(Symbol) }
|
155
155
|
def type
|
156
156
|
end
|
@@ -168,7 +168,7 @@ module TerminalShop
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
-
class
|
171
|
+
class Weekly < TerminalShop::BaseModel
|
172
172
|
sig { returns(Integer) }
|
173
173
|
def interval
|
174
174
|
end
|
@@ -197,8 +197,8 @@ module TerminalShop
|
|
197
197
|
sig do
|
198
198
|
override.returns(
|
199
199
|
[
|
200
|
-
[NilClass, TerminalShop::Models::SubscriptionAPI::Schedule::
|
201
|
-
[NilClass, TerminalShop::Models::SubscriptionAPI::Schedule::
|
200
|
+
[NilClass, TerminalShop::Models::SubscriptionAPI::Schedule::Fixed],
|
201
|
+
[NilClass, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly]
|
202
202
|
]
|
203
203
|
)
|
204
204
|
end
|
@@ -13,8 +13,8 @@ module TerminalShop
|
|
13
13
|
quantity: Integer,
|
14
14
|
next_: String,
|
15
15
|
schedule: T.any(
|
16
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
17
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
16
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Fixed,
|
17
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
18
18
|
),
|
19
19
|
request_options: T.nilable(T.any(TerminalShop::RequestOptions, T::Hash[Symbol, T.anything]))
|
20
20
|
).returns(TerminalShop::Models::SubscriptionCreateResponse)
|
@@ -65,28 +65,28 @@ module TerminalShop
|
|
65
65
|
end
|
66
66
|
|
67
67
|
type schedule =
|
68
|
-
TerminalShop::Models::SubscriptionAPI::Schedule::
|
69
|
-
| TerminalShop::Models::SubscriptionAPI::Schedule::
|
68
|
+
TerminalShop::Models::SubscriptionAPI::Schedule::Fixed
|
69
|
+
| TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
70
70
|
|
71
71
|
class Schedule < TerminalShop::Union
|
72
|
-
type
|
72
|
+
type fixed = { type: :fixed }
|
73
73
|
|
74
|
-
class
|
74
|
+
class Fixed < TerminalShop::BaseModel
|
75
75
|
attr_accessor type: :fixed
|
76
76
|
|
77
77
|
def initialize:
|
78
78
|
(type: :fixed) -> void
|
79
79
|
| (
|
80
|
-
?TerminalShop::Models::SubscriptionAPI::Schedule::
|
80
|
+
?TerminalShop::Models::SubscriptionAPI::Schedule::fixed
|
81
81
|
| TerminalShop::BaseModel data
|
82
82
|
) -> void
|
83
83
|
|
84
|
-
def to_hash: -> TerminalShop::Models::SubscriptionAPI::Schedule::
|
84
|
+
def to_hash: -> TerminalShop::Models::SubscriptionAPI::Schedule::fixed
|
85
85
|
end
|
86
86
|
|
87
|
-
type
|
87
|
+
type weekly = { interval: Integer, type: :weekly }
|
88
88
|
|
89
|
-
class
|
89
|
+
class Weekly < TerminalShop::BaseModel
|
90
90
|
attr_accessor interval: Integer
|
91
91
|
|
92
92
|
attr_accessor type: :weekly
|
@@ -94,14 +94,14 @@ module TerminalShop
|
|
94
94
|
def initialize:
|
95
95
|
(interval: Integer, type: :weekly) -> void
|
96
96
|
| (
|
97
|
-
?TerminalShop::Models::SubscriptionAPI::Schedule::
|
97
|
+
?TerminalShop::Models::SubscriptionAPI::Schedule::weekly
|
98
98
|
| TerminalShop::BaseModel data
|
99
99
|
) -> void
|
100
100
|
|
101
|
-
def to_hash: -> TerminalShop::Models::SubscriptionAPI::Schedule::
|
101
|
+
def to_hash: -> TerminalShop::Models::SubscriptionAPI::Schedule::weekly
|
102
102
|
end
|
103
103
|
|
104
|
-
private def self.variants: -> [[nil, TerminalShop::Models::SubscriptionAPI::Schedule::
|
104
|
+
private def self.variants: -> [[nil, TerminalShop::Models::SubscriptionAPI::Schedule::Fixed], [nil, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly]]
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terminal-shop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.alpha.
|
4
|
+
version: 0.1.0.pre.alpha.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Terminal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|