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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c35020e82a26bf26e9c0f7ca2926f00db9a43f10767c0e21fd61442e68bb07cf
4
- data.tar.gz: 56a1434608c6c18d12aaa9d926bc67206b6334e9fc42a4f7e3dbfd072da36d41
3
+ metadata.gz: e49f5a72c701e7a5a68d1b537d9910a95d385966dcab6788a080c0d7cfefc503
4
+ data.tar.gz: c94a21a6fc772735aedd857c5f592b5ab0eb7344419814d593f7bec71b96b5e5
5
5
  SHA512:
6
- metadata.gz: a20785d886ae90219e648ad6cd65fbd0366aea77fc73c702db96e7327e2b039e4772f1eaaef423e3e75c47547d012e335a19f7fa16483aa69376ccf13a371075
7
- data.tar.gz: 5a84296c9dcb1868cd6f662bf8a34e067162fce60c9344957cac63bc3ad7473f36abb63d7a3e2db741ddd00967a6eb42d04bc2e7378a6cecbc94d791105770f5
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::Type, TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1, nil]
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::Type, TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1]
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::Type, TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1]
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::Type
130
+ # in TerminalShop::Models::SubscriptionAPI::Schedule::Fixed
131
131
  # # ...
132
- # in TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1
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::Type }
137
+ variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Fixed }
138
138
 
139
- variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1 }
139
+ variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Weekly }
140
140
 
141
141
  # @example
142
142
  # ```ruby
143
- # type => {
143
+ # fixed => {
144
144
  # type: :fixed
145
145
  # }
146
146
  # ```
147
- class Type < TerminalShop::BaseModel
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
- # union_member1 => {
163
+ # weekly => {
164
164
  # interval: Integer,
165
165
  # type: :weekly
166
166
  # }
167
167
  # ```
168
- class UnionMember1 < TerminalShop::BaseModel
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 timeout [Float]
15
+ # @param blk [Proc]
16
16
  #
17
17
  # @return [ConnectionPool]
18
18
  #
19
- private def get_pool(url)
19
+ private def with_pool(url, &blk)
20
20
  origin = TerminalShop::Util.uri_origin(url)
21
- @mutex.synchronize do
22
- @pools[origin] ||= ConnectionPool.new(size: Etc.nprocessors) do
23
- port =
24
- case [url.port, url.scheme]
25
- in [Integer, _]
26
- url.port
27
- in [nil, "http" | "ws"]
28
- Net::HTTP.http_default_port
29
- in [nil, "https" | "wss"]
30
- Net::HTTP.https_default_port
31
- end
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
- session = Net::HTTP.new(url.host, port)
34
- session.use_ssl = %w[https wss].include?(url.scheme)
35
- session.max_retries = 0
36
- session
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
- ![:head, :options].include?(method),
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
- # This timeout is for acquiring a connection from the pool
71
- # The default 5 seconds seems too short, lets just have a nearly unbounded queue for now
72
- #
73
- # TODO: revisit this around granular timeout / concurrency control
74
- get_pool(url).with(timeout: 600) do |conn|
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.read_timeout = timeout
77
- conn.write_timeout = timeout
78
- conn.continue_timeout = timeout
115
+ conn.start
116
+ end
79
117
 
80
- conn.start unless conn.started?
118
+ conn.read_timeout = timeout
119
+ conn.write_timeout = timeout
120
+ conn.continue_timeout = timeout
81
121
 
82
- conn.request(request)
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::Type, TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1] :schedule Schedule of the subscription.
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
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TerminalShop
4
- VERSION = "0.1.0-alpha.7"
4
+ VERSION = "0.1.0-alpha.10"
5
5
  end
@@ -63,8 +63,8 @@ module TerminalShop
63
63
  returns(
64
64
  T.nilable(
65
65
  T.any(
66
- TerminalShop::Models::SubscriptionAPI::Schedule::Type,
67
- TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1
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::Type,
79
- TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1
78
+ TerminalShop::Models::SubscriptionAPI::Schedule::Fixed,
79
+ TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
80
80
  )
81
81
  ).returns(T.any(
82
- TerminalShop::Models::SubscriptionAPI::Schedule::Type,
83
- TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1
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::Type,
100
- TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1
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::Type,
128
- TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1
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 Type < TerminalShop::BaseModel
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 UnionMember1 < TerminalShop::BaseModel
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::Type],
201
- [NilClass, TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1]
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::Type,
17
- TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1
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)
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module TerminalShop
4
- VERSION = "0.1.0-alpha.7"
4
+ VERSION = "0.1.0-alpha.10"
5
5
  end
@@ -65,28 +65,28 @@ module TerminalShop
65
65
  end
66
66
 
67
67
  type schedule =
68
- TerminalShop::Models::SubscriptionAPI::Schedule::Type
69
- | TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1
68
+ TerminalShop::Models::SubscriptionAPI::Schedule::Fixed
69
+ | TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
70
70
 
71
71
  class Schedule < TerminalShop::Union
72
- type type_ = { type: :fixed }
72
+ type fixed = { type: :fixed }
73
73
 
74
- class Type < TerminalShop::BaseModel
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::type_
80
+ ?TerminalShop::Models::SubscriptionAPI::Schedule::fixed
81
81
  | TerminalShop::BaseModel data
82
82
  ) -> void
83
83
 
84
- def to_hash: -> TerminalShop::Models::SubscriptionAPI::Schedule::type_
84
+ def to_hash: -> TerminalShop::Models::SubscriptionAPI::Schedule::fixed
85
85
  end
86
86
 
87
- type union_member1 = { interval: Integer, type: :weekly }
87
+ type weekly = { interval: Integer, type: :weekly }
88
88
 
89
- class UnionMember1 < TerminalShop::BaseModel
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::union_member1
97
+ ?TerminalShop::Models::SubscriptionAPI::Schedule::weekly
98
98
  | TerminalShop::BaseModel data
99
99
  ) -> void
100
100
 
101
- def to_hash: -> TerminalShop::Models::SubscriptionAPI::Schedule::union_member1
101
+ def to_hash: -> TerminalShop::Models::SubscriptionAPI::Schedule::weekly
102
102
  end
103
103
 
104
- private def self.variants: -> [[nil, TerminalShop::Models::SubscriptionAPI::Schedule::Type], [nil, TerminalShop::Models::SubscriptionAPI::Schedule::UnionMember1]]
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
@@ -1,3 +1,3 @@
1
1
  module TerminalShop
2
- VERSION: "0.1.0-alpha.6"
2
+ VERSION: "0.1.0-alpha.9"
3
3
  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.7
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-16 00:00:00.000000000 Z
11
+ date: 2025-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool