internetdata 2.6.3 → 2.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b6a8f4fb33244001e88839b70a653777f091911b885a02cedbcc4ad637d658e
4
- data.tar.gz: c068ea8ade475fbf6f570cd60414637e6fc7074ba083d445f3c2856435a64270
3
+ metadata.gz: afd47ed11a5c7584109ee4cd24d9a80355735d93ab75f34b2e259d00c7bf5a1c
4
+ data.tar.gz: b1e54653b61eecfc115d38f31479419189ceef73892117c392340c07edfd7b7d
5
5
  SHA512:
6
- metadata.gz: 8b3746379cfc383ca98641ff59f475270fe6eedb4566b3977fc6ef75db320a542ba1cffcab694b465ac3fc6d0280ebe21bf973970ebd4b17354fbc140012d410
7
- data.tar.gz: f29a490ae7ae8f17cc84325978e58ba3337100ef3e15641222a71980b62811881c37ccde11db828758aabbf865f78c9347c3b1c2954bba7cfac8362c65dad734
6
+ metadata.gz: 2103eda9f58619d97eea99a26cba2eabdb00f766a4a2baaa2b71c17f1bffb5bc10f34ea322e5614010d8e8a65d27afb7b9371d2cbe4249187363aabb225e7581
7
+ data.tar.gz: e2997411f2e09d36b335c0c55ad1a2e8a9df52e1b413ad686502c712536d587cd16f50b391b07d7500602e0bfd90733a4148c69109cc6cb5a5798139125ac417
@@ -90,11 +90,17 @@ module InternetData
90
90
  # the spec requires. The generated reader raised a RuntimeError, a
91
91
  # JSON::ParserError or an ArgumentError for those, none of them retried, and
92
92
  # handed an empty or non-object body back as nil, as if it were the answer.
93
+ #
94
+ # Every member present is checked against the type the spec gives it before
95
+ # the answer is handed back: the generated reader converts with `to_i` and
96
+ # `to_s`, so `"version":"x"` came back as version 0 and `"version":"3"` as 3,
97
+ # as if either were the answer (2.6.3, measured 2026-10-16).
93
98
  def deserialize(response, return_type)
94
99
  data = super
95
- return data unless data.nil?
100
+ raise Error.new(:server_error, "the API answered with no #{return_type}", status: response.code) if data.nil?
96
101
 
97
- raise Error.new(:server_error, "the API answered with no #{return_type}", status: response.code)
102
+ check_type!(JSON.parse(response.body, symbolize_names: true), return_type.to_s, 'the answer') if return_type
103
+ data
98
104
  rescue Error
99
105
  raise
100
106
  rescue StandardError => e
@@ -189,5 +195,42 @@ module InternetData
189
195
  end
190
196
 
191
197
  private_class_method :transport_failure?, :parse_object, :oauth_refusal
198
+
199
+ private
200
+
201
+ # True when `value` has the generated `type`, a model's members recursively;
202
+ # raises TypeError naming where it does not. A null is left to the models'
203
+ # own required-member checks.
204
+ def check_type!(value, type, where)
205
+ return true if value.nil?
206
+
207
+ typed =
208
+ case type
209
+ when 'String', 'Date', 'Time' then value.is_a?(String)
210
+ when 'Integer' then value.is_a?(Integer)
211
+ when 'Float' then value.is_a?(Numeric)
212
+ when 'Boolean' then [true, false].include?(value)
213
+ when 'Object' then true
214
+ when /\AArray<(?<inner>.+)>\z/
215
+ inner = Regexp.last_match(:inner)
216
+ value.is_a?(Array) && value.each_with_index.all? { |v, i| check_type!(v, inner, "#{where}[#{i}]") }
217
+ when /\AHash<String, ?(?<inner>.+)>\z/
218
+ inner = Regexp.last_match(:inner)
219
+ value.is_a?(Hash) && value.all? { |k, v| check_type!(v, inner, "#{where}.#{k}") }
220
+ else
221
+ model = InternetData.const_get(type)
222
+ if model.respond_to?(:openapi_types)
223
+ value.is_a?(Hash) && model.openapi_types.all? do |attr, member|
224
+ key = model.attribute_map[attr]
225
+ check_type!(value[key], member.to_s, "#{where}.#{key}")
226
+ end
227
+ else
228
+ value.is_a?(String) # an enum
229
+ end
230
+ end
231
+ return true if typed
232
+
233
+ raise TypeError, "#{where} is not a #{type}"
234
+ end
192
235
  end
193
236
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InternetData
4
- VERSION = '2.6.3'
4
+ VERSION = '2.6.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: internetdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mslm Dev