brand.dev 0.0.1.pre.alpha.0 → 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 +4 -4
- data/CHANGELOG.md +188 -0
- data/README.md +7 -3
- data/lib/brand_dev/errors.rb +22 -0
- data/lib/brand_dev/internal/transport/base_client.rb +10 -2
- data/lib/brand_dev/internal/type/array_of.rb +6 -1
- data/lib/brand_dev/internal/type/base_model.rb +77 -25
- data/lib/brand_dev/internal/type/boolean.rb +7 -1
- data/lib/brand_dev/internal/type/converter.rb +42 -34
- data/lib/brand_dev/internal/type/enum.rb +16 -5
- data/lib/brand_dev/internal/type/file_input.rb +6 -1
- data/lib/brand_dev/internal/type/hash_of.rb +6 -1
- data/lib/brand_dev/internal/type/union.rb +17 -9
- data/lib/brand_dev/internal/type/unknown.rb +7 -1
- data/lib/brand_dev/internal/util.rb +8 -9
- data/lib/brand_dev/models/brand_ai_query_params.rb +173 -0
- data/lib/brand_dev/models/brand_ai_query_response.rb +80 -0
- data/lib/brand_dev/models/brand_identify_from_transaction_params.rb +14 -1
- data/lib/brand_dev/models/brand_identify_from_transaction_response.rb +1 -29
- data/lib/brand_dev/models/brand_prefetch_params.rb +35 -0
- data/lib/brand_dev/models/brand_prefetch_response.rb +33 -0
- data/lib/brand_dev/models/brand_retrieve_by_ticker_params.rb +14 -1
- data/lib/brand_dev/models/brand_retrieve_by_ticker_response.rb +1 -29
- data/lib/brand_dev/models/brand_retrieve_naics_params.rb +11 -1
- data/lib/brand_dev/models/brand_retrieve_params.rb +24 -1
- data/lib/brand_dev/models/brand_retrieve_response.rb +1 -29
- data/lib/brand_dev/models/brand_retrieve_simplified_params.rb +35 -0
- data/lib/brand_dev/models/brand_retrieve_simplified_response.rb +280 -0
- data/lib/brand_dev/models/brand_screenshot_params.rb +49 -0
- data/lib/brand_dev/models/brand_screenshot_response.rb +64 -0
- data/lib/brand_dev/models/brand_styleguide_params.rb +36 -0
- data/lib/brand_dev/models/brand_styleguide_response.rb +769 -0
- data/lib/brand_dev/models.rb +13 -5
- data/lib/brand_dev/resources/brand.rb +165 -18
- data/lib/brand_dev/version.rb +1 -1
- data/lib/brand_dev.rb +10 -2
- data/rbi/brand_dev/errors.rbi +16 -0
- data/rbi/brand_dev/internal/type/boolean.rbi +2 -0
- data/rbi/brand_dev/internal/type/converter.rbi +15 -15
- data/rbi/brand_dev/internal/type/union.rbi +5 -0
- data/rbi/brand_dev/internal/type/unknown.rbi +2 -0
- data/rbi/brand_dev/internal/util.rbi +2 -0
- data/rbi/brand_dev/models/brand_ai_query_params.rbi +319 -0
- data/rbi/brand_dev/models/brand_ai_query_response.rbi +182 -0
- data/rbi/brand_dev/models/brand_identify_from_transaction_params.rbi +15 -0
- data/rbi/brand_dev/models/brand_identify_from_transaction_response.rbi +0 -69
- data/rbi/brand_dev/models/brand_prefetch_params.rbi +58 -0
- data/rbi/brand_dev/models/brand_prefetch_response.rbi +57 -0
- data/rbi/brand_dev/models/brand_retrieve_by_ticker_params.rbi +19 -1
- data/rbi/brand_dev/models/brand_retrieve_by_ticker_response.rbi +0 -69
- data/rbi/brand_dev/models/brand_retrieve_naics_params.rbi +19 -1
- data/rbi/brand_dev/models/brand_retrieve_params.rbi +30 -0
- data/rbi/brand_dev/models/brand_retrieve_response.rbi +0 -65
- data/rbi/brand_dev/models/brand_retrieve_simplified_params.rbi +61 -0
- data/rbi/brand_dev/models/brand_retrieve_simplified_response.rbi +667 -0
- data/rbi/brand_dev/models/brand_screenshot_params.rbi +105 -0
- data/rbi/brand_dev/models/brand_screenshot_response.rbi +135 -0
- data/rbi/brand_dev/models/brand_styleguide_params.rbi +60 -0
- data/rbi/brand_dev/models/brand_styleguide_response.rbi +1648 -0
- data/rbi/brand_dev/models.rbi +10 -1
- data/rbi/brand_dev/resources/brand.rbi +133 -6
- data/sig/brand_dev/errors.rbs +9 -0
- data/sig/brand_dev/internal/type/converter.rbs +7 -1
- data/sig/brand_dev/models/brand_ai_query_params.rbs +162 -0
- data/sig/brand_dev/models/brand_ai_query_response.rbs +79 -0
- data/sig/brand_dev/models/brand_identify_from_transaction_params.rbs +7 -1
- data/sig/brand_dev/models/brand_identify_from_transaction_response.rbs +0 -25
- data/sig/brand_dev/models/brand_prefetch_params.rbs +30 -0
- data/sig/brand_dev/models/brand_prefetch_response.rbs +28 -0
- data/sig/brand_dev/models/brand_retrieve_by_ticker_params.rbs +8 -1
- data/sig/brand_dev/models/brand_retrieve_by_ticker_response.rbs +0 -25
- data/sig/brand_dev/models/brand_retrieve_naics_params.rbs +8 -1
- data/sig/brand_dev/models/brand_retrieve_params.rbs +15 -1
- data/sig/brand_dev/models/brand_retrieve_response.rbs +0 -25
- data/sig/brand_dev/models/brand_retrieve_simplified_params.rbs +30 -0
- data/sig/brand_dev/models/brand_retrieve_simplified_response.rbs +292 -0
- data/sig/brand_dev/models/brand_screenshot_params.rbs +46 -0
- data/sig/brand_dev/models/brand_screenshot_response.rbs +63 -0
- data/sig/brand_dev/models/brand_styleguide_params.rbs +30 -0
- data/sig/brand_dev/models/brand_styleguide_response.rbs +925 -0
- data/sig/brand_dev/models.rbs +9 -1
- data/sig/brand_dev/resources/brand.rbs +35 -3
- metadata +46 -22
- data/lib/brand_dev/models/brand_search_params.rb +0 -22
- data/lib/brand_dev/models/brand_search_response.rb +0 -35
- data/rbi/brand_dev/models/brand_search_params.rbi +0 -40
- data/rbi/brand_dev/models/brand_search_response.rbi +0 -63
- data/sig/brand_dev/models/brand_search_params.rbs +0 -23
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5187a0e7ff93105de03073b21b9af7154630af2e6e27a0f89e6fb00be215f9e
|
4
|
+
data.tar.gz: d82dc675e43177be3b3027b2b76abdbc858db3ef6552240a8f7aad352eee3532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 824254ebd3b93a96f97aa78a39ceb0401563885f5fcf7fea0664afe24b8273627c2bbd47ba717479406e2f5b2b9642ebfd7822f1b0daa41cce06b45053bb1c52
|
7
|
+
data.tar.gz: 05e67886ddb430d822216bef9baff7168c3a56f49cc625ce55a371c22d0cc61820ac20cc4d42731b7395baac73707389790154e3990778c7f9a8a884daba9ddb
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.0.2 (2025-07-21)
|
4
|
+
|
5
|
+
Full Changelog: [v0.0.1...v0.0.2](https://github.com/brand-dot-dev/ruby-sdk/compare/v0.0.1...v0.0.2)
|
6
|
+
|
7
|
+
### Chores
|
8
|
+
|
9
|
+
* **internal:** version bump ([c8553b7](https://github.com/brand-dot-dev/ruby-sdk/commit/c8553b728303284cda46b2a980743c5533932fdd))
|
10
|
+
|
11
|
+
## 0.0.1 (2025-07-21)
|
12
|
+
|
13
|
+
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)
|
14
|
+
|
15
|
+
### Features
|
16
|
+
|
17
|
+
* **api:** manual updates ([cfaabba](https://github.com/brand-dot-dev/ruby-sdk/commit/cfaabbab93b68ba4926f78560d759d788e4b4b98))
|
18
|
+
|
19
|
+
|
20
|
+
### Chores
|
21
|
+
|
22
|
+
* **internal:** allow streams to also be unwrapped on a per-row basis ([99d7893](https://github.com/brand-dot-dev/ruby-sdk/commit/99d7893d01a3e111d49fb7c39e53bc9dd524f6b6))
|
23
|
+
* **internal:** version bump ([d51ca58](https://github.com/brand-dot-dev/ruby-sdk/commit/d51ca5841eb432576fb2e251d4ebdab02cfb1ad7))
|
24
|
+
|
25
|
+
## 0.1.0-alpha.13 (2025-06-29)
|
26
|
+
|
27
|
+
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)
|
28
|
+
|
29
|
+
### Chores
|
30
|
+
|
31
|
+
* **internal:** version bump ([20129a5](https://github.com/brand-dot-dev/ruby-sdk/commit/20129a56c65cbf2bbe2e6f15ea146213a0b41aa0))
|
32
|
+
|
33
|
+
## 0.1.0-alpha.12 (2025-06-29)
|
34
|
+
|
35
|
+
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)
|
36
|
+
|
37
|
+
### Features
|
38
|
+
|
39
|
+
* **api:** manual updates ([ed09624](https://github.com/brand-dot-dev/ruby-sdk/commit/ed09624d1e608e9a6f1294f385341483d4973a3e))
|
40
|
+
|
41
|
+
|
42
|
+
### Chores
|
43
|
+
|
44
|
+
* **ci:** only run for pushes and fork pull requests ([4356075](https://github.com/brand-dot-dev/ruby-sdk/commit/4356075a3db29b2d44ea84ad3abfc37491ec7301))
|
45
|
+
* **internal:** version bump ([d186e95](https://github.com/brand-dot-dev/ruby-sdk/commit/d186e95c03f25e3f0c07a43e0dab6c40970769e4))
|
46
|
+
|
47
|
+
## 0.1.0-alpha.11 (2025-06-27)
|
48
|
+
|
49
|
+
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)
|
50
|
+
|
51
|
+
### Bug Fixes
|
52
|
+
|
53
|
+
* **ci:** release-doctor — report correct token name ([d8ea78e](https://github.com/brand-dot-dev/ruby-sdk/commit/d8ea78ebf0d975cac2720b3441e4cc98e49e348c))
|
54
|
+
|
55
|
+
|
56
|
+
### Chores
|
57
|
+
|
58
|
+
* **internal:** version bump ([41f18be](https://github.com/brand-dot-dev/ruby-sdk/commit/41f18bedff6bd714f0679df48e7b23e0995916ce))
|
59
|
+
|
60
|
+
## 0.1.0-alpha.10 (2025-06-19)
|
61
|
+
|
62
|
+
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)
|
63
|
+
|
64
|
+
### Features
|
65
|
+
|
66
|
+
* **api:** manual updates ([7d6d67c](https://github.com/brand-dot-dev/ruby-sdk/commit/7d6d67c7b7a3159e7793e2032dd49f9fe491ecce))
|
67
|
+
|
68
|
+
|
69
|
+
### Chores
|
70
|
+
|
71
|
+
* **internal:** version bump ([1cd51db](https://github.com/brand-dot-dev/ruby-sdk/commit/1cd51dbfd4ecb991f8513c180db3eb2b9f8d4a94))
|
72
|
+
|
73
|
+
## 0.1.0-alpha.9 (2025-06-19)
|
74
|
+
|
75
|
+
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)
|
76
|
+
|
77
|
+
### Features
|
78
|
+
|
79
|
+
* **api:** manual updates ([169c21b](https://github.com/brand-dot-dev/ruby-sdk/commit/169c21b016f153befa54e0d2a68fbe0a8fe6df7e))
|
80
|
+
* **api:** manual updates ([e3f5264](https://github.com/brand-dot-dev/ruby-sdk/commit/e3f5264df830ac3cc62db19ba13050d7822f0259))
|
81
|
+
|
82
|
+
|
83
|
+
### Bug Fixes
|
84
|
+
|
85
|
+
* issue where we cannot mutate arrays on base model derivatives ([ebaaa42](https://github.com/brand-dot-dev/ruby-sdk/commit/ebaaa42de2ed5b3f20120dcba81a42e85cba778a))
|
86
|
+
|
87
|
+
|
88
|
+
### Chores
|
89
|
+
|
90
|
+
* **ci:** enable for pull requests ([1e06613](https://github.com/brand-dot-dev/ruby-sdk/commit/1e066138d45a47d25eaf469e9a472279252ada3a))
|
91
|
+
* **internal:** version bump ([90fada6](https://github.com/brand-dot-dev/ruby-sdk/commit/90fada6f55ae8d314784042718e7de258694575b))
|
92
|
+
|
93
|
+
## 0.1.0-alpha.8 (2025-06-12)
|
94
|
+
|
95
|
+
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)
|
96
|
+
|
97
|
+
### Chores
|
98
|
+
|
99
|
+
* **ci:** link to correct github repo ([f6c0a8c](https://github.com/brand-dot-dev/ruby-sdk/commit/f6c0a8c7bfa4a6354bec596cca3b8484797bb296))
|
100
|
+
* **internal:** version bump ([1094c6a](https://github.com/brand-dot-dev/ruby-sdk/commit/1094c6ac192a8b7fe3d774e5fe2d9890fdbc9062))
|
101
|
+
|
102
|
+
## 0.1.0-alpha.7 (2025-06-08)
|
103
|
+
|
104
|
+
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)
|
105
|
+
|
106
|
+
### Chores
|
107
|
+
|
108
|
+
* **internal:** version bump ([d704a75](https://github.com/brand-dot-dev/ruby-sdk/commit/d704a75754d47d3ffa7797e96ae02cc4145b7b59))
|
109
|
+
|
110
|
+
## 0.1.0-alpha.6 (2025-06-08)
|
111
|
+
|
112
|
+
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)
|
113
|
+
|
114
|
+
### Features
|
115
|
+
|
116
|
+
* **api:** manual updates ([aa20a00](https://github.com/brand-dot-dev/ruby-sdk/commit/aa20a0054ed6afaea030f1391f50b94b9e019b17))
|
117
|
+
|
118
|
+
|
119
|
+
### Chores
|
120
|
+
|
121
|
+
* **internal:** version bump ([223cabb](https://github.com/brand-dot-dev/ruby-sdk/commit/223cabb690bebf1e41c54c6cc1c3367b81d9bb98))
|
122
|
+
|
123
|
+
## 0.1.0-alpha.5 (2025-06-06)
|
124
|
+
|
125
|
+
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)
|
126
|
+
|
127
|
+
### Features
|
128
|
+
|
129
|
+
* **api:** manual updates ([d07e957](https://github.com/brand-dot-dev/ruby-sdk/commit/d07e957a8e10c10626468008285953a205b6dafc))
|
130
|
+
|
131
|
+
|
132
|
+
### Chores
|
133
|
+
|
134
|
+
* **internal:** version bump ([6b3a243](https://github.com/brand-dot-dev/ruby-sdk/commit/6b3a2437ab0592fee82bc4829e048937f54d9e18))
|
135
|
+
|
136
|
+
## 0.1.0-alpha.4 (2025-06-06)
|
137
|
+
|
138
|
+
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)
|
139
|
+
|
140
|
+
### Features
|
141
|
+
|
142
|
+
* **api:** manual updates ([05a611f](https://github.com/brand-dot-dev/ruby-sdk/commit/05a611fe140468f965dbb41c0d8250d3dd84a9aa))
|
143
|
+
|
144
|
+
|
145
|
+
### Chores
|
146
|
+
|
147
|
+
* **internal:** codegen related update ([b850fe2](https://github.com/brand-dot-dev/ruby-sdk/commit/b850fe270f6c9e7d63b380a6bdcdb9c0c6b6b65f))
|
148
|
+
|
149
|
+
## 0.1.0-alpha.3 (2025-06-06)
|
150
|
+
|
151
|
+
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)
|
152
|
+
|
153
|
+
### Features
|
154
|
+
|
155
|
+
* **api:** manual updates ([7410667](https://github.com/brand-dot-dev/ruby-sdk/commit/7410667d18ceacfb171c91eb14a4825f77e3487b))
|
156
|
+
|
157
|
+
|
158
|
+
### Chores
|
159
|
+
|
160
|
+
* **internal:** codegen related update ([08a0fc4](https://github.com/brand-dot-dev/ruby-sdk/commit/08a0fc45756634925a18266d526b41a217b37492))
|
161
|
+
|
162
|
+
## 0.1.0-alpha.2 (2025-06-05)
|
163
|
+
|
164
|
+
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)
|
165
|
+
|
166
|
+
### Features
|
167
|
+
|
168
|
+
* **api:** manual updates ([6613bcd](https://github.com/brand-dot-dev/ruby-sdk/commit/6613bcdddf846a0dbcb1e507da7ec58c93e4125d))
|
169
|
+
|
170
|
+
|
171
|
+
### Bug Fixes
|
172
|
+
|
173
|
+
* `to_sorbet_type` should not return branded types ([0047f7c](https://github.com/brand-dot-dev/ruby-sdk/commit/0047f7ce754514e6c5ac04546aa262d1e4df68f5))
|
174
|
+
* 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))
|
175
|
+
|
176
|
+
## 0.1.0-alpha.1 (2025-06-02)
|
177
|
+
|
178
|
+
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)
|
179
|
+
|
180
|
+
### Features
|
181
|
+
|
182
|
+
* **api:** manual updates ([1c2a095](https://github.com/brand-dot-dev/ruby-sdk/commit/1c2a09538494964e67752f572ed11a41f4bf4e29))
|
183
|
+
|
184
|
+
|
185
|
+
### Chores
|
186
|
+
|
187
|
+
* configure new SDK language ([4b2d19e](https://github.com/brand-dot-dev/ruby-sdk/commit/4b2d19e3ea9342c01529655c0231e1258c04de35))
|
188
|
+
* 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/
|
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.
|
18
|
+
gem "brand.dev", "~> 0.0.2"
|
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/
|
233
|
+
See [the contributing documentation](https://github.com/brand-dot-dev/ruby-sdk/tree/main/CONTRIBUTING.md).
|
data/lib/brand_dev/errors.rb
CHANGED
@@ -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(
|
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,
|
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
|
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)
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
BrandDev::
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
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
|
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?(
|
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(
|
250
|
-
keys.delete(
|
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 = {})
|
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
|
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]
|