checkout-intents 0.0.2
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 +7 -0
- data/.ignore +2 -0
- data/CHANGELOG.md +16 -0
- data/README.md +358 -0
- data/SECURITY.md +27 -0
- data/lib/checkout_intents/client.rb +100 -0
- data/lib/checkout_intents/errors.rb +228 -0
- data/lib/checkout_intents/file_part.rb +58 -0
- data/lib/checkout_intents/internal/cursor_pagination.rb +125 -0
- data/lib/checkout_intents/internal/transport/base_client.rb +577 -0
- data/lib/checkout_intents/internal/transport/pooled_net_requester.rb +210 -0
- data/lib/checkout_intents/internal/type/array_of.rb +168 -0
- data/lib/checkout_intents/internal/type/base_model.rb +536 -0
- data/lib/checkout_intents/internal/type/base_page.rb +55 -0
- data/lib/checkout_intents/internal/type/boolean.rb +77 -0
- data/lib/checkout_intents/internal/type/converter.rb +327 -0
- data/lib/checkout_intents/internal/type/enum.rb +131 -0
- data/lib/checkout_intents/internal/type/file_input.rb +111 -0
- data/lib/checkout_intents/internal/type/hash_of.rb +188 -0
- data/lib/checkout_intents/internal/type/request_parameters.rb +42 -0
- data/lib/checkout_intents/internal/type/union.rb +258 -0
- data/lib/checkout_intents/internal/type/unknown.rb +81 -0
- data/lib/checkout_intents/internal/util.rb +920 -0
- data/lib/checkout_intents/internal.rb +20 -0
- data/lib/checkout_intents/models/base_checkout_intent.rb +76 -0
- data/lib/checkout_intents/models/betas/checkout_session_create_params.rb +148 -0
- data/lib/checkout_intents/models/brand_retrieve_params.rb +14 -0
- data/lib/checkout_intents/models/brand_retrieve_response.rb +52 -0
- data/lib/checkout_intents/models/buyer.rb +69 -0
- data/lib/checkout_intents/models/checkout_intent.rb +230 -0
- data/lib/checkout_intents/models/checkout_intent_add_payment_params.rb +20 -0
- data/lib/checkout_intents/models/checkout_intent_confirm_params.rb +20 -0
- data/lib/checkout_intents/models/checkout_intent_create_params.rb +68 -0
- data/lib/checkout_intents/models/checkout_intent_list_params.rb +58 -0
- data/lib/checkout_intents/models/checkout_intent_purchase_params.rb +74 -0
- data/lib/checkout_intents/models/checkout_intent_retrieve_params.rb +14 -0
- data/lib/checkout_intents/models/checkout_session.rb +23 -0
- data/lib/checkout_intents/models/money.rb +21 -0
- data/lib/checkout_intents/models/offer.rb +113 -0
- data/lib/checkout_intents/models/payment_method.rb +120 -0
- data/lib/checkout_intents/models/variant_selection.rb +33 -0
- data/lib/checkout_intents/models.rb +76 -0
- data/lib/checkout_intents/request_options.rb +78 -0
- data/lib/checkout_intents/resources/betas/checkout_sessions.rb +54 -0
- data/lib/checkout_intents/resources/betas.rb +18 -0
- data/lib/checkout_intents/resources/brands.rb +37 -0
- data/lib/checkout_intents/resources/checkout_intents.rb +173 -0
- data/lib/checkout_intents/version.rb +5 -0
- data/lib/checkout_intents.rb +77 -0
- data/manifest.yaml +17 -0
- data/rbi/checkout_intents/client.rbi +74 -0
- data/rbi/checkout_intents/errors.rbi +205 -0
- data/rbi/checkout_intents/file_part.rbi +37 -0
- data/rbi/checkout_intents/internal/cursor_pagination.rbi +74 -0
- data/rbi/checkout_intents/internal/transport/base_client.rbi +309 -0
- data/rbi/checkout_intents/internal/transport/pooled_net_requester.rbi +84 -0
- data/rbi/checkout_intents/internal/type/array_of.rbi +108 -0
- data/rbi/checkout_intents/internal/type/base_model.rbi +314 -0
- data/rbi/checkout_intents/internal/type/base_page.rbi +43 -0
- data/rbi/checkout_intents/internal/type/boolean.rbi +58 -0
- data/rbi/checkout_intents/internal/type/converter.rbi +225 -0
- data/rbi/checkout_intents/internal/type/enum.rbi +82 -0
- data/rbi/checkout_intents/internal/type/file_input.rbi +59 -0
- data/rbi/checkout_intents/internal/type/hash_of.rbi +108 -0
- data/rbi/checkout_intents/internal/type/request_parameters.rbi +31 -0
- data/rbi/checkout_intents/internal/type/union.rbi +134 -0
- data/rbi/checkout_intents/internal/type/unknown.rbi +58 -0
- data/rbi/checkout_intents/internal/util.rbi +487 -0
- data/rbi/checkout_intents/internal.rbi +18 -0
- data/rbi/checkout_intents/models/base_checkout_intent.rbi +142 -0
- data/rbi/checkout_intents/models/betas/checkout_session_create_params.rbi +281 -0
- data/rbi/checkout_intents/models/brand_retrieve_params.rbi +32 -0
- data/rbi/checkout_intents/models/brand_retrieve_response.rbi +109 -0
- data/rbi/checkout_intents/models/buyer.rbi +92 -0
- data/rbi/checkout_intents/models/checkout_intent.rbi +653 -0
- data/rbi/checkout_intents/models/checkout_intent_add_payment_params.rbi +59 -0
- data/rbi/checkout_intents/models/checkout_intent_confirm_params.rbi +59 -0
- data/rbi/checkout_intents/models/checkout_intent_create_params.rbi +141 -0
- data/rbi/checkout_intents/models/checkout_intent_list_params.rbi +146 -0
- data/rbi/checkout_intents/models/checkout_intent_purchase_params.rbi +165 -0
- data/rbi/checkout_intents/models/checkout_intent_retrieve_params.rbi +32 -0
- data/rbi/checkout_intents/models/checkout_session.rbi +36 -0
- data/rbi/checkout_intents/models/money.rbi +32 -0
- data/rbi/checkout_intents/models/offer.rbi +225 -0
- data/rbi/checkout_intents/models/payment_method.rbi +292 -0
- data/rbi/checkout_intents/models/variant_selection.rbi +55 -0
- data/rbi/checkout_intents/models.rbi +40 -0
- data/rbi/checkout_intents/request_options.rbi +64 -0
- data/rbi/checkout_intents/resources/betas/checkout_sessions.rbi +47 -0
- data/rbi/checkout_intents/resources/betas.rbi +15 -0
- data/rbi/checkout_intents/resources/brands.rbi +29 -0
- data/rbi/checkout_intents/resources/checkout_intents.rbi +165 -0
- data/rbi/checkout_intents/version.rbi +5 -0
- data/sig/checkout_intents/client.rbs +36 -0
- data/sig/checkout_intents/errors.rbs +117 -0
- data/sig/checkout_intents/file_part.rbs +21 -0
- data/sig/checkout_intents/internal/cursor_pagination.rbs +48 -0
- data/sig/checkout_intents/internal/transport/base_client.rbs +133 -0
- data/sig/checkout_intents/internal/transport/pooled_net_requester.rbs +48 -0
- data/sig/checkout_intents/internal/type/array_of.rbs +48 -0
- data/sig/checkout_intents/internal/type/base_model.rbs +104 -0
- data/sig/checkout_intents/internal/type/base_page.rbs +24 -0
- data/sig/checkout_intents/internal/type/boolean.rbs +26 -0
- data/sig/checkout_intents/internal/type/converter.rbs +79 -0
- data/sig/checkout_intents/internal/type/enum.rbs +32 -0
- data/sig/checkout_intents/internal/type/file_input.rbs +25 -0
- data/sig/checkout_intents/internal/type/hash_of.rbs +48 -0
- data/sig/checkout_intents/internal/type/request_parameters.rbs +20 -0
- data/sig/checkout_intents/internal/type/union.rbs +52 -0
- data/sig/checkout_intents/internal/type/unknown.rbs +26 -0
- data/sig/checkout_intents/internal/util.rbs +185 -0
- data/sig/checkout_intents/internal.rbs +10 -0
- data/sig/checkout_intents/models/base_checkout_intent.rbs +88 -0
- data/sig/checkout_intents/models/betas/checkout_session_create_params.rbs +172 -0
- data/sig/checkout_intents/models/brand_retrieve_params.rbs +15 -0
- data/sig/checkout_intents/models/brand_retrieve_response.rbs +43 -0
- data/sig/checkout_intents/models/buyer.rbs +67 -0
- data/sig/checkout_intents/models/checkout_intent.rbs +324 -0
- data/sig/checkout_intents/models/checkout_intent_add_payment_params.rbs +24 -0
- data/sig/checkout_intents/models/checkout_intent_confirm_params.rbs +24 -0
- data/sig/checkout_intents/models/checkout_intent_create_params.rbs +84 -0
- data/sig/checkout_intents/models/checkout_intent_list_params.rbs +77 -0
- data/sig/checkout_intents/models/checkout_intent_purchase_params.rbs +89 -0
- data/sig/checkout_intents/models/checkout_intent_retrieve_params.rbs +15 -0
- data/sig/checkout_intents/models/checkout_session.rbs +13 -0
- data/sig/checkout_intents/models/money.rbs +15 -0
- data/sig/checkout_intents/models/offer.rbs +135 -0
- data/sig/checkout_intents/models/payment_method.rbs +127 -0
- data/sig/checkout_intents/models/variant_selection.rbs +30 -0
- data/sig/checkout_intents/models.rbs +33 -0
- data/sig/checkout_intents/request_options.rbs +36 -0
- data/sig/checkout_intents/resources/betas/checkout_sessions.rbs +19 -0
- data/sig/checkout_intents/resources/betas.rbs +9 -0
- data/sig/checkout_intents/resources/brands.rbs +12 -0
- data/sig/checkout_intents/resources/checkout_intents.rbs +54 -0
- data/sig/checkout_intents/version.rbs +3 -0
- metadata +194 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CheckoutIntents
|
|
4
|
+
module Errors
|
|
5
|
+
class Error < StandardError
|
|
6
|
+
# @!attribute cause
|
|
7
|
+
#
|
|
8
|
+
# @return [StandardError, nil]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class ConversionError < CheckoutIntents::Errors::Error
|
|
12
|
+
# @return [StandardError, nil]
|
|
13
|
+
def cause = @cause.nil? ? super : @cause
|
|
14
|
+
|
|
15
|
+
# @api private
|
|
16
|
+
#
|
|
17
|
+
# @param on [Class<StandardError>]
|
|
18
|
+
# @param method [Symbol]
|
|
19
|
+
# @param target [Object]
|
|
20
|
+
# @param value [Object]
|
|
21
|
+
# @param cause [StandardError, nil]
|
|
22
|
+
def initialize(on:, method:, target:, value:, cause: nil)
|
|
23
|
+
cls = on.name.split("::").last
|
|
24
|
+
|
|
25
|
+
message = [
|
|
26
|
+
"Failed to parse #{cls}.#{method} from #{value.class} to #{target.inspect}.",
|
|
27
|
+
"To get the unparsed API response, use #{cls}[#{method.inspect}].",
|
|
28
|
+
cause && "Cause: #{cause.message}"
|
|
29
|
+
].filter(&:itself).join(" ")
|
|
30
|
+
|
|
31
|
+
@cause = cause
|
|
32
|
+
super(message)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class APIError < CheckoutIntents::Errors::Error
|
|
37
|
+
# @return [URI::Generic]
|
|
38
|
+
attr_accessor :url
|
|
39
|
+
|
|
40
|
+
# @return [Integer, nil]
|
|
41
|
+
attr_accessor :status
|
|
42
|
+
|
|
43
|
+
# @return [Hash{String=>String}, nil]
|
|
44
|
+
attr_accessor :headers
|
|
45
|
+
|
|
46
|
+
# @return [Object, nil]
|
|
47
|
+
attr_accessor :body
|
|
48
|
+
|
|
49
|
+
# @api private
|
|
50
|
+
#
|
|
51
|
+
# @param url [URI::Generic]
|
|
52
|
+
# @param status [Integer, nil]
|
|
53
|
+
# @param headers [Hash{String=>String}, nil]
|
|
54
|
+
# @param body [Object, nil]
|
|
55
|
+
# @param request [nil]
|
|
56
|
+
# @param response [nil]
|
|
57
|
+
# @param message [String, nil]
|
|
58
|
+
def initialize(url:, status: nil, headers: nil, body: nil, request: nil, response: nil, message: nil)
|
|
59
|
+
@url = url
|
|
60
|
+
@status = status
|
|
61
|
+
@headers = headers
|
|
62
|
+
@body = body
|
|
63
|
+
@request = request
|
|
64
|
+
@response = response
|
|
65
|
+
super(message)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class APIConnectionError < CheckoutIntents::Errors::APIError
|
|
70
|
+
# @!attribute status
|
|
71
|
+
#
|
|
72
|
+
# @return [nil]
|
|
73
|
+
|
|
74
|
+
# @!attribute body
|
|
75
|
+
#
|
|
76
|
+
# @return [nil]
|
|
77
|
+
|
|
78
|
+
# @api private
|
|
79
|
+
#
|
|
80
|
+
# @param url [URI::Generic]
|
|
81
|
+
# @param status [nil]
|
|
82
|
+
# @param headers [Hash{String=>String}, nil]
|
|
83
|
+
# @param body [nil]
|
|
84
|
+
# @param request [nil]
|
|
85
|
+
# @param response [nil]
|
|
86
|
+
# @param message [String, nil]
|
|
87
|
+
def initialize(
|
|
88
|
+
url:,
|
|
89
|
+
status: nil,
|
|
90
|
+
headers: nil,
|
|
91
|
+
body: nil,
|
|
92
|
+
request: nil,
|
|
93
|
+
response: nil,
|
|
94
|
+
message: "Connection error."
|
|
95
|
+
)
|
|
96
|
+
super
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
class APITimeoutError < CheckoutIntents::Errors::APIConnectionError
|
|
101
|
+
# @api private
|
|
102
|
+
#
|
|
103
|
+
# @param url [URI::Generic]
|
|
104
|
+
# @param status [nil]
|
|
105
|
+
# @param headers [Hash{String=>String}, nil]
|
|
106
|
+
# @param body [nil]
|
|
107
|
+
# @param request [nil]
|
|
108
|
+
# @param response [nil]
|
|
109
|
+
# @param message [String, nil]
|
|
110
|
+
def initialize(
|
|
111
|
+
url:,
|
|
112
|
+
status: nil,
|
|
113
|
+
headers: nil,
|
|
114
|
+
body: nil,
|
|
115
|
+
request: nil,
|
|
116
|
+
response: nil,
|
|
117
|
+
message: "Request timed out."
|
|
118
|
+
)
|
|
119
|
+
super
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
class APIStatusError < CheckoutIntents::Errors::APIError
|
|
124
|
+
# @api private
|
|
125
|
+
#
|
|
126
|
+
# @param url [URI::Generic]
|
|
127
|
+
# @param status [Integer]
|
|
128
|
+
# @param headers [Hash{String=>String}, nil]
|
|
129
|
+
# @param body [Object, nil]
|
|
130
|
+
# @param request [nil]
|
|
131
|
+
# @param response [nil]
|
|
132
|
+
# @param message [String, nil]
|
|
133
|
+
#
|
|
134
|
+
# @return [self]
|
|
135
|
+
def self.for(url:, status:, headers:, body:, request:, response:, message: nil)
|
|
136
|
+
kwargs =
|
|
137
|
+
{
|
|
138
|
+
url: url,
|
|
139
|
+
status: status,
|
|
140
|
+
headers: headers,
|
|
141
|
+
body: body,
|
|
142
|
+
request: request,
|
|
143
|
+
response: response,
|
|
144
|
+
message: message
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
case status
|
|
148
|
+
in 400
|
|
149
|
+
CheckoutIntents::Errors::BadRequestError.new(**kwargs)
|
|
150
|
+
in 401
|
|
151
|
+
CheckoutIntents::Errors::AuthenticationError.new(**kwargs)
|
|
152
|
+
in 403
|
|
153
|
+
CheckoutIntents::Errors::PermissionDeniedError.new(**kwargs)
|
|
154
|
+
in 404
|
|
155
|
+
CheckoutIntents::Errors::NotFoundError.new(**kwargs)
|
|
156
|
+
in 409
|
|
157
|
+
CheckoutIntents::Errors::ConflictError.new(**kwargs)
|
|
158
|
+
in 422
|
|
159
|
+
CheckoutIntents::Errors::UnprocessableEntityError.new(**kwargs)
|
|
160
|
+
in 429
|
|
161
|
+
CheckoutIntents::Errors::RateLimitError.new(**kwargs)
|
|
162
|
+
in (500..)
|
|
163
|
+
CheckoutIntents::Errors::InternalServerError.new(**kwargs)
|
|
164
|
+
else
|
|
165
|
+
CheckoutIntents::Errors::APIStatusError.new(**kwargs)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# @!parse
|
|
170
|
+
# # @return [Integer]
|
|
171
|
+
# attr_accessor :status
|
|
172
|
+
|
|
173
|
+
# @api private
|
|
174
|
+
#
|
|
175
|
+
# @param url [URI::Generic]
|
|
176
|
+
# @param status [Integer]
|
|
177
|
+
# @param headers [Hash{String=>String}, nil]
|
|
178
|
+
# @param body [Object, nil]
|
|
179
|
+
# @param request [nil]
|
|
180
|
+
# @param response [nil]
|
|
181
|
+
# @param message [String, nil]
|
|
182
|
+
def initialize(url:, status:, headers:, body:, request:, response:, message: nil)
|
|
183
|
+
message ||= {url: url.to_s, status: status, body: body}
|
|
184
|
+
super(
|
|
185
|
+
url: url,
|
|
186
|
+
status: status,
|
|
187
|
+
headers: headers,
|
|
188
|
+
body: body,
|
|
189
|
+
request: request,
|
|
190
|
+
response: response,
|
|
191
|
+
message: message&.to_s
|
|
192
|
+
)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
class BadRequestError < CheckoutIntents::Errors::APIStatusError
|
|
197
|
+
HTTP_STATUS = 400
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
class AuthenticationError < CheckoutIntents::Errors::APIStatusError
|
|
201
|
+
HTTP_STATUS = 401
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
class PermissionDeniedError < CheckoutIntents::Errors::APIStatusError
|
|
205
|
+
HTTP_STATUS = 403
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
class NotFoundError < CheckoutIntents::Errors::APIStatusError
|
|
209
|
+
HTTP_STATUS = 404
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
class ConflictError < CheckoutIntents::Errors::APIStatusError
|
|
213
|
+
HTTP_STATUS = 409
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
class UnprocessableEntityError < CheckoutIntents::Errors::APIStatusError
|
|
217
|
+
HTTP_STATUS = 422
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
class RateLimitError < CheckoutIntents::Errors::APIStatusError
|
|
221
|
+
HTTP_STATUS = 429
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
class InternalServerError < CheckoutIntents::Errors::APIStatusError
|
|
225
|
+
HTTP_STATUS = (500..)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CheckoutIntents
|
|
4
|
+
class FilePart
|
|
5
|
+
# @return [Pathname, StringIO, IO, String]
|
|
6
|
+
attr_reader :content
|
|
7
|
+
|
|
8
|
+
# @return [String, nil]
|
|
9
|
+
attr_reader :content_type
|
|
10
|
+
|
|
11
|
+
# @return [String, nil]
|
|
12
|
+
attr_reader :filename
|
|
13
|
+
|
|
14
|
+
# @api private
|
|
15
|
+
#
|
|
16
|
+
# @return [String]
|
|
17
|
+
private def read
|
|
18
|
+
case content
|
|
19
|
+
in Pathname
|
|
20
|
+
content.read(binmode: true)
|
|
21
|
+
in StringIO
|
|
22
|
+
content.string
|
|
23
|
+
in IO
|
|
24
|
+
content.read
|
|
25
|
+
in String
|
|
26
|
+
content
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @param a [Object]
|
|
31
|
+
#
|
|
32
|
+
# @return [String]
|
|
33
|
+
def to_json(*a) = read.to_json(*a)
|
|
34
|
+
|
|
35
|
+
# @param a [Object]
|
|
36
|
+
#
|
|
37
|
+
# @return [String]
|
|
38
|
+
def to_yaml(*a) = read.to_yaml(*a)
|
|
39
|
+
|
|
40
|
+
# @param content [Pathname, StringIO, IO, String]
|
|
41
|
+
# @param filename [Pathname, String, nil]
|
|
42
|
+
# @param content_type [String, nil]
|
|
43
|
+
def initialize(content, filename: nil, content_type: nil)
|
|
44
|
+
@content_type = content_type
|
|
45
|
+
@filename =
|
|
46
|
+
case [filename, (@content = content)]
|
|
47
|
+
in [String | Pathname, _]
|
|
48
|
+
::File.basename(filename)
|
|
49
|
+
in [nil, Pathname]
|
|
50
|
+
content.basename.to_path
|
|
51
|
+
in [nil, IO]
|
|
52
|
+
content.to_path
|
|
53
|
+
else
|
|
54
|
+
filename
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CheckoutIntents
|
|
4
|
+
module Internal
|
|
5
|
+
# @generic Elem
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# if cursor_pagination.has_next?
|
|
9
|
+
# cursor_pagination = cursor_pagination.next_page
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# cursor_pagination.auto_paging_each do |checkout_intent|
|
|
14
|
+
# puts(checkout_intent)
|
|
15
|
+
# end
|
|
16
|
+
class CursorPagination
|
|
17
|
+
include CheckoutIntents::Internal::Type::BasePage
|
|
18
|
+
|
|
19
|
+
# @return [Array<generic<Elem>>, nil]
|
|
20
|
+
attr_accessor :data
|
|
21
|
+
|
|
22
|
+
# @return [PageInfo]
|
|
23
|
+
attr_accessor :page_info
|
|
24
|
+
|
|
25
|
+
# @return [Boolean]
|
|
26
|
+
def next_page?
|
|
27
|
+
!data.to_a.empty? && (!page_info&.start_cursor.to_s.empty? || !page_info&.end_cursor.to_s.empty?)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @raise [CheckoutIntents::HTTP::Error]
|
|
31
|
+
# @return [self]
|
|
32
|
+
def next_page
|
|
33
|
+
unless next_page?
|
|
34
|
+
message = "No more pages available. Please check #next_page? before calling ##{__method__}"
|
|
35
|
+
raise RuntimeError.new(message)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
req = CheckoutIntents::Internal::Util.deep_merge(
|
|
39
|
+
@req,
|
|
40
|
+
{query: page_info&.start_cursor.nil? ? {after: page_info&.end_cursor} : {before: page_info&.start_cursor}}
|
|
41
|
+
)
|
|
42
|
+
@client.request(req)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @param blk [Proc]
|
|
46
|
+
#
|
|
47
|
+
# @yieldparam [generic<Elem>]
|
|
48
|
+
def auto_paging_each(&blk)
|
|
49
|
+
unless block_given?
|
|
50
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
page = self
|
|
54
|
+
loop do
|
|
55
|
+
page.data&.each(&blk)
|
|
56
|
+
|
|
57
|
+
break unless page.next_page?
|
|
58
|
+
page = page.next_page
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @api private
|
|
63
|
+
#
|
|
64
|
+
# @param client [CheckoutIntents::Internal::Transport::BaseClient]
|
|
65
|
+
# @param req [Hash{Symbol=>Object}]
|
|
66
|
+
# @param headers [Hash{String=>String}]
|
|
67
|
+
# @param page_data [Hash{Symbol=>Object}]
|
|
68
|
+
def initialize(client:, req:, headers:, page_data:)
|
|
69
|
+
super
|
|
70
|
+
|
|
71
|
+
case page_data
|
|
72
|
+
in {data: Array => data}
|
|
73
|
+
@data = data.map { CheckoutIntents::Internal::Type::Converter.coerce(@model, _1) }
|
|
74
|
+
else
|
|
75
|
+
end
|
|
76
|
+
case page_data
|
|
77
|
+
in {pageInfo: Hash | nil => page_info}
|
|
78
|
+
@page_info =
|
|
79
|
+
CheckoutIntents::Internal::Type::Converter.coerce(
|
|
80
|
+
CheckoutIntents::Internal::CursorPagination::PageInfo,
|
|
81
|
+
page_info
|
|
82
|
+
)
|
|
83
|
+
else
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# @api private
|
|
88
|
+
#
|
|
89
|
+
# @return [String]
|
|
90
|
+
def inspect
|
|
91
|
+
model = CheckoutIntents::Internal::Type::Converter.inspect(@model, depth: 1)
|
|
92
|
+
|
|
93
|
+
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
class PageInfo < CheckoutIntents::Internal::Type::BaseModel
|
|
97
|
+
# @!attribute end_cursor
|
|
98
|
+
#
|
|
99
|
+
# @return [String, nil]
|
|
100
|
+
optional :end_cursor, String, api_name: :endCursor, nil?: true
|
|
101
|
+
|
|
102
|
+
# @!attribute has_next_page
|
|
103
|
+
#
|
|
104
|
+
# @return [Boolean, nil]
|
|
105
|
+
optional :has_next_page, CheckoutIntents::Internal::Type::Boolean, api_name: :hasNextPage
|
|
106
|
+
|
|
107
|
+
# @!attribute has_previous_page
|
|
108
|
+
#
|
|
109
|
+
# @return [Boolean, nil]
|
|
110
|
+
optional :has_previous_page, CheckoutIntents::Internal::Type::Boolean, api_name: :hasPreviousPage
|
|
111
|
+
|
|
112
|
+
# @!attribute start_cursor
|
|
113
|
+
#
|
|
114
|
+
# @return [String, nil]
|
|
115
|
+
optional :start_cursor, String, api_name: :startCursor, nil?: true
|
|
116
|
+
|
|
117
|
+
# @!method initialize(end_cursor: nil, has_next_page: nil, has_previous_page: nil, start_cursor: nil)
|
|
118
|
+
# @param end_cursor [String, nil]
|
|
119
|
+
# @param has_next_page [Boolean]
|
|
120
|
+
# @param has_previous_page [Boolean]
|
|
121
|
+
# @param start_cursor [String, nil]
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|