browserup_mitmproxy_client 1.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 (76) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +68 -0
  4. data/README.md +119 -0
  5. data/Rakefile +10 -0
  6. data/browserup_mitmproxy_client.gemspec +38 -0
  7. data/docs/BrowserUpProxyApi.md +657 -0
  8. data/docs/Counter.md +20 -0
  9. data/docs/Entry.md +38 -0
  10. data/docs/EntryRequest.md +36 -0
  11. data/docs/EntryRequestCookies.md +32 -0
  12. data/docs/EntryRequestQueryString.md +22 -0
  13. data/docs/EntryResponse.md +36 -0
  14. data/docs/EntryResponseContent.md +28 -0
  15. data/docs/EntryTimings.md +32 -0
  16. data/docs/Error.md +20 -0
  17. data/docs/Har.md +18 -0
  18. data/docs/HarLog.md +28 -0
  19. data/docs/HarLogCreator.md +22 -0
  20. data/docs/Header.md +22 -0
  21. data/docs/MatchCriteria.md +44 -0
  22. data/docs/NameValuePair.md +20 -0
  23. data/docs/Page.md +32 -0
  24. data/docs/PagePageTimings.md +22 -0
  25. data/docs/VerifyResult.md +22 -0
  26. data/docs/WebSocketMessage.md +24 -0
  27. data/git_push.sh +58 -0
  28. data/lib/browserup_mitmproxy_client/api/browser_up_proxy_api.rb +689 -0
  29. data/lib/browserup_mitmproxy_client/api_client.rb +389 -0
  30. data/lib/browserup_mitmproxy_client/api_error.rb +57 -0
  31. data/lib/browserup_mitmproxy_client/configuration.rb +279 -0
  32. data/lib/browserup_mitmproxy_client/models/counter.rb +239 -0
  33. data/lib/browserup_mitmproxy_client/models/entry.rb +359 -0
  34. data/lib/browserup_mitmproxy_client/models/entry_request.rb +346 -0
  35. data/lib/browserup_mitmproxy_client/models/entry_request_cookies.rb +291 -0
  36. data/lib/browserup_mitmproxy_client/models/entry_request_query_string.rb +246 -0
  37. data/lib/browserup_mitmproxy_client/models/entry_response.rb +348 -0
  38. data/lib/browserup_mitmproxy_client/models/entry_response_content.rb +273 -0
  39. data/lib/browserup_mitmproxy_client/models/entry_timings.rb +463 -0
  40. data/lib/browserup_mitmproxy_client/models/error.rb +229 -0
  41. data/lib/browserup_mitmproxy_client/models/har.rb +223 -0
  42. data/lib/browserup_mitmproxy_client/models/har_log.rb +287 -0
  43. data/lib/browserup_mitmproxy_client/models/har_log_creator.rb +246 -0
  44. data/lib/browserup_mitmproxy_client/models/header.rb +246 -0
  45. data/lib/browserup_mitmproxy_client/models/match_criteria.rb +346 -0
  46. data/lib/browserup_mitmproxy_client/models/name_value_pair.rb +229 -0
  47. data/lib/browserup_mitmproxy_client/models/page.rb +312 -0
  48. data/lib/browserup_mitmproxy_client/models/page_page_timings.rb +288 -0
  49. data/lib/browserup_mitmproxy_client/models/verify_result.rb +254 -0
  50. data/lib/browserup_mitmproxy_client/models/web_socket_message.rb +265 -0
  51. data/lib/browserup_mitmproxy_client/version.rb +15 -0
  52. data/lib/browserup_mitmproxy_client.rb +59 -0
  53. data/spec/api/browser_up_proxy_api_spec.rb +148 -0
  54. data/spec/api_client_spec.rb +226 -0
  55. data/spec/configuration_spec.rb +42 -0
  56. data/spec/models/counter_spec.rb +40 -0
  57. data/spec/models/entry_request_cookies_spec.rb +76 -0
  58. data/spec/models/entry_request_query_string_spec.rb +46 -0
  59. data/spec/models/entry_request_spec.rb +88 -0
  60. data/spec/models/entry_response_content_spec.rb +64 -0
  61. data/spec/models/entry_response_spec.rb +88 -0
  62. data/spec/models/entry_spec.rb +94 -0
  63. data/spec/models/entry_timings_spec.rb +76 -0
  64. data/spec/models/error_spec.rb +40 -0
  65. data/spec/models/har_log_creator_spec.rb +46 -0
  66. data/spec/models/har_log_spec.rb +64 -0
  67. data/spec/models/har_spec.rb +34 -0
  68. data/spec/models/header_spec.rb +46 -0
  69. data/spec/models/match_criteria_spec.rb +112 -0
  70. data/spec/models/name_value_pair_spec.rb +40 -0
  71. data/spec/models/page_page_timings_spec.rb +46 -0
  72. data/spec/models/page_spec.rb +76 -0
  73. data/spec/models/verify_result_spec.rb +46 -0
  74. data/spec/models/web_socket_message_spec.rb +52 -0
  75. data/spec/spec_helper.rb +111 -0
  76. metadata +181 -0
