crisphive 0.2.0 → 0.3.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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +98 -10
  3. data/lib/crisphive/api/business_skill_api.rb +348 -0
  4. data/lib/crisphive/api/customer_api.rb +7 -4
  5. data/lib/crisphive/api/job_request_business_api.rb +243 -27
  6. data/lib/crisphive/api/job_types_api.rb +208 -0
  7. data/lib/crisphive/api/permission_api.rb +79 -0
  8. data/lib/crisphive/api/service_area_api.rb +208 -0
  9. data/lib/crisphive/api/technician_api.rb +8 -8
  10. data/lib/crisphive/api/technician_time_off_api.rb +240 -0
  11. data/lib/crisphive/api/vehicle_api.rb +208 -0
  12. data/lib/crisphive/api/webhooks_api.rb +213 -0
  13. data/lib/crisphive/models/api_internal_techtimeoff_actions.rb +232 -0
  14. data/lib/crisphive/models/api_internal_techtimeoff_status.rb +42 -0
  15. data/lib/crisphive/models/assignable_group.rb +289 -0
  16. data/lib/crisphive/models/book_and_confirm_job_request200_response.rb +253 -0
  17. data/lib/crisphive/models/commit_absence_resolve200_response.rb +253 -0
  18. data/lib/crisphive/models/create_job_type200_response.rb +253 -0
  19. data/lib/crisphive/models/create_service_area200_response.rb +253 -0
  20. data/lib/crisphive/models/create_skill200_response.rb +253 -0
  21. data/lib/crisphive/models/create_skill_category200_response.rb +253 -0
  22. data/lib/crisphive/models/create_technician_time_off200_response.rb +253 -0
  23. data/lib/crisphive/models/create_vehicle200_response.rb +253 -0
  24. data/lib/crisphive/models/create_webhook_endpoint200_response.rb +253 -0
  25. data/lib/crisphive/models/customer.rb +11 -1
  26. data/lib/crisphive/models/customer_contact.rb +25 -5
  27. data/lib/crisphive/models/customer_create_request.rb +12 -2
  28. data/lib/crisphive/models/customer_list_item.rb +11 -1
  29. data/lib/crisphive/models/customer_quick_books_link.rb +235 -0
  30. data/lib/crisphive/models/customer_service_area_ref.rb +225 -0
  31. data/lib/crisphive/models/customer_technician_ref.rb +225 -0
  32. data/lib/crisphive/models/customer_update_request.rb +23 -20
  33. data/lib/crisphive/models/internal_jobrequest_http_address_req.rb +475 -0
  34. data/lib/crisphive/models/job_request.rb +11 -1
  35. data/lib/crisphive/models/job_request_absence_alternative.rb +356 -0
  36. data/lib/crisphive/models/job_request_absence_alternative_cost.rb +275 -0
  37. data/lib/crisphive/models/job_request_absence_assignment.rb +319 -0
  38. data/lib/crisphive/models/job_request_absence_commit_request.rb +296 -0
  39. data/lib/crisphive/models/job_request_absence_notification.rb +283 -0
  40. data/lib/crisphive/models/job_request_absence_plan.rb +322 -0
  41. data/lib/crisphive/models/job_request_absence_preview_request.rb +280 -0
  42. data/lib/crisphive/models/job_request_absence_resolved_job.rb +499 -0
  43. data/lib/crisphive/models/job_request_absence_solver.rb +289 -0
  44. data/lib/crisphive/models/job_request_absence_time_off.rb +281 -0
  45. data/lib/crisphive/models/job_request_absence_unresolved_job.rb +364 -0
  46. data/lib/crisphive/models/job_request_action_summary.rb +1 -1
  47. data/lib/crisphive/models/job_request_attention_summary.rb +2 -2
  48. data/lib/crisphive/models/job_request_blocker.rb +363 -0
  49. data/lib/crisphive/models/job_request_blocker_ref.rb +223 -0
  50. data/lib/crisphive/models/job_request_book_and_confirm_customer.rb +302 -0
  51. data/lib/crisphive/models/job_request_book_and_confirm_emergency.rb +315 -0
  52. data/lib/crisphive/models/job_request_book_and_confirm_emergency_result.rb +279 -0
  53. data/lib/crisphive/models/job_request_book_and_confirm_refusal.rb +280 -0
  54. data/lib/crisphive/models/job_request_book_and_confirm_request.rb +466 -0
  55. data/lib/crisphive/models/job_request_book_and_confirm_response.rb +295 -0
  56. data/lib/crisphive/models/job_request_confirm_request.rb +14 -4
  57. data/lib/crisphive/models/job_request_create_request.rb +1 -1
  58. data/lib/crisphive/models/job_request_emergency_candidate.rb +26 -4
  59. data/lib/crisphive/models/job_request_emergency_candidates.rb +1 -1
  60. data/lib/crisphive/models/job_request_emergency_candidates_request.rb +24 -11
  61. data/lib/crisphive/models/job_request_emergency_commit_request.rb +11 -1
  62. data/lib/crisphive/models/job_request_emergency_inline_job.rb +353 -0
  63. data/lib/crisphive/models/job_request_emergency_plan.rb +25 -3
  64. data/lib/crisphive/models/job_request_emergency_preview_request.rb +24 -11
  65. data/lib/crisphive/models/job_request_move_commit_req.rb +11 -1
  66. data/lib/crisphive/models/job_request_move_plan.rb +11 -1
  67. data/lib/crisphive/models/job_request_move_preview_req.rb +11 -1
  68. data/lib/crisphive/models/job_request_move_warning.rb +32 -8
  69. data/lib/crisphive/models/job_request_priority_update_result.rb +217 -0
  70. data/lib/crisphive/models/job_request_quote_request.rb +14 -11
  71. data/lib/crisphive/models/job_request_reassign_fallback.rb +287 -0
  72. data/lib/crisphive/models/job_request_skill_summary.rb +1 -1
  73. data/lib/crisphive/models/job_request_status_summary.rb +1 -1
  74. data/lib/crisphive/models/job_request_time_segments.rb +2 -2
  75. data/lib/crisphive/models/job_type.rb +42 -2
  76. data/lib/crisphive/models/job_type_create_request.rb +399 -0
  77. data/lib/crisphive/models/job_type_create_response.rb +215 -0
  78. data/lib/crisphive/models/job_type_update_request.rb +400 -0
  79. data/lib/crisphive/models/list_assignable_groups200_response.rb +255 -0
  80. data/lib/crisphive/models/list_technician_time_off200_response.rb +253 -0
  81. data/lib/crisphive/models/list_webhook_event_types200_response.rb +255 -0
  82. data/lib/crisphive/models/quote_job_request200_response.rb +253 -0
  83. data/lib/crisphive/models/service_area.rb +21 -1
  84. data/lib/crisphive/models/service_area_create_request.rb +455 -0
  85. data/lib/crisphive/models/service_area_create_response.rb +215 -0
  86. data/lib/crisphive/models/service_area_update_request.rb +451 -0
  87. data/lib/crisphive/models/skill_category_create_request.rb +270 -0
  88. data/lib/crisphive/models/skill_category_create_response.rb +215 -0
  89. data/lib/crisphive/models/skill_create_request.rb +270 -0
  90. data/lib/crisphive/models/skill_create_response.rb +215 -0
  91. data/lib/crisphive/models/skill_update_request.rb +281 -0
  92. data/lib/crisphive/models/technician.rb +64 -2
  93. data/lib/crisphive/models/technician_create_request.rb +14 -11
  94. data/lib/crisphive/models/technician_time_off.rb +334 -0
  95. data/lib/crisphive/models/technician_time_off_create_request.rb +285 -0
  96. data/lib/crisphive/models/technician_time_off_create_response.rb +215 -0
  97. data/lib/crisphive/models/technician_time_off_list.rb +246 -0
  98. data/lib/crisphive/models/technician_update_request.rb +2 -2
  99. data/lib/crisphive/models/vehicle_create_request.rb +420 -0
  100. data/lib/crisphive/models/vehicle_create_response.rb +215 -0
  101. data/lib/crisphive/models/vehicle_update_request.rb +440 -0
  102. data/lib/crisphive/models/webhook_create_request.rb +320 -0
  103. data/lib/crisphive/models/webhook_create_response.rb +391 -0
  104. data/lib/crisphive/models/webhook_verification.rb +235 -0
  105. data/lib/crisphive/version.rb +1 -1
  106. data/lib/crisphive.rb +66 -0
  107. metadata +68 -2
