brand.dev 0.0.1.pre.alpha.0 → 0.0.1

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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +180 -0
  3. data/README.md +7 -3
  4. data/lib/brand_dev/errors.rb +22 -0
  5. data/lib/brand_dev/internal/transport/base_client.rb +10 -2
  6. data/lib/brand_dev/internal/type/array_of.rb +6 -1
  7. data/lib/brand_dev/internal/type/base_model.rb +77 -25
  8. data/lib/brand_dev/internal/type/boolean.rb +7 -1
  9. data/lib/brand_dev/internal/type/converter.rb +42 -34
  10. data/lib/brand_dev/internal/type/enum.rb +16 -5
  11. data/lib/brand_dev/internal/type/file_input.rb +6 -1
  12. data/lib/brand_dev/internal/type/hash_of.rb +6 -1
  13. data/lib/brand_dev/internal/type/union.rb +17 -9
  14. data/lib/brand_dev/internal/type/unknown.rb +7 -1
  15. data/lib/brand_dev/internal/util.rb +8 -9
  16. data/lib/brand_dev/models/brand_ai_query_params.rb +173 -0
  17. data/lib/brand_dev/models/brand_ai_query_response.rb +80 -0
  18. data/lib/brand_dev/models/brand_identify_from_transaction_params.rb +14 -1
  19. data/lib/brand_dev/models/brand_identify_from_transaction_response.rb +1 -29
  20. data/lib/brand_dev/models/brand_prefetch_params.rb +35 -0
  21. data/lib/brand_dev/models/brand_prefetch_response.rb +33 -0
  22. data/lib/brand_dev/models/brand_retrieve_by_ticker_params.rb +14 -1
  23. data/lib/brand_dev/models/brand_retrieve_by_ticker_response.rb +1 -29
  24. data/lib/brand_dev/models/brand_retrieve_naics_params.rb +11 -1
  25. data/lib/brand_dev/models/brand_retrieve_params.rb +24 -1
  26. data/lib/brand_dev/models/brand_retrieve_response.rb +1 -29
  27. data/lib/brand_dev/models/brand_retrieve_simplified_params.rb +35 -0
  28. data/lib/brand_dev/models/brand_retrieve_simplified_response.rb +280 -0
  29. data/lib/brand_dev/models/brand_screenshot_params.rb +49 -0
  30. data/lib/brand_dev/models/brand_screenshot_response.rb +64 -0
  31. data/lib/brand_dev/models/brand_styleguide_params.rb +36 -0
  32. data/lib/brand_dev/models/brand_styleguide_response.rb +769 -0
  33. data/lib/brand_dev/models.rb +13 -5
  34. data/lib/brand_dev/resources/brand.rb +165 -18
  35. data/lib/brand_dev/version.rb +1 -1
  36. data/lib/brand_dev.rb +10 -2
  37. data/rbi/brand_dev/errors.rbi +16 -0
  38. data/rbi/brand_dev/internal/type/boolean.rbi +2 -0
  39. data/rbi/brand_dev/internal/type/converter.rbi +15 -15
  40. data/rbi/brand_dev/internal/type/union.rbi +5 -0
  41. data/rbi/brand_dev/internal/type/unknown.rbi +2 -0
  42. data/rbi/brand_dev/internal/util.rbi +2 -0
  43. data/rbi/brand_dev/models/brand_ai_query_params.rbi +319 -0
  44. data/rbi/brand_dev/models/brand_ai_query_response.rbi +182 -0
  45. data/rbi/brand_dev/models/brand_identify_from_transaction_params.rbi +15 -0
  46. data/rbi/brand_dev/models/brand_identify_from_transaction_response.rbi +0 -69
  47. data/rbi/brand_dev/models/brand_prefetch_params.rbi +58 -0
  48. data/rbi/brand_dev/models/brand_prefetch_response.rbi +57 -0
  49. data/rbi/brand_dev/models/brand_retrieve_by_ticker_params.rbi +19 -1
  50. data/rbi/brand_dev/models/brand_retrieve_by_ticker_response.rbi +0 -69
  51. data/rbi/brand_dev/models/brand_retrieve_naics_params.rbi +19 -1
  52. data/rbi/brand_dev/models/brand_retrieve_params.rbi +30 -0
  53. data/rbi/brand_dev/models/brand_retrieve_response.rbi +0 -65
  54. data/rbi/brand_dev/models/brand_retrieve_simplified_params.rbi +61 -0
  55. data/rbi/brand_dev/models/brand_retrieve_simplified_response.rbi +667 -0
  56. data/rbi/brand_dev/models/brand_screenshot_params.rbi +105 -0
  57. data/rbi/brand_dev/models/brand_screenshot_response.rbi +135 -0
  58. data/rbi/brand_dev/models/brand_styleguide_params.rbi +60 -0
  59. data/rbi/brand_dev/models/brand_styleguide_response.rbi +1648 -0
  60. data/rbi/brand_dev/models.rbi +10 -1
  61. data/rbi/brand_dev/resources/brand.rbi +133 -6
  62. data/sig/brand_dev/errors.rbs +9 -0
  63. data/sig/brand_dev/internal/type/converter.rbs +7 -1
  64. data/sig/brand_dev/models/brand_ai_query_params.rbs +162 -0
  65. data/sig/brand_dev/models/brand_ai_query_response.rbs +79 -0
  66. data/sig/brand_dev/models/brand_identify_from_transaction_params.rbs +7 -1
  67. data/sig/brand_dev/models/brand_identify_from_transaction_response.rbs +0 -25
  68. data/sig/brand_dev/models/brand_prefetch_params.rbs +30 -0
  69. data/sig/brand_dev/models/brand_prefetch_response.rbs +28 -0
  70. data/sig/brand_dev/models/brand_retrieve_by_ticker_params.rbs +8 -1
  71. data/sig/brand_dev/models/brand_retrieve_by_ticker_response.rbs +0 -25
  72. data/sig/brand_dev/models/brand_retrieve_naics_params.rbs +8 -1
  73. data/sig/brand_dev/models/brand_retrieve_params.rbs +15 -1
  74. data/sig/brand_dev/models/brand_retrieve_response.rbs +0 -25
  75. data/sig/brand_dev/models/brand_retrieve_simplified_params.rbs +30 -0
  76. data/sig/brand_dev/models/brand_retrieve_simplified_response.rbs +292 -0
  77. data/sig/brand_dev/models/brand_screenshot_params.rbs +46 -0
  78. data/sig/brand_dev/models/brand_screenshot_response.rbs +63 -0
  79. data/sig/brand_dev/models/brand_styleguide_params.rbs +30 -0
  80. data/sig/brand_dev/models/brand_styleguide_response.rbs +925 -0
  81. data/sig/brand_dev/models.rbs +9 -1
  82. data/sig/brand_dev/resources/brand.rbs +35 -3
  83. metadata +46 -22
  84. data/lib/brand_dev/models/brand_search_params.rb +0 -22
  85. data/lib/brand_dev/models/brand_search_response.rb +0 -35
  86. data/rbi/brand_dev/models/brand_search_params.rbi +0 -40
  87. data/rbi/brand_dev/models/brand_search_response.rbi +0 -63
  88. data/sig/brand_dev/models/brand_search_params.rbs +0 -23
  89. data/sig/brand_dev/models/brand_search_response.rbs +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 308ab90d3e6f03ff0fb725a2aece6d8c14bb16ff54ed00fab2fee5ad217a72fe