@@ -0,0 +1,463 @@
1
+ =begin
2
+ #BrowserUp MitmProxy
3
+
4
+ #___ This is the REST API for controlling the BrowserUp MitmProxy. The BrowserUp MitmProxy is a swiss army knife for automated testing that captures HTTP traffic in HAR files. It is also useful for Selenium/Cypress tests. ___
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module BrowserupMitmProxy
17
+ class EntryTimings
18
+ attr_accessor :dns
19
+
20
+ attr_accessor :connect
21
+
22
+ attr_accessor :blocked
23
+
24
+ attr_accessor :_send
25
+
26
+ attr_accessor :wait
27
+
28
+ attr_accessor :receive
29
+
30
+ attr_accessor :ssl
31
+
32
+ attr_accessor :comment
33
+
34
+ # Attribute mapping from ruby-style variable name to JSON key.
35
+ def self.attribute_map
36
+ {
37
+ :'dns' => :'dns',
38
+ :'connect' => :'connect',
39
+ :'blocked' => :'blocked',
40
+ :'_send' => :'send',
41
+ :'wait' => :'wait',
42
+ :'receive' => :'receive',
43
+ :'ssl' => :'ssl',
44
+ :'comment' => :'comment'
45
+ }
46
+ end
47
+
48
+ # Returns all the JSON keys this model knows about
49
+ def self.acceptable_attributes
50
+ attribute_map.values
51
+ end
52
+
53
+ # Attribute type mapping.
54
+ def self.openapi_types
55
+ {
56
+ :'dns' => :'Integer',
57
+ :'connect' => :'Integer',
58
+ :'blocked' => :'Integer',
59
+ :'_send' => :'Integer',
60
+ :'wait' => :'Integer',
61
+ :'receive' => :'Integer',
62
+ :'ssl' => :'Integer',
63
+ :'comment' => :'String'
64
+ }
65
+ end
66
+
67
+ # List of attributes with nullable: true
68
+ def self.openapi_nullable
69
+ Set.new([
70
+ ])
71
+ end
72
+
73
+ # Initializes the object
74
+ # @param [Hash] attributes Model attributes in the form of hash
75
+ def initialize(attributes = {})
76
+ if (!attributes.is_a?(Hash))
77
+ fail ArgumentError, "The input argument (attributes) must be a hash in `BrowserupMitmProxy::EntryTimings` initialize method"
78
+ end
79
+
80
+ # check to see if the attribute exists and convert string to symbol for hash key
81
+ attributes = attributes.each_with_object({}) { |(k, v), h|
82
+ if (!self.class.attribute_map.key?(k.to_sym))
83
+ fail ArgumentError, "`#{k}` is not a valid attribute in `BrowserupMitmProxy::EntryTimings`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
84
+ end
85
+ h[k.to_sym] = v
86
+ }
87
+
88
+ if attributes.key?(:'dns')
89
+ self.dns = attributes[:'dns']
90
+ else
91
+ self.dns = -1
92
+ end
93
+
94
+ if attributes.key?(:'connect')
95
+ self.connect = attributes[:'connect']
96
+ else
97
+ self.connect = -1
98
+ end
99
+
100
+ if attributes.key?(:'blocked')
101
+ self.blocked = attributes[:'blocked']
102
+ else
103
+ self.blocked = -1
104
+ end
105
+
106
+ if attributes.key?(:'_send')
107
+ self._send = attributes[:'_send']
108
+ else
109
+ self._send = -1
110
+ end
111
+
112
+ if attributes.key?(:'wait')
113
+ self.wait = attributes[:'wait']
114
+ else
115
+ self.wait = -1
116
+ end
117
+
118
+ if attributes.key?(:'receive')
119
+ self.receive = attributes[:'receive']
120
+ else
121
+ self.receive = -1
122
+ end
123
+
124
+ if attributes.key?(:'ssl')
125
+ self.ssl = attributes[:'ssl']
126
+ else
127
+ self.ssl = -1
128
+ end
129
+
130
+ if attributes.key?(:'comment')
131
+ self.comment = attributes[:'comment']
132
+ end
133
+ end
134
+
135
+ # Show invalid properties with the reasons. Usually used together with valid?
136
+ # @return Array for valid properties with the reasons
137
+ def list_invalid_properties
138
+ invalid_properties = Array.new
139
+ if @dns.nil?
140
+ invalid_properties.push('invalid value for "dns", dns cannot be nil.')
141
+ end
142
+
143
+ if @dns < -1
144
+ invalid_properties.push('invalid value for "dns", must be greater than or equal to -1.')
145
+ end
146
+
147
+ if @connect.nil?
148
+ invalid_properties.push('invalid value for "connect", connect cannot be nil.')
149
+ end
150
+
151
+ if @connect < -1
152
+ invalid_properties.push('invalid value for "connect", must be greater than or equal to -1.')
153
+ end
154
+
155
+ if @blocked.nil?
156
+ invalid_properties.push('invalid value for "blocked", blocked cannot be nil.')
157
+ end
158
+
159
+ if @blocked < -1
160
+ invalid_properties.push('invalid value for "blocked", must be greater than or equal to -1.')
161
+ end
162
+
163
+ if @_send.nil?
164
+ invalid_properties.push('invalid value for "_send", _send cannot be nil.')
165
+ end
166
+
167
+ if @_send < -1
168
+ invalid_properties.push('invalid value for "_send", must be greater than or equal to -1.')
169
+ end
170
+
171
+ if @wait.nil?
172
+ invalid_properties.push('invalid value for "wait", wait cannot be nil.')
173
+ end
174
+
175
+ if @wait < -1
176
+ invalid_properties.push('invalid value for "wait", must be greater than or equal to -1.')
177
+ end
178
+
179
+ if @receive.nil?
180
+ invalid_properties.push('invalid value for "receive", receive cannot be nil.')
181
+ end
182
+
183
+ if @receive < -1
184
+ invalid_properties.push('invalid value for "receive", must be greater than or equal to -1.')
185
+ end
186
+
187
+ if @ssl.nil?
188
+ invalid_properties.push('invalid value for "ssl", ssl cannot be nil.')
189
+ end
190
+
191
+ if @ssl < -1
192
+ invalid_properties.push('invalid value for "ssl", must be greater than or equal to -1.')
193
+ end
194
+
195
+ invalid_properties
196
+ end
197
+
198
+ # Check to see if the all the properties in the model are valid
199
+ # @return true if the model is valid
200
+ def valid?
201
+ return false if @dns.nil?
202
+ return false if @dns < -1
203
+ return false if @connect.nil?
204
+ return false if @connect < -1
205
+ return false if @blocked.nil?
206
+ return false if @blocked < -1
207
+ return false if @_send.nil?
208
+ return false if @_send < -1
209
+ return false if @wait.nil?
210
+ return false if @wait < -1
211
+ return false if @receive.nil?
212
+ return false if @receive < -1
213
+ return false if @ssl.nil?
214
+ return false if @ssl < -1
215
+ true
216
+ end
217
+
218
+ # Custom attribute writer method with validation
219
+ # @param [Object] dns Value to be assigned
220
+ def dns=(dns)
221
+ if dns.nil?
222
+ fail ArgumentError, 'dns cannot be nil'
223
+ end
224
+
225
+ if dns < -1
226
+ fail ArgumentError, 'invalid value for "dns", must be greater than or equal to -1.'
227
+ end
228
+
229
+ @dns = dns
230
+ end
231
+
232
+ # Custom attribute writer method with validation
233
+ # @param [Object] connect Value to be assigned
234
+ def connect=(connect)
235
+ if connect.nil?
236
+ fail ArgumentError, 'connect cannot be nil'
237
+ end
238
+
239
+ if connect < -1
240
+ fail ArgumentError, 'invalid value for "connect", must be greater than or equal to -1.'
241
+ end
242
+
243
+ @connect = connect
244
+ end
245
+
246
+ # Custom attribute writer method with validation
247
+ # @param [Object] blocked Value to be assigned
248
+ def blocked=(blocked)
249
+ if blocked.nil?
250
+ fail ArgumentError, 'blocked cannot be nil'
251
+ end
252
+
253
+ if blocked < -1
254
+ fail ArgumentError, 'invalid value for "blocked", must be greater than or equal to -1.'
255
+ end
256
+
257
+ @blocked = blocked
258
+ end
259
+
260
+ # Custom attribute writer method with validation
261
+ # @param [Object] _send Value to be assigned
262
+ def _send=(_send)
263
+ if _send.nil?
264
+ fail ArgumentError, '_send cannot be nil'
265
+ end
266
+
267
+ if _send < -1
268
+ fail ArgumentError, 'invalid value for "_send", must be greater than or equal to -1.'
269
+ end
270
+
271
+ @_send = _send
272
+ end
273
+
274
+ # Custom attribute writer method with validation
275
+ # @param [Object] wait Value to be assigned
276
+ def wait=(wait)
277
+ if wait.nil?
278
+ fail ArgumentError, 'wait cannot be nil'
279
+ end
280
+
281
+ if wait < -1
282
+ fail ArgumentError, 'invalid value for "wait", must be greater than or equal to -1.'
283
+ end
284
+
285
+ @wait = wait
286
+ end
287
+
288
+ # Custom attribute writer method with validation
289
+ # @param [Object] receive Value to be assigned
290
+ def receive=(receive)
291
+ if receive.nil?
292
+ fail ArgumentError, 'receive cannot be nil'
293
+ end
294
+
295
+ if receive < -1
296
+ fail ArgumentError, 'invalid value for "receive", must be greater than or equal to -1.'
297
+ end
298
+
299
+ @receive = receive
300
+ end
301
+
302
+ # Custom attribute writer method with validation
303
+ # @param [Object] ssl Value to be assigned
304
+ def ssl=(ssl)
305
+ if ssl.nil?
306
+ fail ArgumentError, 'ssl cannot be nil'
307
+ end
308
+
309
+ if ssl < -1
310
+ fail ArgumentError, 'invalid value for "ssl", must be greater than or equal to -1.'
311
+ end
312
+
313
+ @ssl = ssl
314
+ end
315
+
316
+ # Checks equality by comparing each attribute.
317
+ # @param [Object] Object to be compared
318
+ def ==(o)
319
+ return true if self.equal?(o)
320
+ self.class == o.class &&
321
+ dns == o.dns &&
322
+ connect == o.connect &&
323
+ blocked == o.blocked &&
324
+ _send == o._send &&
325
+ wait == o.wait &&
326
+ receive == o.receive &&
327
+ ssl == o.ssl &&
328
+ comment == o.comment
329
+ end
330
+
331
+ # @see the `==` method
332
+ # @param [Object] Object to be compared
333
+ def eql?(o)
334
+ self == o
335
+ end
336
+
337
+ # Calculates hash code according to all attributes.
338
+ # @return [Integer] Hash code
339
+ def hash
340
+ [dns, connect, blocked, _send, wait, receive, ssl, comment].hash
341
+ end
342
+
343
+ # Builds the object from hash
344
+ # @param [Hash] attributes Model attributes in the form of hash
345
+ # @return [Object] Returns the model itself
346
+ def self.build_from_hash(attributes)
347
+ new.build_from_hash(attributes)
348
+ end
349
+
350
+ # Builds the object from hash
351
+ # @param [Hash] attributes Model attributes in the form of hash
352
+ # @return [Object] Returns the model itself
353
+ def build_from_hash(attributes)
354
+ return nil unless attributes.is_a?(Hash)
355
+ self.class.openapi_types.each_pair do |key, type|
356
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
357
+ self.send("#{key}=", nil)
358
+ elsif type =~ /\AArray<(.*)>/i
359
+ # check to ensure the input is an array given that the attribute
360
+ # is documented as an array but the input is not
361
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
362
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
363
+ end
364
+ elsif !attributes[self.class.attribute_map[key]].nil?
365
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
366
+ end
367
+ end
368
+
369
+ self
370
+ end
371
+
372
+ # Deserializes the data based on type
373
+ # @param string type Data type
374
+ # @param string value Value to be deserialized
375
+ # @return [Object] Deserialized data
376
+ def _deserialize(type, value)
377
+ case type.to_sym
378
+ when :Time
379
+ Time.parse(value)
380
+ when :Date
381
+ Date.parse(value)
382
+ when :String
383
+ value.to_s
384
+ when :Integer
385
+ value.to_i
386
+ when :Float
387
+ value.to_f
388
+ when :Boolean
389
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
390
+ true
391
+ else
392
+ false
393
+ end
394
+ when :Object
395
+ # generic object (usually a Hash), return directly
396
+ value
397
+ when /\AArray<(?<inner_type>.+)>\z/
398
+ inner_type = Regexp.last_match[:inner_type]
399
+ value.map { |v| _deserialize(inner_type, v) }
400
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
401
+ k_type = Regexp.last_match[:k_type]
402
+ v_type = Regexp.last_match[:v_type]
403
+ {}.tap do |hash|
404
+ value.each do |k, v|
405
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
406
+ end
407
+ end
408
+ else # model
409
+ # models (e.g. Pet) or oneOf
410
+ klass = BrowserupMitmProxy.const_get(type)
411
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
412
+ end
413
+ end
414
+
415
+ # Returns the string representation of the object
416
+ # @return [String] String presentation of the object
417
+ def to_s
418
+ to_hash.to_s
419
+ end
420
+
421
+ # to_body is an alias to to_hash (backward compatibility)
422
+ # @return [Hash] Returns the object in the form of hash
423
+ def to_body
424
+ to_hash
425
+ end
426
+
427
+ # Returns the object in the form of hash
428
+ # @return [Hash] Returns the object in the form of hash
429
+ def to_hash
430
+ hash = {}
431
+ self.class.attribute_map.each_pair do |attr, param|
432
+ value = self.send(attr)
433
+ if value.nil?
434
+ is_nullable = self.class.openapi_nullable.include?(attr)
435
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
436
+ end
437
+
438
+ hash[param] = _to_hash(value)
439
+ end
440
+ hash
441
+ end
442
+
443
+ # Outputs non-array value in the form of hash
444
+ # For object, use to_hash. Otherwise, just return the value
445
+ # @param [Object] value Any valid value
446
+ # @return [Hash] Returns the value in the form of hash
447
+ def _to_hash(value)
448
+ if value.is_a?(Array)
449
+ value.compact.map { |v| _to_hash(v) }
450
+ elsif value.is_a?(Hash)
451
+ {}.tap do |hash|
452
+ value.each { |k, v| hash[k] = _to_hash(v) }
453
+ end
454
+ elsif value.respond_to? :to_hash
455
+ value.to_hash
456
+ else
457
+ value
458
+ end
459
+ end
460
+
461
+ end
462
+
463
+ end
@@ -0,0 +1,229 @@
1
+ =begin
2
+ #BrowserUp MitmProxy
3
+
4
+ #___ This is the REST API for controlling the BrowserUp MitmProxy. The BrowserUp MitmProxy is a swiss army knife for automated testing that captures HTTP traffic in HAR files. It is also useful for Selenium/Cypress tests. ___
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module BrowserupMitmProxy
17
+ class Error
18
+ # Name of the Error to add. Stored in har under _errors
19
+ attr_accessor :name
20
+
21
+ # Short details of the error
22
+ attr_accessor :details
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'name' => :'name',
28
+ :'details' => :'details'
29
+ }
30
+ end
31
+
32
+ # Returns all the JSON keys this model knows about
33
+ def self.acceptable_attributes
34
+ attribute_map.values
35
+ end
36
+
37
+ # Attribute type mapping.
38
+ def self.openapi_types
39
+ {
40
+ :'name' => :'String',
41
+ :'details' => :'String'
42
+ }
43
+ end
44
+
45
+ # List of attributes with nullable: true
46
+ def self.openapi_nullable
47
+ Set.new([
48
+ ])
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `BrowserupMitmProxy::Error` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!self.class.attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `BrowserupMitmProxy::Error`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'name')
67
+ self.name = attributes[:'name']
68
+ end
69
+
70
+ if attributes.key?(:'details')
71
+ self.details = attributes[:'details']
72
+ end
73
+ end
74
+
75
+ # Show invalid properties with the reasons. Usually used together with valid?
76
+ # @return Array for valid properties with the reasons
77
+ def list_invalid_properties
78
+ invalid_properties = Array.new
79
+ invalid_properties
80
+ end
81
+
82
+ # Check to see if the all the properties in the model are valid
83
+ # @return true if the model is valid
84
+ def valid?
85
+ true
86
+ end
87
+
88
+ # Checks equality by comparing each attribute.
89
+ # @param [Object] Object to be compared
90
+ def ==(o)
91
+ return true if self.equal?(o)
92
+ self.class == o.class &&
93
+ name == o.name &&
94
+ details == o.details
95
+ end
96
+
97
+ # @see the `==` method
98
+ # @param [Object] Object to be compared
99
+ def eql?(o)
100
+ self == o
101
+ end
102
+
103
+ # Calculates hash code according to all attributes.
104
+ # @return [Integer] Hash code
105
+ def hash
106
+ [name, details].hash
107
+ end
108
+
109
+ # Builds the object from hash
110
+ # @param [Hash] attributes Model attributes in the form of hash
111
+ # @return [Object] Returns the model itself
112
+ def self.build_from_hash(attributes)
113
+ new.build_from_hash(attributes)
114
+ end
115
+
116
+ # Builds the object from hash
117
+ # @param [Hash] attributes Model attributes in the form of hash
118
+ # @return [Object] Returns the model itself
119
+ def build_from_hash(attributes)
120
+ return nil unless attributes.is_a?(Hash)
121
+ self.class.openapi_types.each_pair do |key, type|
122
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
123
+ self.send("#{key}=", nil)
124
+ elsif type =~ /\AArray<(.*)>/i
125
+ # check to ensure the input is an array given that the attribute
126
+ # is documented as an array but the input is not
127
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
128
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
129
+ end
130
+ elsif !attributes[self.class.attribute_map[key]].nil?
131
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
132
+ end
133
+ end
134
+
135
+ self
136
+ end
137
+
138
+ # Deserializes the data based on type
139
+ # @param string type Data type
140
+ # @param string value Value to be deserialized
141
+ # @return [Object] Deserialized data
142
+ def _deserialize(type, value)
143
+ case type.to_sym
144
+ when :Time
145
+ Time.parse(value)
146
+ when :Date
147
+ Date.parse(value)
148
+ when :String
149
+ value.to_s
150
+ when :Integer
151
+ value.to_i
152
+ when :Float
153
+ value.to_f
154
+ when :Boolean
155
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
156
+ true
157
+ else
158
+ false
159
+ end
160
+ when :Object
161
+ # generic object (usually a Hash), return directly
162
+ value
163
+ when /\AArray<(?<inner_type>.+)>\z/
164
+ inner_type = Regexp.last_match[:inner_type]
165
+ value.map { |v| _deserialize(inner_type, v) }
166
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
167
+ k_type = Regexp.last_match[:k_type]
168
+ v_type = Regexp.last_match[:v_type]
169
+ {}.tap do |hash|
170
+ value.each do |k, v|
171
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
172
+ end
173
+ end
174
+ else # model
175
+ # models (e.g. Pet) or oneOf
176
+ klass = BrowserupMitmProxy.const_get(type)
177
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
178
+ end
179
+ end
180
+
181
+ # Returns the string representation of the object
182
+ # @return [String] String presentation of the object
183
+ def to_s
184
+ to_hash.to_s
185
+ end
186
+
187
+ # to_body is an alias to to_hash (backward compatibility)
188
+ # @return [Hash] Returns the object in the form of hash
189
+ def to_body
190
+ to_hash
191
+ end
192
+
193
+ # Returns the object in the form of hash
194
+ # @return [Hash] Returns the object in the form of hash
195
+ def to_hash
196
+ hash = {}
197
+ self.class.attribute_map.each_pair do |attr, param|
198
+ value = self.send(attr)
199
+ if value.nil?
200
+ is_nullable = self.class.openapi_nullable.include?(attr)
201
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
202
+ end
203
+
204
+ hash[param] = _to_hash(value)
205
+ end
206
+ hash
207
+ end
208
+
209
+ # Outputs non-array value in the form of hash
210
+ # For object, use to_hash. Otherwise, just return the value
211
+ # @param [Object] value Any valid value
212
+ # @return [Hash] Returns the value in the form of hash
213
+ def _to_hash(value)
214
+ if value.is_a?(Array)
215
+ value.compact.map { |v| _to_hash(v) }
216
+ elsif value.is_a?(Hash)
217
+ {}.tap do |hash|
218
+ value.each { |k, v| hash[k] = _to_hash(v) }
219
+ end
220
+ elsif value.respond_to? :to_hash
221
+ value.to_hash
222
+ else
223
+ value
224
+ end
225
+ end
226
+
227
+ end
228
+
229
+ end