@@ -0,0 +1,499 @@
1
+ =begin
2
+ #Crisphive Developer API
3
+
4
+ #Public REST API for integrating Crisphive from your own backend. Authenticate every request with a secret API key as a Bearer token (`Authorization: Bearer chsk_live_…`). The key prefix selects the data environment: `chsk_live_…` → production (live), `chsk_test_…` → sandbox (isolated test). **Key scopes (restricted keys).** A key is either *full-access* (can call every endpoint below) or *restricted* to a set of permission codes chosen at creation — the same codes as the dashboard permission grid (e.g. `customers_view`, `job_create`, `team_manage`). A restricted key calling an endpoint outside its scope gets `403`. The full code list is the permission catalog (`GET /permission/modules` on the dashboard API). Create, scope, and revoke keys from the business dashboard. Every response is wrapped in the envelope `{ \"error_code\": 0, \"message\": \"Success\", \"data\": <payload> }`.
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.11.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Crisphive
17
+ class JobRequestAbsenceResolvedJob
18
+ # Commit only, when the placement came from unresolved[].alternatives[]: the accepted kind. Absent for a strict placement. EXTEND-ONLY.
19
+ attr_accessor :alternative_kind
20
+
21
+ # Commit only: the job's \"needs attention\" flag was cleared in the same write.
22
+ attr_accessor :attention_cleared
23
+
24
+ # Minutes the alternate already has booked that day (load).
25
+ attr_accessor :booked_minutes
26
+
27
+ # Commit only, with alternative_kind: what the business paid for this placement.
28
+ attr_accessor :cost
29
+
30
+ # Customer name on the job.
31
+ attr_accessor :customer_name
32
+
33
+ # Business-local calendar day the window starts on (YYYY-MM-DD) — group a multi-day range on it.
34
+ attr_accessor :date
35
+
36
+ attr_accessor :desired_skills
37
+
38
+ # Alternate's driving distance to the site in km. ABSENT when the engine had no route (no start location, no job coordinates, routing failure) — hide the chip rather than rendering \"0 km\".
39
+ attr_accessor :distance_km
40
+
41
+ # Window end (UTC).
42
+ attr_accessor :end_at
43
+
44
+ # How many alternates could have taken this job.
45
+ attr_accessor :feasible_count
46
+
47
+ # UUID of the absent technician losing the job.
48
+ attr_accessor :from_technician_id
49
+
50
+ # UUID of the re-staffed job.
51
+ attr_accessor :job_id
52
+
53
+ # Desired skills the alternate holds / the job asks for.
54
+ attr_accessor :matched_skills
55
+
56
+ # Commit only: what the customer-notification routing will do for this job.
57
+ attr_accessor :notification
58
+
59
+ attr_accessor :original_end_at
60
+
61
+ # Commit only, when window_preserved is false: the window the job LEFT (UTC).
62
+ attr_accessor :original_start_at
63
+
64
+ # Priority (p0..p3).
65
+ attr_accessor :priority
66
+
67
+ # Human-friendly short code.
68
+ attr_accessor :short_code
69
+
70
+ # Window start (UTC). For a strict or reassign_out_of_area placement it is byte-identical to the job's current window; for an accepted reschedule alternative (commit) it is the NEW window.
71
+ attr_accessor :start_at
72
+
73
+ # status_version: at preview the current value (echo it on commit); on the COMMIT response the post-commit value (+1).
74
+ attr_accessor :status_version
75
+
76
+ # Full name of the alternate. Omitted when unresolved.
77
+ attr_accessor :to_name
78
+
79
+ # UUID of the alternate receiving the job.
80
+ attr_accessor :to_technician_id
81
+
82
+ # Engine ranking score for this alternate on this job (0..1).
83
+ attr_accessor :total_score
84
+
85
+ # Alternate's one-way commute estimate in minutes (rounded up). Absent when unknown.
86
+ attr_accessor :travel_minutes
87
+
88
+ # True unless the coordinator accepted a reschedule alternative — then false, and original_start_at/original_end_at carry the window the job left.
89
+ attr_accessor :window_preserved
90
+
91
+ class EnumAttributeValidator
92
+ attr_reader :datatype
93
+ attr_reader :allowable_values
94
+
95
+ def initialize(datatype, allowable_values)
96
+ @allowable_values = allowable_values.map do |value|
97
+ case datatype.to_s
98
+ when /Integer/i
99
+ value.to_i
100
+ when /Float/i
101
+ value.to_f
102
+ else
103
+ value
104
+ end
105
+ end
106
+ end
107
+
108
+ def valid?(value)
109
+ !value || allowable_values.include?(value)
110
+ end
111
+ end
112
+
113
+ # Attribute mapping from ruby-style variable name to JSON key.
114
+ def self.attribute_map
115
+ {
116
+ :'alternative_kind' => :'alternative_kind',
117
+ :'attention_cleared' => :'attention_cleared',
118
+ :'booked_minutes' => :'booked_minutes',
119
+ :'cost' => :'cost',
120
+ :'customer_name' => :'customer_name',
121
+ :'date' => :'date',
122
+ :'desired_skills' => :'desired_skills',
123
+ :'distance_km' => :'distance_km',
124
+ :'end_at' => :'end_at',
125
+ :'feasible_count' => :'feasible_count',
126
+ :'from_technician_id' => :'from_technician_id',
127
+ :'job_id' => :'job_id',
128
+ :'matched_skills' => :'matched_skills',
129
+ :'notification' => :'notification',
130
+ :'original_end_at' => :'original_end_at',
131
+ :'original_start_at' => :'original_start_at',
132
+ :'priority' => :'priority',
133
+ :'short_code' => :'short_code',
134
+ :'start_at' => :'start_at',
135
+ :'status_version' => :'status_version',
136
+ :'to_name' => :'to_name',
137
+ :'to_technician_id' => :'to_technician_id',
138
+ :'total_score' => :'total_score',
139
+ :'travel_minutes' => :'travel_minutes',
140
+ :'window_preserved' => :'window_preserved'
141
+ }
142
+ end
143
+
144
+ # Returns all the JSON keys this model knows about
145
+ def self.acceptable_attributes
146
+ attribute_map.values
147
+ end
148
+
149
+ # Attribute type mapping.
150
+ def self.openapi_types
151
+ {
152
+ :'alternative_kind' => :'String',
153
+ :'attention_cleared' => :'Boolean',
154
+ :'booked_minutes' => :'Integer',
155
+ :'cost' => :'JobRequestAbsenceAlternativeCost',
156
+ :'customer_name' => :'String',
157
+ :'date' => :'Date',
158
+ :'desired_skills' => :'Integer',
159
+ :'distance_km' => :'Float',
160
+ :'end_at' => :'Time',
161
+ :'feasible_count' => :'Integer',
162
+ :'from_technician_id' => :'String',
163
+ :'job_id' => :'String',
164
+ :'matched_skills' => :'Integer',
165
+ :'notification' => :'JobRequestAbsenceNotification',
166
+ :'original_end_at' => :'Time',
167
+ :'original_start_at' => :'Time',
168
+ :'priority' => :'String',
169
+ :'short_code' => :'String',
170
+ :'start_at' => :'Time',
171
+ :'status_version' => :'Integer',
172
+ :'to_name' => :'String',
173
+ :'to_technician_id' => :'String',
174
+ :'total_score' => :'Float',
175
+ :'travel_minutes' => :'Integer',
176
+ :'window_preserved' => :'Boolean'
177
+ }
178
+ end
179
+
180
+ # List of attributes with nullable: true
181
+ def self.openapi_nullable
182
+ Set.new([
183
+ ])
184
+ end
185
+
186
+ # Initializes the object
187
+ # @param [Hash] attributes Model attributes in the form of hash
188
+ def initialize(attributes = {})
189
+ if (!attributes.is_a?(Hash))
190
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Crisphive::JobRequestAbsenceResolvedJob` initialize method"
191
+ end
192
+
193
+ # check to see if the attribute exists and convert string to symbol for hash key
194
+ attributes = attributes.each_with_object({}) { |(k, v), h|
195
+ if (!self.class.attribute_map.key?(k.to_sym))
196
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Crisphive::JobRequestAbsenceResolvedJob`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
197
+ end
198
+ h[k.to_sym] = v
199
+ }
200
+
201
+ if attributes.key?(:'alternative_kind')
202
+ self.alternative_kind = attributes[:'alternative_kind']
203
+ end
204
+
205
+ if attributes.key?(:'attention_cleared')
206
+ self.attention_cleared = attributes[:'attention_cleared']
207
+ end
208
+
209
+ if attributes.key?(:'booked_minutes')
210
+ self.booked_minutes = attributes[:'booked_minutes']
211
+ end
212
+
213
+ if attributes.key?(:'cost')
214
+ self.cost = attributes[:'cost']
215
+ end
216
+
217
+ if attributes.key?(:'customer_name')
218
+ self.customer_name = attributes[:'customer_name']
219
+ end
220
+
221
+ if attributes.key?(:'date')
222
+ self.date = attributes[:'date']
223
+ end
224
+
225
+ if attributes.key?(:'desired_skills')
226
+ self.desired_skills = attributes[:'desired_skills']
227
+ end
228
+
229
+ if attributes.key?(:'distance_km')
230
+ self.distance_km = attributes[:'distance_km']
231
+ end
232
+
233
+ if attributes.key?(:'end_at')
234
+ self.end_at = attributes[:'end_at']
235
+ end
236
+
237
+ if attributes.key?(:'feasible_count')
238
+ self.feasible_count = attributes[:'feasible_count']
239
+ end
240
+
241
+ if attributes.key?(:'from_technician_id')
242
+ self.from_technician_id = attributes[:'from_technician_id']
243
+ end
244
+
245
+ if attributes.key?(:'job_id')
246
+ self.job_id = attributes[:'job_id']
247
+ end
248
+
249
+ if attributes.key?(:'matched_skills')
250
+ self.matched_skills = attributes[:'matched_skills']
251
+ end
252
+
253
+ if attributes.key?(:'notification')
254
+ self.notification = attributes[:'notification']
255
+ end
256
+
257
+ if attributes.key?(:'original_end_at')
258
+ self.original_end_at = attributes[:'original_end_at']
259
+ end
260
+
261
+ if attributes.key?(:'original_start_at')
262
+ self.original_start_at = attributes[:'original_start_at']
263
+ end
264
+
265
+ if attributes.key?(:'priority')
266
+ self.priority = attributes[:'priority']
267
+ end
268
+
269
+ if attributes.key?(:'short_code')
270
+ self.short_code = attributes[:'short_code']
271
+ end
272
+
273
+ if attributes.key?(:'start_at')
274
+ self.start_at = attributes[:'start_at']
275
+ end
276
+
277
+ if attributes.key?(:'status_version')
278
+ self.status_version = attributes[:'status_version']
279
+ end
280
+
281
+ if attributes.key?(:'to_name')
282
+ self.to_name = attributes[:'to_name']
283
+ end
284
+
285
+ if attributes.key?(:'to_technician_id')
286
+ self.to_technician_id = attributes[:'to_technician_id']
287
+ end
288
+
289
+ if attributes.key?(:'total_score')
290
+ self.total_score = attributes[:'total_score']
291
+ end
292
+
293
+ if attributes.key?(:'travel_minutes')
294
+ self.travel_minutes = attributes[:'travel_minutes']
295
+ end
296
+
297
+ if attributes.key?(:'window_preserved')
298
+ self.window_preserved = attributes[:'window_preserved']
299
+ end
300
+ end
301
+
302
+ # Show invalid properties with the reasons. Usually used together with valid?
303
+ # @return Array for valid properties with the reasons
304
+ def list_invalid_properties
305
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
306
+ invalid_properties = Array.new
307
+ invalid_properties
308
+ end
309
+
310
+ # Check to see if the all the properties in the model are valid
311
+ # @return true if the model is valid
312
+ def valid?
313
+ warn '[DEPRECATED] the `valid?` method is obsolete'
314
+ alternative_kind_validator = EnumAttributeValidator.new('String', ["reassign_out_of_area", "reschedule_same_day", "reschedule_later_day"])
315
+ return false unless alternative_kind_validator.valid?(@alternative_kind)
316
+ priority_validator = EnumAttributeValidator.new('String', ["p0", "p1", "p2", "p3"])
317
+ return false unless priority_validator.valid?(@priority)
318
+ true
319
+ end
320
+
321
+ # Custom attribute writer method checking allowed values (enum).
322
+ # @param [Object] alternative_kind Object to be assigned
323
+ def alternative_kind=(alternative_kind)
324
+ validator = EnumAttributeValidator.new('String', ["reassign_out_of_area", "reschedule_same_day", "reschedule_later_day"])
325
+ unless validator.valid?(alternative_kind)
326
+ fail ArgumentError, "invalid value for \"alternative_kind\", must be one of #{validator.allowable_values}."
327
+ end
328
+ @alternative_kind = alternative_kind
329
+ end
330
+
331
+ # Custom attribute writer method checking allowed values (enum).
332
+ # @param [Object] priority Object to be assigned
333
+ def priority=(priority)
334
+ validator = EnumAttributeValidator.new('String', ["p0", "p1", "p2", "p3"])
335
+ unless validator.valid?(priority)
336
+ fail ArgumentError, "invalid value for \"priority\", must be one of #{validator.allowable_values}."
337
+ end
338
+ @priority = priority
339
+ end
340
+
341
+ # Checks equality by comparing each attribute.
342
+ # @param [Object] Object to be compared
343
+ def ==(o)
344
+ return true if self.equal?(o)
345
+ self.class == o.class &&
346
+ alternative_kind == o.alternative_kind &&
347
+ attention_cleared == o.attention_cleared &&
348
+ booked_minutes == o.booked_minutes &&
349
+ cost == o.cost &&
350
+ customer_name == o.customer_name &&
351
+ date == o.date &&
352
+ desired_skills == o.desired_skills &&
353
+ distance_km == o.distance_km &&
354
+ end_at == o.end_at &&
355
+ feasible_count == o.feasible_count &&
356
+ from_technician_id == o.from_technician_id &&
357
+ job_id == o.job_id &&
358
+ matched_skills == o.matched_skills &&
359
+ notification == o.notification &&
360
+ original_end_at == o.original_end_at &&
361
+ original_start_at == o.original_start_at &&
362
+ priority == o.priority &&
363
+ short_code == o.short_code &&
364
+ start_at == o.start_at &&
365
+ status_version == o.status_version &&
366
+ to_name == o.to_name &&
367
+ to_technician_id == o.to_technician_id &&
368
+ total_score == o.total_score &&
369
+ travel_minutes == o.travel_minutes &&
370
+ window_preserved == o.window_preserved
371
+ end
372
+
373
+ # @see the `==` method
374
+ # @param [Object] Object to be compared
375
+ def eql?(o)
376
+ self == o
377
+ end
378
+
379
+ # Calculates hash code according to all attributes.
380
+ # @return [Integer] Hash code
381
+ def hash
382
+ [alternative_kind, attention_cleared, booked_minutes, cost, customer_name, date, desired_skills, distance_km, end_at, feasible_count, from_technician_id, job_id, matched_skills, notification, original_end_at, original_start_at, priority, short_code, start_at, status_version, to_name, to_technician_id, total_score, travel_minutes, window_preserved].hash
383
+ end
384
+
385
+ # Builds the object from hash
386
+ # @param [Hash] attributes Model attributes in the form of hash
387
+ # @return [Object] Returns the model itself
388
+ def self.build_from_hash(attributes)
389
+ return nil unless attributes.is_a?(Hash)
390
+ attributes = attributes.transform_keys(&:to_sym)
391
+ transformed_hash = {}
392
+ openapi_types.each_pair do |key, type|
393
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
394
+ transformed_hash["#{key}"] = nil
395
+ elsif type =~ /\AArray<(.*)>/i
396
+ # check to ensure the input is an array given that the attribute
397
+ # is documented as an array but the input is not
398
+ if attributes[attribute_map[key]].is_a?(Array)
399
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
400
+ end
401
+ elsif !attributes[attribute_map[key]].nil?
402
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
403
+ end
404
+ end
405
+ new(transformed_hash)
406
+ end
407
+
408
+ # Deserializes the data based on type
409
+ # @param string type Data type
410
+ # @param string value Value to be deserialized
411
+ # @return [Object] Deserialized data
412
+ def self._deserialize(type, value)
413
+ case type.to_sym
414
+ when :Time
415
+ Time.parse(value)
416
+ when :Date
417
+ Date.parse(value)
418
+ when :String
419
+ value.to_s
420
+ when :Integer
421
+ value.to_i
422
+ when :Float
423
+ value.to_f
424
+ when :Boolean
425
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
426
+ true
427
+ else
428
+ false
429
+ end
430
+ when :Object
431
+ # generic object (usually a Hash), return directly
432
+ value
433
+ when /\AArray<(?<inner_type>.+)>\z/
434
+ inner_type = Regexp.last_match[:inner_type]
435
+ value.map { |v| _deserialize(inner_type, v) }
436
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
437
+ k_type = Regexp.last_match[:k_type]
438
+ v_type = Regexp.last_match[:v_type]
439
+ {}.tap do |hash|
440
+ value.each do |k, v|
441
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
442
+ end
443
+ end
444
+ else # model
445
+ # models (e.g. Pet) or oneOf
446
+ klass = Crisphive.const_get(type)
447
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
448
+ end
449
+ end
450
+
451
+ # Returns the string representation of the object
452
+ # @return [String] String presentation of the object
453
+ def to_s
454
+ to_hash.to_s
455
+ end
456
+
457
+ # to_body is an alias to to_hash (backward compatibility)
458
+ # @return [Hash] Returns the object in the form of hash
459
+ def to_body
460
+ to_hash
461
+ end
462
+
463
+ # Returns the object in the form of hash
464
+ # @return [Hash] Returns the object in the form of hash
465
+ def to_hash
466
+ hash = {}
467
+ self.class.attribute_map.each_pair do |attr, param|
468
+ value = self.send(attr)
469
+ if value.nil?
470
+ is_nullable = self.class.openapi_nullable.include?(attr)
471
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
472
+ end
473
+
474
+ hash[param] = _to_hash(value)
475
+ end
476
+ hash
477
+ end
478
+
479
+ # Outputs non-array value in the form of hash
480
+ # For object, use to_hash. Otherwise, just return the value
481
+ # @param [Object] value Any valid value
482
+ # @return [Hash] Returns the value in the form of hash
483
+ def _to_hash(value)
484
+ if value.is_a?(Array)
485
+ value.compact.map { |v| _to_hash(v) }
486
+ elsif value.is_a?(Hash)
487
+ {}.tap do |hash|
488
+ value.each { |k, v| hash[k] = _to_hash(v) }
489
+ end
490
+ elsif value.respond_to? :to_hash
491
+ value.to_hash
492
+ else
493
+ value
494
+ end
495
+ end
496
+
497
+ end
498
+
499
+ end