brand.dev 0.0.1.pre.alpha.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 +7 -0
- data/README.md +229 -0
- data/SECURITY.md +23 -0
- data/lib/brand_dev/client.rb +74 -0
- data/lib/brand_dev/errors.rb +192 -0
- data/lib/brand_dev/file_part.rb +55 -0
- data/lib/brand_dev/internal/transport/base_client.rb +555 -0
- data/lib/brand_dev/internal/transport/pooled_net_requester.rb +209 -0
- data/lib/brand_dev/internal/type/array_of.rb +162 -0
- data/lib/brand_dev/internal/type/base_model.rb +484 -0
- data/lib/brand_dev/internal/type/base_page.rb +55 -0
- data/lib/brand_dev/internal/type/boolean.rb +71 -0
- data/lib/brand_dev/internal/type/converter.rb +292 -0
- data/lib/brand_dev/internal/type/enum.rb +120 -0
- data/lib/brand_dev/internal/type/file_input.rb +103 -0
- data/lib/brand_dev/internal/type/hash_of.rb +182 -0
- data/lib/brand_dev/internal/type/request_parameters.rb +42 -0
- data/lib/brand_dev/internal/type/union.rb +227 -0
- data/lib/brand_dev/internal/type/unknown.rb +75 -0
- data/lib/brand_dev/internal/util.rb +915 -0
- data/lib/brand_dev/internal.rb +20 -0
- data/lib/brand_dev/models/brand_identify_from_transaction_params.rb +22 -0
- data/lib/brand_dev/models/brand_identify_from_transaction_response.rb +435 -0
- data/lib/brand_dev/models/brand_retrieve_by_ticker_params.rb +22 -0
- data/lib/brand_dev/models/brand_retrieve_by_ticker_response.rb +432 -0
- data/lib/brand_dev/models/brand_retrieve_naics_params.rb +27 -0
- data/lib/brand_dev/models/brand_retrieve_naics_response.rb +61 -0
- data/lib/brand_dev/models/brand_retrieve_params.rb +91 -0
- data/lib/brand_dev/models/brand_retrieve_response.rb +432 -0
- data/lib/brand_dev/models/brand_search_params.rb +22 -0
- data/lib/brand_dev/models/brand_search_response.rb +35 -0
- data/lib/brand_dev/models.rb +51 -0
- data/lib/brand_dev/request_options.rb +77 -0
- data/lib/brand_dev/resources/brand.rb +130 -0
- data/lib/brand_dev/version.rb +5 -0
- data/lib/brand_dev.rb +64 -0
- data/manifest.yaml +15 -0
- data/rbi/brand_dev/client.rbi +49 -0
- data/rbi/brand_dev/errors.rbi +162 -0
- data/rbi/brand_dev/file_part.rbi +37 -0
- data/rbi/brand_dev/internal/transport/base_client.rbi +293 -0
- data/rbi/brand_dev/internal/transport/pooled_net_requester.rbi +79 -0
- data/rbi/brand_dev/internal/type/array_of.rbi +104 -0
- data/rbi/brand_dev/internal/type/base_model.rbi +302 -0
- data/rbi/brand_dev/internal/type/base_page.rbi +42 -0
- data/rbi/brand_dev/internal/type/boolean.rbi +56 -0
- data/rbi/brand_dev/internal/type/converter.rbi +162 -0
- data/rbi/brand_dev/internal/type/enum.rbi +82 -0
- data/rbi/brand_dev/internal/type/file_input.rbi +59 -0
- data/rbi/brand_dev/internal/type/hash_of.rbi +104 -0
- data/rbi/brand_dev/internal/type/request_parameters.rbi +29 -0
- data/rbi/brand_dev/internal/type/union.rbi +116 -0
- data/rbi/brand_dev/internal/type/unknown.rbi +56 -0
- data/rbi/brand_dev/internal/util.rbi +485 -0
- data/rbi/brand_dev/internal.rbi +16 -0
- data/rbi/brand_dev/models/brand_identify_from_transaction_params.rbi +46 -0
- data/rbi/brand_dev/models/brand_identify_from_transaction_response.rbi +981 -0
- data/rbi/brand_dev/models/brand_retrieve_by_ticker_params.rbi +43 -0
- data/rbi/brand_dev/models/brand_retrieve_by_ticker_response.rbi +976 -0
- data/rbi/brand_dev/models/brand_retrieve_naics_params.rbi +44 -0
- data/rbi/brand_dev/models/brand_retrieve_naics_response.rbi +127 -0
- data/rbi/brand_dev/models/brand_retrieve_params.rbi +344 -0
- data/rbi/brand_dev/models/brand_retrieve_response.rbi +949 -0
- data/rbi/brand_dev/models/brand_search_params.rbi +40 -0
- data/rbi/brand_dev/models/brand_search_response.rbi +63 -0
- data/rbi/brand_dev/models.rbi +14 -0
- data/rbi/brand_dev/request_options.rbi +59 -0
- data/rbi/brand_dev/resources/brand.rbi +89 -0
- data/rbi/brand_dev/version.rbi +5 -0
- data/sig/brand_dev/client.rbs +26 -0
- data/sig/brand_dev/errors.rbs +101 -0
- data/sig/brand_dev/file_part.rbs +21 -0
- data/sig/brand_dev/internal/transport/base_client.rbs +131 -0
- data/sig/brand_dev/internal/transport/pooled_net_requester.rbs +45 -0
- data/sig/brand_dev/internal/type/array_of.rbs +48 -0
- data/sig/brand_dev/internal/type/base_model.rbs +102 -0
- data/sig/brand_dev/internal/type/base_page.rbs +24 -0
- data/sig/brand_dev/internal/type/boolean.rbs +26 -0
- data/sig/brand_dev/internal/type/converter.rbs +56 -0
- data/sig/brand_dev/internal/type/enum.rbs +32 -0
- data/sig/brand_dev/internal/type/file_input.rbs +25 -0
- data/sig/brand_dev/internal/type/hash_of.rbs +48 -0
- data/sig/brand_dev/internal/type/request_parameters.rbs +17 -0
- data/sig/brand_dev/internal/type/union.rbs +52 -0
- data/sig/brand_dev/internal/type/unknown.rbs +26 -0
- data/sig/brand_dev/internal/util.rbs +185 -0
- data/sig/brand_dev/internal.rbs +9 -0
- data/sig/brand_dev/models/brand_identify_from_transaction_params.rbs +24 -0
- data/sig/brand_dev/models/brand_identify_from_transaction_response.rbs +418 -0
- data/sig/brand_dev/models/brand_retrieve_by_ticker_params.rbs +23 -0
- data/sig/brand_dev/models/brand_retrieve_by_ticker_response.rbs +418 -0
- data/sig/brand_dev/models/brand_retrieve_naics_params.rbs +23 -0
- data/sig/brand_dev/models/brand_retrieve_naics_response.rbs +61 -0
- data/sig/brand_dev/models/brand_retrieve_params.rbs +148 -0
- data/sig/brand_dev/models/brand_retrieve_response.rbs +418 -0
- data/sig/brand_dev/models/brand_search_params.rbs +23 -0
- data/sig/brand_dev/models/brand_search_response.rbs +29 -0
- data/sig/brand_dev/models.rbs +11 -0
- data/sig/brand_dev/request_options.rbs +34 -0
- data/sig/brand_dev/resources/brand.rbs +33 -0
- data/sig/brand_dev/version.rbs +3 -0
- metadata +160 -0
@@ -0,0 +1,484 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrandDev
|
4
|
+
module Internal
|
5
|
+
module Type
|
6
|
+
# @abstract
|
7
|
+
class BaseModel
|
8
|
+
extend BrandDev::Internal::Type::Converter
|
9
|
+
extend BrandDev::Internal::Util::SorbetRuntimeSupport
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# @api private
|
13
|
+
#
|
14
|
+
# Assumes superclass fields are totally defined before fields are accessed /
|
15
|
+
# defined on subclasses.
|
16
|
+
#
|
17
|
+
# @param child [Class<BrandDev::Internal::Type::BaseModel>]
|
18
|
+
def inherited(child)
|
19
|
+
super
|
20
|
+
child.known_fields.replace(known_fields.dup)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @api private
|
24
|
+
#
|
25
|
+
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
|
26
|
+
def known_fields = @known_fields ||= {}
|
27
|
+
|
28
|
+
# @api private
|
29
|
+
#
|
30
|
+
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
|
31
|
+
def fields
|
32
|
+
known_fields.transform_values do |field|
|
33
|
+
{**field.except(:type_fn), type: field.fetch(:type_fn).call}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# @api private
|
38
|
+
#
|
39
|
+
# @param name_sym [Symbol]
|
40
|
+
#
|
41
|
+
# @param required [Boolean]
|
42
|
+
#
|
43
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, BrandDev::Internal::Type::Converter, Class]
|
44
|
+
#
|
45
|
+
# @param spec [Hash{Symbol=>Object}] .
|
46
|
+
#
|
47
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
48
|
+
#
|
49
|
+
# @option spec [Proc] :enum
|
50
|
+
#
|
51
|
+
# @option spec [Proc] :union
|
52
|
+
#
|
53
|
+
# @option spec [Boolean] :"nil?"
|
54
|
+
private def add_field(name_sym, required:, type_info:, spec:)
|
55
|
+
type_fn, info =
|
56
|
+
case type_info
|
57
|
+
in Proc | BrandDev::Internal::Type::Converter | Class
|
58
|
+
[BrandDev::Internal::Type::Converter.type_info({**spec, union: type_info}), spec]
|
59
|
+
in Hash
|
60
|
+
[BrandDev::Internal::Type::Converter.type_info(type_info), type_info]
|
61
|
+
end
|
62
|
+
|
63
|
+
setter = "#{name_sym}="
|
64
|
+
api_name = info.fetch(:api_name, name_sym)
|
65
|
+
nilable = info.fetch(:nil?, false)
|
66
|
+
const = if required && !nilable
|
67
|
+
info.fetch(
|
68
|
+
:const,
|
69
|
+
BrandDev::Internal::OMIT
|
70
|
+
)
|
71
|
+
else
|
72
|
+
BrandDev::Internal::OMIT
|
73
|
+
end
|
74
|
+
|
75
|
+
[name_sym, setter].each { undef_method(_1) } if known_fields.key?(name_sym)
|
76
|
+
|
77
|
+
known_fields[name_sym] =
|
78
|
+
{
|
79
|
+
mode: @mode,
|
80
|
+
api_name: api_name,
|
81
|
+
required: required,
|
82
|
+
nilable: nilable,
|
83
|
+
const: const,
|
84
|
+
type_fn: type_fn
|
85
|
+
}
|
86
|
+
|
87
|
+
define_method(setter) { @data.store(name_sym, _1) }
|
88
|
+
|
89
|
+
define_method(name_sym) do
|
90
|
+
target = type_fn.call
|
91
|
+
value = @data.fetch(name_sym) { const == BrandDev::Internal::OMIT ? nil : const }
|
92
|
+
state = {strictness: :strong, exactness: {yes: 0, no: 0, maybe: 0}, branched: 0}
|
93
|
+
if (nilable || !required) && value.nil?
|
94
|
+
nil
|
95
|
+
else
|
96
|
+
BrandDev::Internal::Type::Converter.coerce(
|
97
|
+
target,
|
98
|
+
value,
|
99
|
+
state: state
|
100
|
+
)
|
101
|
+
end
|
102
|
+
rescue StandardError => e
|
103
|
+
cls = self.class.name.split("::").last
|
104
|
+
message = [
|
105
|
+
"Failed to parse #{cls}.#{__method__} from #{value.class} to #{target.inspect}.",
|
106
|
+
"To get the unparsed API response, use #{cls}[#{__method__.inspect}].",
|
107
|
+
"Cause: #{e.message}"
|
108
|
+
].join(" ")
|
109
|
+
raise BrandDev::Errors::ConversionError.new(message)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# @api private
|
114
|
+
#
|
115
|
+
# @param name_sym [Symbol]
|
116
|
+
#
|
117
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, BrandDev::Internal::Type::Converter, Class]
|
118
|
+
#
|
119
|
+
# @param spec [Hash{Symbol=>Object}] .
|
120
|
+
#
|
121
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
122
|
+
#
|
123
|
+
# @option spec [Proc] :enum
|
124
|
+
#
|
125
|
+
# @option spec [Proc] :union
|
126
|
+
#
|
127
|
+
# @option spec [Boolean] :"nil?"
|
128
|
+
def required(name_sym, type_info, spec = {})
|
129
|
+
add_field(name_sym, required: true, type_info: type_info, spec: spec)
|
130
|
+
end
|
131
|
+
|
132
|
+
# @api private
|
133
|
+
#
|
134
|
+
# @param name_sym [Symbol]
|
135
|
+
#
|
136
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, BrandDev::Internal::Type::Converter, Class]
|
137
|
+
#
|
138
|
+
# @param spec [Hash{Symbol=>Object}] .
|
139
|
+
#
|
140
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
141
|
+
#
|
142
|
+
# @option spec [Proc] :enum
|
143
|
+
#
|
144
|
+
# @option spec [Proc] :union
|
145
|
+
#
|
146
|
+
# @option spec [Boolean] :"nil?"
|
147
|
+
def optional(name_sym, type_info, spec = {})
|
148
|
+
add_field(name_sym, required: false, type_info: type_info, spec: spec)
|
149
|
+
end
|
150
|
+
|
151
|
+
# @api private
|
152
|
+
#
|
153
|
+
# `request_only` attributes not excluded from `.#coerce` when receiving responses
|
154
|
+
# even if well behaved servers should not send them
|
155
|
+
#
|
156
|
+
# @param blk [Proc]
|
157
|
+
private def request_only(&blk)
|
158
|
+
@mode = :dump
|
159
|
+
blk.call
|
160
|
+
ensure
|
161
|
+
@mode = nil
|
162
|
+
end
|
163
|
+
|
164
|
+
# @api private
|
165
|
+
#
|
166
|
+
# `response_only` attributes are omitted from `.#dump` when making requests
|
167
|
+
#
|
168
|
+
# @param blk [Proc]
|
169
|
+
private def response_only(&blk)
|
170
|
+
@mode = :coerce
|
171
|
+
blk.call
|
172
|
+
ensure
|
173
|
+
@mode = nil
|
174
|
+
end
|
175
|
+
|
176
|
+
# @api public
|
177
|
+
#
|
178
|
+
# @param other [Object]
|
179
|
+
#
|
180
|
+
# @return [Boolean]
|
181
|
+
def ==(other)
|
182
|
+
other.is_a?(Class) && other <= BrandDev::Internal::Type::BaseModel && other.fields == fields
|
183
|
+
end
|
184
|
+
|
185
|
+
# @api public
|
186
|
+
#
|
187
|
+
# @return [Integer]
|
188
|
+
def hash = fields.hash
|
189
|
+
end
|
190
|
+
|
191
|
+
# @api public
|
192
|
+
#
|
193
|
+
# @param other [Object]
|
194
|
+
#
|
195
|
+
# @return [Boolean]
|
196
|
+
def ==(other) = self.class == other.class && @data == other.to_h
|
197
|
+
|
198
|
+
# @api public
|
199
|
+
#
|
200
|
+
# @return [Integer]
|
201
|
+
def hash = [self.class, @data].hash
|
202
|
+
|
203
|
+
class << self
|
204
|
+
# @api private
|
205
|
+
#
|
206
|
+
# @param value [BrandDev::Internal::Type::BaseModel, Hash{Object=>Object}, Object]
|
207
|
+
#
|
208
|
+
# @param state [Hash{Symbol=>Object}] .
|
209
|
+
#
|
210
|
+
# @option state [Boolean, :strong] :strictness
|
211
|
+
#
|
212
|
+
# @option state [Hash{Symbol=>Object}] :exactness
|
213
|
+
#
|
214
|
+
# @option state [Integer] :branched
|
215
|
+
#
|
216
|
+
# @return [self, Object]
|
217
|
+
def coerce(value, state:)
|
218
|
+
exactness = state.fetch(:exactness)
|
219
|
+
|
220
|
+
if value.is_a?(self.class)
|
221
|
+
exactness[:yes] += 1
|
222
|
+
return value
|
223
|
+
end
|
224
|
+
|
225
|
+
unless (val = BrandDev::Internal::Util.coerce_hash(value)).is_a?(Hash)
|
226
|
+
exactness[:no] += 1
|
227
|
+
return value
|
228
|
+
end
|
229
|
+
exactness[:yes] += 1
|
230
|
+
|
231
|
+
keys = val.keys.to_set
|
232
|
+
instance = new
|
233
|
+
data = instance.to_h
|
234
|
+
|
235
|
+
# rubocop:disable Metrics/BlockLength
|
236
|
+
fields.each do |name, field|
|
237
|
+
mode, required, target = field.fetch_values(:mode, :required, :type)
|
238
|
+
api_name, nilable, const = field.fetch_values(:api_name, :nilable, :const)
|
239
|
+
|
240
|
+
unless val.key?(api_name)
|
241
|
+
if required && mode != :dump && const == BrandDev::Internal::OMIT
|
242
|
+
exactness[nilable ? :maybe : :no] += 1
|
243
|
+
else
|
244
|
+
exactness[:yes] += 1
|
245
|
+
end
|
246
|
+
next
|
247
|
+
end
|
248
|
+
|
249
|
+
item = val.fetch(api_name)
|
250
|
+
keys.delete(api_name)
|
251
|
+
|
252
|
+
converted =
|
253
|
+
if item.nil? && (nilable || !required)
|
254
|
+
exactness[nilable ? :yes : :maybe] += 1
|
255
|
+
nil
|
256
|
+
else
|
257
|
+
coerced = BrandDev::Internal::Type::Converter.coerce(target, item, state: state)
|
258
|
+
case target
|
259
|
+
in BrandDev::Internal::Type::Converter | Symbol
|
260
|
+
coerced
|
261
|
+
else
|
262
|
+
item
|
263
|
+
end
|
264
|
+
end
|
265
|
+
data.store(name, converted)
|
266
|
+
end
|
267
|
+
# rubocop:enable Metrics/BlockLength
|
268
|
+
|
269
|
+
keys.each { data.store(_1, val.fetch(_1)) }
|
270
|
+
instance
|
271
|
+
end
|
272
|
+
|
273
|
+
# @api private
|
274
|
+
#
|
275
|
+
# @param value [self, Object]
|
276
|
+
#
|
277
|
+
# @param state [Hash{Symbol=>Object}] .
|
278
|
+
#
|
279
|
+
# @option state [Boolean] :can_retry
|
280
|
+
#
|
281
|
+
# @return [Hash{Object=>Object}, Object]
|
282
|
+
def dump(value, state:)
|
283
|
+
unless (coerced = BrandDev::Internal::Util.coerce_hash(value)).is_a?(Hash)
|
284
|
+
return super
|
285
|
+
end
|
286
|
+
|
287
|
+
acc = {}
|
288
|
+
|
289
|
+
coerced.each do |key, val|
|
290
|
+
name = key.is_a?(String) ? key.to_sym : key
|
291
|
+
case (field = known_fields[name])
|
292
|
+
in nil
|
293
|
+
acc.store(name, super(val, state: state))
|
294
|
+
else
|
295
|
+
api_name, mode, type_fn = field.fetch_values(:api_name, :mode, :type_fn)
|
296
|
+
case mode
|
297
|
+
in :coerce
|
298
|
+
next
|
299
|
+
else
|
300
|
+
target = type_fn.call
|
301
|
+
acc.store(api_name, BrandDev::Internal::Type::Converter.dump(target, val, state: state))
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
known_fields.each_value do |field|
|
307
|
+
api_name, mode, const = field.fetch_values(:api_name, :mode, :const)
|
308
|
+
next if mode == :coerce || acc.key?(api_name) || const == BrandDev::Internal::OMIT
|
309
|
+
acc.store(api_name, const)
|
310
|
+
end
|
311
|
+
|
312
|
+
acc
|
313
|
+
end
|
314
|
+
|
315
|
+
# @api private
|
316
|
+
#
|
317
|
+
# @return [Object]
|
318
|
+
def to_sorbet_type
|
319
|
+
self
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
class << self
|
324
|
+
# @api private
|
325
|
+
#
|
326
|
+
# @param model [BrandDev::Internal::Type::BaseModel]
|
327
|
+
# @param convert [Boolean]
|
328
|
+
#
|
329
|
+
# @return [Hash{Symbol=>Object}]
|
330
|
+
def recursively_to_h(model, convert:)
|
331
|
+
rec = ->(x) do
|
332
|
+
case x
|
333
|
+
in BrandDev::Internal::Type::BaseModel
|
334
|
+
if convert
|
335
|
+
fields = x.class.known_fields
|
336
|
+
x.to_h.to_h do |key, val|
|
337
|
+
[key, rec.call(fields.key?(key) ? x.public_send(key) : val)]
|
338
|
+
rescue BrandDev::Errors::ConversionError
|
339
|
+
[key, rec.call(val)]
|
340
|
+
end
|
341
|
+
else
|
342
|
+
rec.call(x.to_h)
|
343
|
+
end
|
344
|
+
in Hash
|
345
|
+
x.transform_values(&rec)
|
346
|
+
in Array
|
347
|
+
x.map(&rec)
|
348
|
+
else
|
349
|
+
x
|
350
|
+
end
|
351
|
+
end
|
352
|
+
rec.call(model)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
# @api public
|
357
|
+
#
|
358
|
+
# Returns the raw value associated with the given key, if found. Otherwise, nil is
|
359
|
+
# returned.
|
360
|
+
#
|
361
|
+
# It is valid to lookup keys that are not in the API spec, for example to access
|
362
|
+
# undocumented features. This method does not parse response data into
|
363
|
+
# higher-level types. Lookup by anything other than a Symbol is an ArgumentError.
|
364
|
+
#
|
365
|
+
# @param key [Symbol]
|
366
|
+
#
|
367
|
+
# @return [Object, nil]
|
368
|
+
def [](key)
|
369
|
+
unless key.instance_of?(Symbol)
|
370
|
+
raise ArgumentError.new("Expected symbol key for lookup, got #{key.inspect}")
|
371
|
+
end
|
372
|
+
|
373
|
+
@data[key]
|
374
|
+
end
|
375
|
+
|
376
|
+
# @api public
|
377
|
+
#
|
378
|
+
# Returns a Hash of the data underlying this object. O(1)
|
379
|
+
#
|
380
|
+
# Keys are Symbols and values are the raw values from the response. The return
|
381
|
+
# value indicates which values were ever set on the object. i.e. there will be a
|
382
|
+
# key in this hash if they ever were, even if the set value was nil.
|
383
|
+
#
|
384
|
+
# This method is not recursive. The returned value is shared by the object, so it
|
385
|
+
# should not be mutated.
|
386
|
+
#
|
387
|
+
# @return [Hash{Symbol=>Object}]
|
388
|
+
def to_h = @data
|
389
|
+
|
390
|
+
alias_method :to_hash, :to_h
|
391
|
+
|
392
|
+
# @api public
|
393
|
+
#
|
394
|
+
# In addition to the behaviour of `#to_h`, this method will recursively call
|
395
|
+
# `#to_h` on nested models.
|
396
|
+
#
|
397
|
+
# @return [Hash{Symbol=>Object}]
|
398
|
+
def deep_to_h = self.class.recursively_to_h(@data, convert: false)
|
399
|
+
|
400
|
+
# @param keys [Array<Symbol>, nil]
|
401
|
+
#
|
402
|
+
# @return [Hash{Symbol=>Object}]
|
403
|
+
#
|
404
|
+
# @example
|
405
|
+
# # `brand_retrieve_response` is a `BrandDev::Models::BrandRetrieveResponse`
|
406
|
+
# brand_retrieve_response => {
|
407
|
+
# brand: brand,
|
408
|
+
# code: code,
|
409
|
+
# status: status
|
410
|
+
# }
|
411
|
+
def deconstruct_keys(keys)
|
412
|
+
(keys || self.class.known_fields.keys)
|
413
|
+
.filter_map do |k|
|
414
|
+
unless self.class.known_fields.key?(k)
|
415
|
+
next
|
416
|
+
end
|
417
|
+
|
418
|
+
[k, public_send(k)]
|
419
|
+
end
|
420
|
+
.to_h
|
421
|
+
end
|
422
|
+
|
423
|
+
# @api public
|
424
|
+
#
|
425
|
+
# @param a [Object]
|
426
|
+
#
|
427
|
+
# @return [String]
|
428
|
+
def to_json(*a) = BrandDev::Internal::Type::Converter.dump(self.class, self).to_json(*a)
|
429
|
+
|
430
|
+
# @api public
|
431
|
+
#
|
432
|
+
# @param a [Object]
|
433
|
+
#
|
434
|
+
# @return [String]
|
435
|
+
def to_yaml(*a) = BrandDev::Internal::Type::Converter.dump(self.class, self).to_yaml(*a)
|
436
|
+
|
437
|
+
# Create a new instance of a model.
|
438
|
+
#
|
439
|
+
# @param data [Hash{Symbol=>Object}, self]
|
440
|
+
def initialize(data = {}) = (@data = BrandDev::Internal::Util.coerce_hash!(data).to_h)
|
441
|
+
|
442
|
+
class << self
|
443
|
+
# @api private
|
444
|
+
#
|
445
|
+
# @param depth [Integer]
|
446
|
+
#
|
447
|
+
# @return [String]
|
448
|
+
def inspect(depth: 0)
|
449
|
+
return super() if depth.positive?
|
450
|
+
|
451
|
+
depth = depth.succ
|
452
|
+
deferred = fields.transform_values do |field|
|
453
|
+
type, required, nilable = field.fetch_values(:type, :required, :nilable)
|
454
|
+
inspected = [
|
455
|
+
BrandDev::Internal::Type::Converter.inspect(type, depth: depth),
|
456
|
+
!required || nilable ? "nil" : nil
|
457
|
+
].compact.join(" | ")
|
458
|
+
-> { inspected }.tap { _1.define_singleton_method(:inspect) { call } }
|
459
|
+
end
|
460
|
+
|
461
|
+
"#{name}[#{deferred.inspect}]"
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
# @api public
|
466
|
+
#
|
467
|
+
# @return [String]
|
468
|
+
def to_s = deep_to_h.to_s
|
469
|
+
|
470
|
+
# @api private
|
471
|
+
#
|
472
|
+
# @return [String]
|
473
|
+
def inspect
|
474
|
+
converted = self.class.recursively_to_h(self, convert: true)
|
475
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} #{converted}>"
|
476
|
+
end
|
477
|
+
|
478
|
+
define_sorbet_constant!(:KnownField) do
|
479
|
+
T.type_alias { {mode: T.nilable(Symbol), required: T::Boolean, nilable: T::Boolean} }
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrandDev
|
4
|
+
module Internal
|
5
|
+
module Type
|
6
|
+
# @api private
|
7
|
+
#
|
8
|
+
# @generic Elem
|
9
|
+
#
|
10
|
+
# This module provides a base implementation for paginated responses in the SDK.
|
11
|
+
module BasePage
|
12
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
13
|
+
|
14
|
+
# @api public
|
15
|
+
#
|
16
|
+
# @return [Boolean]
|
17
|
+
def next_page? = (raise NotImplementedError)
|
18
|
+
|
19
|
+
# @api public
|
20
|
+
#
|
21
|
+
# @raise [BrandDev::Errors::APIError]
|
22
|
+
# @return [self]
|
23
|
+
def next_page = (raise NotImplementedError)
|
24
|
+
|
25
|
+
# @api public
|
26
|
+
#
|
27
|
+
# @param blk [Proc]
|
28
|
+
#
|
29
|
+
# @yieldparam [generic<Elem>]
|
30
|
+
# @return [void]
|
31
|
+
def auto_paging_each(&blk) = (raise NotImplementedError)
|
32
|
+
|
33
|
+
# @return [Enumerable<generic<Elem>>]
|
34
|
+
def to_enum = super(:auto_paging_each)
|
35
|
+
|
36
|
+
alias_method :enum_for, :to_enum
|
37
|
+
|
38
|
+
# @api private
|
39
|
+
#
|
40
|
+
# @param client [BrandDev::Internal::Transport::BaseClient]
|
41
|
+
# @param req [Hash{Symbol=>Object}]
|
42
|
+
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
43
|
+
# @param page_data [Object]
|
44
|
+
def initialize(client:, req:, headers:, page_data:)
|
45
|
+
@client = client
|
46
|
+
@req = req
|
47
|
+
@model = req.fetch(:model)
|
48
|
+
super()
|
49
|
+
end
|
50
|
+
|
51
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrandDev
|
4
|
+
module Internal
|
5
|
+
module Type
|
6
|
+
# @api private
|
7
|
+
#
|
8
|
+
# @abstract
|
9
|
+
#
|
10
|
+
# Ruby has no Boolean class; this is something for models to refer to.
|
11
|
+
class Boolean
|
12
|
+
extend BrandDev::Internal::Type::Converter
|
13
|
+
extend BrandDev::Internal::Util::SorbetRuntimeSupport
|
14
|
+
|
15
|
+
private_class_method :new
|
16
|
+
|
17
|
+
# @api public
|
18
|
+
#
|
19
|
+
# @param other [Object]
|
20
|
+
#
|
21
|
+
# @return [Boolean]
|
22
|
+
def self.===(other) = other == true || other == false
|
23
|
+
|
24
|
+
# @api public
|
25
|
+
#
|
26
|
+
# @param other [Object]
|
27
|
+
#
|
28
|
+
# @return [Boolean]
|
29
|
+
def self.==(other) = other.is_a?(Class) && other <= BrandDev::Internal::Type::Boolean
|
30
|
+
|
31
|
+
class << self
|
32
|
+
# @api private
|
33
|
+
#
|
34
|
+
# @param value [Boolean, Object]
|
35
|
+
#
|
36
|
+
# @param state [Hash{Symbol=>Object}] .
|
37
|
+
#
|
38
|
+
# @option state [Boolean, :strong] :strictness
|
39
|
+
#
|
40
|
+
# @option state [Hash{Symbol=>Object}] :exactness
|
41
|
+
#
|
42
|
+
# @option state [Integer] :branched
|
43
|
+
#
|
44
|
+
# @return [Boolean, Object]
|
45
|
+
def coerce(value, state:)
|
46
|
+
state.fetch(:exactness)[value == true || value == false ? :yes : :no] += 1
|
47
|
+
value
|
48
|
+
end
|
49
|
+
|
50
|
+
# @!method dump(value, state:)
|
51
|
+
# @api private
|
52
|
+
#
|
53
|
+
# @param value [Boolean, Object]
|
54
|
+
#
|
55
|
+
# @param state [Hash{Symbol=>Object}] .
|
56
|
+
#
|
57
|
+
# @option state [Boolean] :can_retry
|
58
|
+
#
|
59
|
+
# @return [Boolean, Object]
|
60
|
+
|
61
|
+
# @api private
|
62
|
+
#
|
63
|
+
# @return [Object]
|
64
|
+
def to_sorbet_type
|
65
|
+
T::Boolean
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|