4
- data.tar.gz: 92c6e324a4885ac710359c9556dad60e904d8630a25510c79c122de0d436f420
3
+ metadata.gz: 8dc662ece9287d2b08fb3f04d4379509681b7b0fd7ad4656511c292893972164
4
+ data.tar.gz: 0efbc1ddf71e7d7c7070976f772cf429420d5dfcc9a6fe00358ef5799550d5bc
5
5
  SHA512:
6
- metadata.gz: 9d454dbf45c518f184acb12ec4f9f418add64888c748939005d7a88df98affd9f4935cc5346088aca69041fd18096d6d92d8f4c69b8dbcc537278050c4358e19
7
- data.tar.gz: 9aa4d6101d29030416e70f1ded7cd38550c582baf2822b5face0f3706718c7989ac27d964f7bd9f08ab55fffdb3e4c5ef7f369fd7ecfea5e409fcc67a991ef49
6
+ metadata.gz: acdf41aa05f9251d8d496f0aade72f49d579d642d25f54e72a30455c630b9dfd57a4c25df484fb40512df23c16a9c949a69fcb258c02c9701f4061b2f7996b51
7
+ data.tar.gz: 53144469bc2b3238d5236ed738bd38e894fab07f86bc05f0aef8e4001323c21600f9a356d1502848fbd4acb9cd7f231442dd521dd1d215efd43cef2a99165b03
data/CHANGELOG.md ADDED
@@ -0,0 +1,180 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1 (2025-07-21)
4
+
5
+ Full Changelog: [v0.1.0-alpha.13...v0.0.1](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.13...v0.0.1)
6
+
7
+ ### Features
8
+
9
+ * **api:** manual updates ([cfaabba](https://github.com/brand-dot-dev/ruby-sdk/commit/cfaabbab93b68ba4926f78560d759d788e4b4b98))
10
+
11
+
12
+ ### Chores
13
+
14
+ * **internal:** allow streams to also be unwrapped on a per-row basis ([99d7893](https://github.com/brand-dot-dev/ruby-sdk/commit/99d7893d01a3e111d49fb7c39e53bc9dd524f6b6))
15
+ * **internal:** version bump ([d51ca58](https://github.com/brand-dot-dev/ruby-sdk/commit/d51ca5841eb432576fb2e251d4ebdab02cfb1ad7))
16
+
17
+ ## 0.1.0-alpha.13 (2025-06-29)
18
+
19
+ Full Changelog: [v0.1.0-alpha.12...v0.1.0-alpha.13](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.12...v0.1.0-alpha.13)
20
+
21
+ ### Chores
22
+
23
+ * **internal:** version bump ([20129a5](https://github.com/brand-dot-dev/ruby-sdk/commit/20129a56c65cbf2bbe2e6f15ea146213a0b41aa0))
24
+
25
+ ## 0.1.0-alpha.12 (2025-06-29)
26
+
27
+ Full Changelog: [v0.1.0-alpha.11...v0.1.0-alpha.12](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.11...v0.1.0-alpha.12)
28
+
29
+ ### Features
30
+
31
+ * **api:** manual updates ([ed09624](https://github.com/brand-dot-dev/ruby-sdk/commit/ed09624d1e608e9a6f1294f385341483d4973a3e))
32
+
33
+
34
+ ### Chores
35
+
36
+ * **ci:** only run for pushes and fork pull requests ([4356075](https://github.com/brand-dot-dev/ruby-sdk/commit/4356075a3db29b2d44ea84ad3abfc37491ec7301))
37
+ * **internal:** version bump ([d186e95](https://github.com/brand-dot-dev/ruby-sdk/commit/d186e95c03f25e3f0c07a43e0dab6c40970769e4))
38
+
39
+ ## 0.1.0-alpha.11 (2025-06-27)
40
+
41
+ Full Changelog: [v0.1.0-alpha.10...v0.1.0-alpha.11](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.10...v0.1.0-alpha.11)
42
+
43
+ ### Bug Fixes
44
+
45
+ * **ci:** release-doctor — report correct token name ([d8ea78e](https://github.com/brand-dot-dev/ruby-sdk/commit/d8ea78ebf0d975cac2720b3441e4cc98e49e348c))
46
+
47
+
48
+ ### Chores
49
+
50
+ * **internal:** version bump ([41f18be](https://github.com/brand-dot-dev/ruby-sdk/commit/41f18bedff6bd714f0679df48e7b23e0995916ce))
51
+
52
+ ## 0.1.0-alpha.10 (2025-06-19)
53
+
54
+ Full Changelog: [v0.1.0-alpha.9...v0.1.0-alpha.10](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.9...v0.1.0-alpha.10)
55
+
56
+ ### Features
57
+
58
+ * **api:** manual updates ([7d6d67c](https://github.com/brand-dot-dev/ruby-sdk/commit/7d6d67c7b7a3159e7793e2032dd49f9fe491ecce))
59
+
60
+
61
+ ### Chores
62
+
63
+ * **internal:** version bump ([1cd51db](https://github.com/brand-dot-dev/ruby-sdk/commit/1cd51dbfd4ecb991f8513c180db3eb2b9f8d4a94))
64
+
65
+ ## 0.1.0-alpha.9 (2025-06-19)
66
+
67
+ Full Changelog: [v0.1.0-alpha.8...v0.1.0-alpha.9](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.8...v0.1.0-alpha.9)
68
+
69
+ ### Features
70
+
71
+ * **api:** manual updates ([169c21b](https://github.com/brand-dot-dev/ruby-sdk/commit/169c21b016f153befa54e0d2a68fbe0a8fe6df7e))
72
+ * **api:** manual updates ([e3f5264](https://github.com/brand-dot-dev/ruby-sdk/commit/e3f5264df830ac3cc62db19ba13050d7822f0259))
73
+
74
+
75
+ ### Bug Fixes
76
+
77
+ * issue where we cannot mutate arrays on base model derivatives ([ebaaa42](https://github.com/brand-dot-dev/ruby-sdk/commit/ebaaa42de2ed5b3f20120dcba81a42e85cba778a))
78
+
79
+
80
+ ### Chores
81
+
82
+ * **ci:** enable for pull requests ([1e06613](https://github.com/brand-dot-dev/ruby-sdk/commit/1e066138d45a47d25eaf469e9a472279252ada3a))
83
+ * **internal:** version bump ([90fada6](https://github.com/brand-dot-dev/ruby-sdk/commit/90fada6f55ae8d314784042718e7de258694575b))
84
+
85
+ ## 0.1.0-alpha.8 (2025-06-12)
86
+
87
+ Full Changelog: [v0.1.0-alpha.7...v0.1.0-alpha.8](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.7...v0.1.0-alpha.8)
88
+
89
+ ### Chores
90
+
91
+ * **ci:** link to correct github repo ([f6c0a8c](https://github.com/brand-dot-dev/ruby-sdk/commit/f6c0a8c7bfa4a6354bec596cca3b8484797bb296))
92
+ * **internal:** version bump ([1094c6a](https://github.com/brand-dot-dev/ruby-sdk/commit/1094c6ac192a8b7fe3d774e5fe2d9890fdbc9062))
93
+
94
+ ## 0.1.0-alpha.7 (2025-06-08)
95
+
96
+ Full Changelog: [v0.1.0-alpha.6...v0.1.0-alpha.7](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.6...v0.1.0-alpha.7)
97
+
98
+ ### Chores
99
+
100
+ * **internal:** version bump ([d704a75](https://github.com/brand-dot-dev/ruby-sdk/commit/d704a75754d47d3ffa7797e96ae02cc4145b7b59))
101
+
102
+ ## 0.1.0-alpha.6 (2025-06-08)
103
+
104
+ Full Changelog: [v0.1.0-alpha.5...v0.1.0-alpha.6](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.5...v0.1.0-alpha.6)
105
+
106
+ ### Features
107
+
108
+ * **api:** manual updates ([aa20a00](https://github.com/brand-dot-dev/ruby-sdk/commit/aa20a0054ed6afaea030f1391f50b94b9e019b17))
109
+
110
+
111
+ ### Chores
112
+
113
+ * **internal:** version bump ([223cabb](https://github.com/brand-dot-dev/ruby-sdk/commit/223cabb690bebf1e41c54c6cc1c3367b81d9bb98))
114
+
115
+ ## 0.1.0-alpha.5 (2025-06-06)
116
+
117
+ Full Changelog: [v0.1.0-alpha.4...v0.1.0-alpha.5](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.4...v0.1.0-alpha.5)
118
+
119
+ ### Features
120
+
121
+ * **api:** manual updates ([d07e957](https://github.com/brand-dot-dev/ruby-sdk/commit/d07e957a8e10c10626468008285953a205b6dafc))
122
+
123
+
124
+ ### Chores
125
+
126
+ * **internal:** version bump ([6b3a243](https://github.com/brand-dot-dev/ruby-sdk/commit/6b3a2437ab0592fee82bc4829e048937f54d9e18))
127
+
128
+ ## 0.1.0-alpha.4 (2025-06-06)
129
+
130
+ Full Changelog: [v0.1.0-alpha.3...v0.1.0-alpha.4](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.3...v0.1.0-alpha.4)
131
+
132
+ ### Features
133
+
134
+ * **api:** manual updates ([05a611f](https://github.com/brand-dot-dev/ruby-sdk/commit/05a611fe140468f965dbb41c0d8250d3dd84a9aa))
135
+
136
+
137
+ ### Chores
138
+
139
+ * **internal:** codegen related update ([b850fe2](https://github.com/brand-dot-dev/ruby-sdk/commit/b850fe270f6c9e7d63b380a6bdcdb9c0c6b6b65f))
140
+
141
+ ## 0.1.0-alpha.3 (2025-06-06)
142
+
143
+ Full Changelog: [v0.1.0-alpha.2...v0.1.0-alpha.3](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.2...v0.1.0-alpha.3)
144
+
145
+ ### Features
146
+
147
+ * **api:** manual updates ([7410667](https://github.com/brand-dot-dev/ruby-sdk/commit/7410667d18ceacfb171c91eb14a4825f77e3487b))
148
+
149
+
150
+ ### Chores
151
+
152
+ * **internal:** codegen related update ([08a0fc4](https://github.com/brand-dot-dev/ruby-sdk/commit/08a0fc45756634925a18266d526b41a217b37492))
153
+
154
+ ## 0.1.0-alpha.2 (2025-06-05)
155
+
156
+ Full Changelog: [v0.1.0-alpha.1...v0.1.0-alpha.2](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.1.0-alpha.1...v0.1.0-alpha.2)
157
+
158
+ ### Features
159
+
160
+ * **api:** manual updates ([6613bcd](https://github.com/brand-dot-dev/ruby-sdk/commit/6613bcdddf846a0dbcb1e507da7ec58c93e4125d))
161
+
162
+
163
+ ### Bug Fixes
164
+
165
+ * `to_sorbet_type` should not return branded types ([0047f7c](https://github.com/brand-dot-dev/ruby-sdk/commit/0047f7ce754514e6c5ac04546aa262d1e4df68f5))
166
+ * default content-type for text in multi-part formdata uploads should be text/plain ([c39a8a7](https://github.com/brand-dot-dev/ruby-sdk/commit/c39a8a78f5445fa88de3b9f765d6211889ba78ef))
167
+
168
+ ## 0.1.0-alpha.1 (2025-06-02)
169
+
170
+ Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.0.1-alpha.0...v0.1.0-alpha.1)
171
+
172
+ ### Features
173
+
174
+ * **api:** manual updates ([1c2a095](https://github.com/brand-dot-dev/ruby-sdk/commit/1c2a09538494964e67752f572ed11a41f4bf4e29))
175
+
176
+
177
+ ### Chores
178
+
179
+ * configure new SDK language ([4b2d19e](https://github.com/brand-dot-dev/ruby-sdk/commit/4b2d19e3ea9342c01529655c0231e1258c04de35))
180
+ * sync repo ([fc86136](https://github.com/brand-dot-dev/ruby-sdk/commit/fc86136bdab0b1c30529662a3dedb8016726d8bc))
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Brand Dev Ruby API library
2
2
 
3
- The Brand Dev Ruby library provides convenient access to the Brand Dev REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/stainless-sdks/brand.dev-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
3
+ The Brand Dev Ruby library provides convenient access to the Brand Dev REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/brand-dot-dev/ruby-sdk#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
4
4
 
5
5
  It is generated with [Stainless](https://www.stainless.com/).
6
6
 
@@ -12,10 +12,14 @@ Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs
12
12
 
13
13
  To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
14
14
 
15
+ <!-- x-release-please-start-version -->
16
+
15
17
  ```ruby
16
- gem "brand.dev", "~> 0.0.1.pre.alpha.0"
18
+ gem "brand.dev", "~> 0.0.1"
17
19
  ```
18
20
 
21
+ <!-- x-release-please-end -->
22
+
19
23
  ## Usage
20
24
 
21
25
  ```ruby
@@ -226,4 +230,4 @@ Ruby 3.2.0 or higher.
226
230
 
227
231
  ## Contributing
228
232
 
229
- See [the contributing documentation](https://github.com/stainless-sdks/brand.dev-ruby/tree/main/CONTRIBUTING.md).
233
+ See [the contributing documentation](https://github.com/brand-dot-dev/ruby-sdk/tree/main/CONTRIBUTING.md).
@@ -9,6 +9,28 @@ module BrandDev
9
9
  end
10
10
 
11
11
  class ConversionError < BrandDev::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
12
34
  end
13
35
 
14
36
  class APIError < BrandDev::Errors::Error
@@ -471,6 +471,7 @@ module BrandDev
471
471
  self.class.validate!(req)
472
472
  model = req.fetch(:model) { BrandDev::Internal::Type::Unknown }
473
473
  opts = req[:options].to_h
474
+ unwrap = req[:unwrap]
474
475
  BrandDev::RequestOptions.validate!(opts)
475
476
  request = build_request(req.except(:options), opts)
476
477
  url = request.fetch(:url)
@@ -487,11 +488,18 @@ module BrandDev
487
488
  decoded = BrandDev::Internal::Util.decode_content(response, stream: stream)
488
489
  case req
489
490
  in {stream: Class => st}
490
- st.new(model: model, url: url, status: status, response: response, stream: decoded)
491
+ st.new(
492
+ model: model,
493
+ url: url,
494
+ status: status,
495
+ response: response,
496
+ unwrap: unwrap,
497
+ stream: decoded
498
+ )
491
499
  in {page: Class => page}
492
500
  page.new(client: self, req: req, headers: response, page_data: decoded)
493
501
  else
494
- unwrapped = BrandDev::Internal::Util.dig(decoded, req[:unwrap])
502
+ unwrapped = BrandDev::Internal::Util.dig(decoded, unwrap)
495
503
  BrandDev::Internal::Type::Converter.coerce(model, unwrapped)
496
504
  end
497
505
  end
@@ -62,10 +62,14 @@ module BrandDev
62
62
  #
63
63
  # @param state [Hash{Symbol=>Object}] .
64
64
  #
65
- # @option state [Boolean, :strong] :strictness
65
+ # @option state [Boolean] :translate_names
66
+ #
67
+ # @option state [Boolean] :strictness
66
68
  #
67
69
  # @option state [Hash{Symbol=>Object}] :exactness
68
70
  #
71
+ # @option state [Class<StandardError>] :error
72
+ #
69
73
  # @option state [Integer] :branched
70
74
  #
71
75
  # @return [Array<Object>, Object]
@@ -74,6 +78,7 @@ module BrandDev
74
78
 
75
79
  unless value.is_a?(Array)
76
80
  exactness[:no] += 1
81
+ state[:error] = TypeError.new("#{value.class} can't be coerced into #{Array}")
77
82
  return value
78
83
  end
79
84
 
@@ -60,7 +60,7 @@ module BrandDev
60
60
  [BrandDev::Internal::Type::Converter.type_info(type_info), type_info]
61
61
  end
62
62
 
63
- setter = "#{name_sym}="
63
+ setter = :"#{name_sym}="
64
64
  api_name = info.fetch(:api_name, name_sym)
65
65
  nilable = info.fetch(:nil?, false)
66
66
  const = if required && !nilable
@@ -84,30 +84,61 @@ module BrandDev
84
84
  type_fn: type_fn
85
85
  }
86
86
 
87
- define_method(setter) { @data.store(name_sym, _1) }
87
+ define_method(setter) do |value|
88
+ target = type_fn.call
89
+ state = BrandDev::Internal::Type::Converter.new_coerce_state(translate_names: false)
90
+ coerced = BrandDev::Internal::Type::Converter.coerce(target, value, state: state)
91
+ status = @coerced.store(name_sym, state.fetch(:error) || true)
92
+ stored =
93
+ case [target, status]
94
+ in [BrandDev::Internal::Type::Converter | Symbol, true]
95
+ coerced
96
+ else
97
+ value
98
+ end
99
+ @data.store(name_sym, stored)
100
+ end
88
101
 
102
+ # rubocop:disable Style/CaseEquality
103
+ # rubocop:disable Metrics/BlockLength
89
104
  define_method(name_sym) do
90
105
  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
106
+
107
+ case @coerced[name_sym]
108
+ in true | false if BrandDev::Internal::Type::Converter === target
109
+ @data.fetch(name_sym)
110
+ in ::StandardError => e
111
+ raise BrandDev::Errors::ConversionError.new(
112
+ on: self.class,
113
+ method: __method__,
114
+ target: target,
115
+ value: @data.fetch(name_sym),
116
+ cause: e
100
117
  )
118
+ else
119
+ Kernel.then do
120
+ value = @data.fetch(name_sym) { const == BrandDev::Internal::OMIT ? nil : const }
121
+ state = BrandDev::Internal::Type::Converter.new_coerce_state(translate_names: false)
122
+ if (nilable || !required) && value.nil?
123
+ nil
124
+ else
125
+ BrandDev::Internal::Type::Converter.coerce(
126
+ target, value, state: state
127
+ )
128
+ end
129
+ rescue StandardError => e
130
+ raise BrandDev::Errors::ConversionError.new(
131
+ on: self.class,
132
+ method: __method__,
133
+ target: target,
134
+ value: value,
135
+ cause: e
136
+ )
137
+ end
101
138
  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
139
  end
140
+ # rubocop:enable Metrics/BlockLength
141
+ # rubocop:enable Style/CaseEquality
111
142
  end
112
143
 
113
144
  # @api private
@@ -207,23 +238,28 @@ module BrandDev
207
238
  #
208
239
  # @param state [Hash{Symbol=>Object}] .
209
240
  #
210
- # @option state [Boolean, :strong] :strictness
241
+ # @option state [Boolean] :translate_names
242
+ #
243
+ # @option state [Boolean] :strictness
211
244
  #
212
245
  # @option state [Hash{Symbol=>Object}] :exactness
213
246
  #
247
+ # @option state [Class<StandardError>] :error
248
+ #
214
249
  # @option state [Integer] :branched
215
250
  #
216
251
  # @return [self, Object]
217
252
  def coerce(value, state:)
218
253
  exactness = state.fetch(:exactness)
219
254
 
220
- if value.is_a?(self.class)
255
+ if value.is_a?(self)
221
256
  exactness[:yes] += 1
222
257
  return value
223
258
  end
224
259
 
225
260
  unless (val = BrandDev::Internal::Util.coerce_hash(value)).is_a?(Hash)
226
261
  exactness[:no] += 1
262
+ state[:error] = TypeError.new("#{value.class} can't be coerced into #{Hash}")
227
263
  return value
228
264
  end
229
265
  exactness[:yes] += 1
@@ -231,13 +267,15 @@ module BrandDev
231
267
  keys = val.keys.to_set
232
268
  instance = new
233
269
  data = instance.to_h
270
+ status = instance.instance_variable_get(:@coerced)
234
271
 
235
272
  # rubocop:disable Metrics/BlockLength
236
273
  fields.each do |name, field|
237
274
  mode, required, target = field.fetch_values(:mode, :required, :type)
238
275
  api_name, nilable, const = field.fetch_values(:api_name, :nilable, :const)
276
+ src_name = state.fetch(:translate_names) ? api_name : name
239
277
 
240
- unless val.key?(api_name)
278
+ unless val.key?(src_name)
241
279
  if required && mode != :dump && const == BrandDev::Internal::OMIT
242
280
  exactness[nilable ? :maybe : :no] += 1
243
281
  else
@@ -246,9 +284,10 @@ module BrandDev
246
284
  next
247
285
  end
248
286
 
249
- item = val.fetch(api_name)
250
- keys.delete(api_name)
287
+ item = val.fetch(src_name)
288
+ keys.delete(src_name)
251
289
 
290
+ state[:error] = nil
252
291
  converted =
253
292
  if item.nil? && (nilable || !required)
254
293
  exactness[nilable ? :yes : :maybe] += 1
@@ -262,6 +301,8 @@ module BrandDev
262
301
  item
263
302
  end
264
303
  end
304
+
305
+ status.store(name, state.fetch(:error) || true)
265
306
  data.store(name, converted)
266
307
  end
267
308
  # rubocop:enable Metrics/BlockLength
@@ -437,7 +478,18 @@ module BrandDev
437
478
  # Create a new instance of a model.
438
479
  #
439
480
  # @param data [Hash{Symbol=>Object}, self]
440
- def initialize(data = {}) = (@data = BrandDev::Internal::Util.coerce_hash!(data).to_h)
481
+ def initialize(data = {})
482
+ @data = {}
483
+ @coerced = {}
484
+ BrandDev::Internal::Util.coerce_hash!(data).each do
485
+ if self.class.known_fields.key?(_1)
486
+ public_send(:"#{_1}=", _2)
487
+ else
488
+ @data.store(_1, _2)
489
+ @coerced.store(_1, false)
490
+ end
491
+ end
492
+ end
441
493
 
442
494
  class << self
443
495
  # @api private
@@ -31,14 +31,20 @@ module BrandDev
31
31
  class << self
32
32
  # @api private
33
33
  #
34
+ # Coerce value to Boolean if possible, otherwise return the original value.
35
+ #
34
36
  # @param value [Boolean, Object]
35
37
  #
36
38
  # @param state [Hash{Symbol=>Object}] .
37
39
  #
38
- # @option state [Boolean, :strong] :strictness
40
+ # @option state [Boolean] :translate_names
41
+ #
42
+ # @option state [Boolean] :strictness
39
43
  #
40
44
  # @option state [Hash{Symbol=>Object}] :exactness
41
45
  #
46
+ # @option state [Class<StandardError>] :error
47
+ #
42
48
  # @option state [Integer] :branched
43
49
  #
44
50
  # @return [Boolean, Object]
@@ -15,10 +15,14 @@ module BrandDev
15
15
  #
16
16
  # @param state [Hash{Symbol=>Object}] .
17
17
  #
18
- # @option state [Boolean, :strong] :strictness
18
+ # @option state [Boolean] :translate_names
19
+ #
20
+ # @option state [Boolean] :strictness
19
21
  #
20
22
  # @option state [Hash{Symbol=>Object}] :exactness
21
23
  #
24
+ # @option state [Class<StandardError>] :error
25
+ #
22
26
  # @option state [Integer] :branched
23
27
  #
24
28
  # @return [Object]
@@ -94,6 +98,21 @@ module BrandDev
94
98
  end
95
99
  end
96
100
 
101
+ # @api private
102
+ #
103
+ # @param translate_names [Boolean]
104
+ #
105
+ # @return [Hash{Symbol=>Object}]
106
+ def new_coerce_state(translate_names: true)
107
+ {
108
+ translate_names: translate_names,
109
+ strictness: true,
110
+ exactness: {yes: 0, no: 0, maybe: 0},
111
+ error: nil,
112
+ branched: 0
113
+ }
114
+ end
115
+
97
116
  # @api private
98
117
  #
99
118
  # Based on `target`, transform `value` into `target`, to the extent possible:
@@ -110,14 +129,11 @@ module BrandDev
110
129
  #
111
130
  # @param value [Object]
112
131
  #
113
- # @param state [Hash{Symbol=>Object}] The `strictness` is one of `true`, `false`, or `:strong`. This informs the
114
- # coercion strategy when we have to decide between multiple possible conversion
115
- # targets:
132
+ # @param state [Hash{Symbol=>Object}] The `strictness` is one of `true`, `false`. This informs the coercion strategy
133
+ # when we have to decide between multiple possible conversion targets:
116
134
  #
117
135
  # - `true`: the conversion must be exact, with minimum coercion.
118
136
  # - `false`: the conversion can be approximate, with some coercion.
119
- # - `:strong`: the conversion must be exact, with no coercion, and raise an error
120
- # if not possible.
121
137
  #
122
138
  # The `exactness` is `Hash` with keys being one of `yes`, `no`, or `maybe`. For
123
139
  # any given conversion attempt, the exactness will be updated based on how closely
@@ -130,21 +146,20 @@ module BrandDev
130
146
  #
131
147
  # See implementation below for more details.
132
148
  #
133
- # @option state [Boolean, :strong] :strictness
149
+ # @option state [Boolean] :translate_names
150
+ #
151
+ # @option state [Boolean] :strictness
134
152
  #
135
153
  # @option state [Hash{Symbol=>Object}] :exactness
136
154
  #
155
+ # @option state [Class<StandardError>] :error
156
+ #
137
157
  # @option state [Integer] :branched
138
158
  #
139
159
  # @return [Object]
140
- def coerce(
141
- target,
142
- value,
143
- state: {strictness: true, exactness: {yes: 0, no: 0, maybe: 0}, branched: 0}
144
- )
145
- # rubocop:disable Lint/SuppressedException
160
+ def coerce(target, value, state: BrandDev::Internal::Type::Converter.new_coerce_state)
146
161
  # rubocop:disable Metrics/BlockNesting
147
- strictness, exactness = state.fetch_values(:strictness, :exactness)
162
+ exactness = state.fetch(:exactness)
148
163
 
149
164
  case target
150
165
  in BrandDev::Internal::Type::Converter
@@ -160,29 +175,26 @@ module BrandDev
160
175
  exactness[value.nil? ? :yes : :maybe] += 1
161
176
  return nil
162
177
  in -> { _1 <= Integer }
163
- if value.is_a?(Integer)
178
+ case value
179
+ in Integer
164
180
  exactness[:yes] += 1
165
181
  return value
166
- elsif strictness == :strong && Integer(value, exception: false) != value
167
- message = "no implicit conversion of #{value.class} into #{target.inspect}"
168
- raise value.is_a?(Numeric) ? ArgumentError.new(message) : TypeError.new(message)
169
182
  else
170
183
  Kernel.then do
171
184
  return Integer(value).tap { exactness[:maybe] += 1 }
172
- rescue ArgumentError, TypeError
185
+ rescue ArgumentError, TypeError => e
186
+ state[:error] = e
173
187
  end
174
188
  end
175
189
  in -> { _1 <= Float }
176
190
  if value.is_a?(Numeric)
177
191
  exactness[:yes] += 1
178
192
  return Float(value)
179
- elsif strictness == :strong
180
- message = "no implicit conversion of #{value.class} into #{target.inspect}"
181
- raise TypeError.new(message)
182
193
  else
183
194
  Kernel.then do
184
195
  return Float(value).tap { exactness[:maybe] += 1 }
185
- rescue ArgumentError, TypeError
196
+ rescue ArgumentError, TypeError => e
197
+ state[:error] = e
186
198
  end
187
199
  end
188
200
  in -> { _1 <= String }
@@ -194,16 +206,13 @@ module BrandDev
194
206
  exactness[:yes] += 1
195
207
  return value.string
196
208
  else
197
- if strictness == :strong
198
- message = "no implicit conversion of #{value.class} into #{target.inspect}"
199
- raise TypeError.new(message)
200
- end
209
+ state[:error] = TypeError.new("#{value.class} can't be coerced into #{String}")
201
210
  end
202
211
  in -> { _1 <= Date || _1 <= Time }
203
212
  Kernel.then do
204
213
  return target.parse(value).tap { exactness[:yes] += 1 }
205
214
  rescue ArgumentError, TypeError => e
206
- raise e if strictness == :strong
215
+ state[:error] = e
207
216
  end
208
217
  in -> { _1 <= StringIO } if value.is_a?(String)
209
218
  exactness[:yes] += 1
@@ -221,10 +230,8 @@ module BrandDev
221
230
  return value
222
231
  end
223
232
  else
224
- if strictness == :strong
225
- message = "cannot convert non-matching #{value.class} into #{target.inspect}"
226
- raise ArgumentError.new(message)
227
- end
233
+ message = "cannot convert non-matching #{value.class} into #{target.inspect}"
234
+ state[:error] = ArgumentError.new(message)
228
235
  end
229
236
  else
230
237
  end
@@ -232,7 +239,6 @@ module BrandDev
232
239
  exactness[:no] += 1
233
240
  value
234
241
  # rubocop:enable Metrics/BlockNesting
235
- # rubocop:enable Lint/SuppressedException
236
242
  end
237
243
 
238
244
  # @api private
@@ -277,8 +283,10 @@ module BrandDev
277
283
  define_sorbet_constant!(:CoerceState) do
278
284
  T.type_alias do
279
285
  {
280
- strictness: T.any(T::Boolean, Symbol),
286
+ translate_names: T::Boolean,
287
+ strictness: T::Boolean,
281
288
  exactness: {yes: Integer, no: Integer, maybe: Integer},
289
+ error: T::Class[StandardError],
282
290
  branched: Integer
283
291
  }
284
292
  end