aftership-tracking-sdk 7.0.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 (76) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/LICENSE +21 -0
  4. data/README.md +285 -0
  5. data/aftership-tracking-sdk.gemspec +27 -0
  6. data/lib/aftership-tracking-sdk/api/courier.rb +163 -0
  7. data/lib/aftership-tracking-sdk/api/estimated_delivery_date.rb +67 -0
  8. data/lib/aftership-tracking-sdk/api/last_checkpoint.rb +143 -0
  9. data/lib/aftership-tracking-sdk/api/notification.rb +403 -0
  10. data/lib/aftership-tracking-sdk/api/tracking.rb +793 -0
  11. data/lib/aftership-tracking-sdk/api_client.rb +426 -0
  12. data/lib/aftership-tracking-sdk/configuration.rb +122 -0
  13. data/lib/aftership-tracking-sdk/error.rb +125 -0
  14. data/lib/aftership-tracking-sdk/models/additional_fields_v1.rb +32 -0
  15. data/lib/aftership-tracking-sdk/models/aftership_estimated_delivery_date_tracking.rb +181 -0
  16. data/lib/aftership-tracking-sdk/models/carbon_emissions_tracking.rb +161 -0
  17. data/lib/aftership-tracking-sdk/models/checkpoint.rb +301 -0
  18. data/lib/aftership-tracking-sdk/models/coordinate_checkpoint.rb +161 -0
  19. data/lib/aftership-tracking-sdk/models/courier.rb +241 -0
  20. data/lib/aftership-tracking-sdk/models/courier_response_v1.rb +161 -0
  21. data/lib/aftership-tracking-sdk/models/custom_estimated_delivery_date_tracking.rb +181 -0
  22. data/lib/aftership-tracking-sdk/models/custom_fields_tracking_update_tracking_by_slug_tracking_number_request.rb +139 -0
  23. data/lib/aftership-tracking-sdk/models/data_courier_response_v1.rb +161 -0
  24. data/lib/aftership-tracking-sdk/models/data_notification_response_v1.rb +151 -0
  25. data/lib/aftership-tracking-sdk/models/data_tracking_delete_response_v1.rb +151 -0
  26. data/lib/aftership-tracking-sdk/models/data_tracking_response_get_multiple_v1.rb +281 -0
  27. data/lib/aftership-tracking-sdk/models/data_tracking_response_v1.rb +151 -0
  28. data/lib/aftership-tracking-sdk/models/destination_address_estimated_delivery_date_request.rb +191 -0
  29. data/lib/aftership-tracking-sdk/models/destination_address_estimated_delivery_date_response.rb +191 -0
  30. data/lib/aftership-tracking-sdk/models/detect_courier_response.rb +161 -0
  31. data/lib/aftership-tracking-sdk/models/estimated_delivery_date_request.rb +221 -0
  32. data/lib/aftership-tracking-sdk/models/estimated_delivery_date_response.rb +261 -0
  33. data/lib/aftership-tracking-sdk/models/estimated_pickup_estimated_delivery_date_request.rb +181 -0
  34. data/lib/aftership-tracking-sdk/models/estimated_pickup_estimated_delivery_date_response.rb +191 -0
  35. data/lib/aftership-tracking-sdk/models/events_checkpoint.rb +161 -0
  36. data/lib/aftership-tracking-sdk/models/first_estimated_delivery_tracking.rb +191 -0
  37. data/lib/aftership-tracking-sdk/models/get_all_couriers_response.rb +161 -0
  38. data/lib/aftership-tracking-sdk/models/get_checkpoint_by_slug_tracking_number_response.rb +211 -0
  39. data/lib/aftership-tracking-sdk/models/get_checkpoint_by_tracking_id_response.rb +211 -0
  40. data/lib/aftership-tracking-sdk/models/get_trackings_response.rb +161 -0
  41. data/lib/aftership-tracking-sdk/models/get_user_couriers_response.rb +161 -0
  42. data/lib/aftership-tracking-sdk/models/latest_estimated_delivery_tracking.rb +191 -0
  43. data/lib/aftership-tracking-sdk/models/mark_tracking_completed_by_id_request.rb +151 -0
  44. data/lib/aftership-tracking-sdk/models/mark_tracking_completed_by_slug_tracking_number_request.rb +151 -0
  45. data/lib/aftership-tracking-sdk/models/meta_v1.rb +171 -0
  46. data/lib/aftership-tracking-sdk/models/next_couriers_tracking.rb +171 -0
  47. data/lib/aftership-tracking-sdk/models/next_couriers_tracking_create_tracking_request.rb +161 -0
  48. data/lib/aftership-tracking-sdk/models/notification.rb +161 -0
  49. data/lib/aftership-tracking-sdk/models/notification_request_v1.rb +161 -0
  50. data/lib/aftership-tracking-sdk/models/notification_response_v1.rb +161 -0
  51. data/lib/aftership-tracking-sdk/models/order_processing_time_estimated_pickup_estimated_delivery_date_request.rb +161 -0
  52. data/lib/aftership-tracking-sdk/models/order_processing_time_estimated_pickup_estimated_delivery_date_response.rb +161 -0
  53. data/lib/aftership-tracking-sdk/models/origin_address_estimated_delivery_date_request.rb +191 -0
  54. data/lib/aftership-tracking-sdk/models/origin_address_estimated_delivery_date_response.rb +191 -0
  55. data/lib/aftership-tracking-sdk/models/pagination.rb +156 -0
  56. data/lib/aftership-tracking-sdk/models/partial_delete_tracking.rb +241 -0
  57. data/lib/aftership-tracking-sdk/models/partial_update_tracking.rb +251 -0
  58. data/lib/aftership-tracking-sdk/models/predict_batch_request.rb +151 -0
  59. data/lib/aftership-tracking-sdk/models/predict_batch_response.rb +151 -0
  60. data/lib/aftership-tracking-sdk/models/reason_events_checkpoint.rb +151 -0
  61. data/lib/aftership-tracking-sdk/models/slug_group_v1.rb +37 -0
  62. data/lib/aftership-tracking-sdk/models/tag_v1.rb +34 -0
  63. data/lib/aftership-tracking-sdk/models/tracking.rb +921 -0
  64. data/lib/aftership-tracking-sdk/models/tracking_create_tracking_request.rb +551 -0
  65. data/lib/aftership-tracking-sdk/models/tracking_delete_response_v1.rb +161 -0
  66. data/lib/aftership-tracking-sdk/models/tracking_detect_courier_request.rb +261 -0
  67. data/lib/aftership-tracking-sdk/models/tracking_response_get_multiple_v1.rb +161 -0
  68. data/lib/aftership-tracking-sdk/models/tracking_response_v1.rb +161 -0
  69. data/lib/aftership-tracking-sdk/models/tracking_update_tracking_by_id_request.rb +501 -0
  70. data/lib/aftership-tracking-sdk/models/tracking_update_tracking_by_slug_tracking_number_request.rb +391 -0
  71. data/lib/aftership-tracking-sdk/models/weight_estimated_delivery_date_request.rb +161 -0
  72. data/lib/aftership-tracking-sdk/models/weight_estimated_delivery_date_response.rb +161 -0
  73. data/lib/aftership-tracking-sdk/sign_string.rb +77 -0
  74. data/lib/aftership-tracking-sdk/version.rb +5 -0
  75. data/lib/aftership-tracking-sdk.rb +47 -0
  76. metadata +157 -0
@@ -0,0 +1,151 @@
1
+ # This code was auto generated by AfterShip SDK Generator.
2
+ # Do not edit the class manually.
3
+ module AftershipAPI::Model
4
+ class DataTrackingDeleteResponseV1
5
+ # Partial tracking model
6
+ # tracking?: PartialDeleteTracking;
7
+ attr_accessor :tracking
8
+
9
+ # Initializes the object
10
+ # @param [Hash] attributes Model attributes in the form of hash
11
+ def initialize(attributes = {})
12
+ if (!attributes.is_a?(Hash))
13
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AftershipAPI::DataTrackingDeleteResponseV1` initialize method"
14
+ end
15
+
16
+ attributes = attributes.each_with_object({}) { |(k, v), h|
17
+ h[k.to_sym] = v
18
+ }
19
+
20
+ if attributes.key?(:'tracking')
21
+ self.tracking = attributes[:'tracking']
22
+ end
23
+ end
24
+
25
+ # Attribute type mapping.
26
+ def self.openapi_types
27
+ {
28
+ :'tracking' => :'PartialDeleteTracking',
29
+ }
30
+ end
31
+
32
+ # Attribute mapping from ruby-style variable name to JSON key.
33
+ def self.attribute_map
34
+ {
35
+ :'tracking' => :'tracking',
36
+ }
37
+ end
38
+
39
+ # Builds the object from hash
40
+ # @param attributes [Hash] Model attributes in the form of hash
41
+ # @return [Object] Returns the model itself
42
+ def self.build_from_hash(attributes)
43
+ return nil unless attributes.is_a?(Hash)
44
+ attributes = attributes.transform_keys(&:to_sym)
45
+ transformed_hash = {}
46
+ openapi_types.each_pair do |key, type|
47
+ if attributes.key?(key) && attributes[key].nil?
48
+ transformed_hash["#{key}"] = nil
49
+ elsif type =~ /\AArray<(.*)>/i
50
+ # check to ensure the input is an array given that the attribute
51
+ # is documented as an array but the input is not
52
+ if attributes[key].is_a?(Array)
53
+ transformed_hash["#{key}"] = attributes[key].map { |v| _deserialize($1, v) }
54
+ end
55
+ elsif !attributes[key].nil?
56
+ transformed_hash["#{key}"] = _deserialize(type, attributes[key])
57
+ end
58
+ end
59
+ new(transformed_hash)
60
+ end
61
+
62
+ # Deserializes the data based on type
63
+ # @param type [String] Data type
64
+ # @param value [String] Value to be deserialized
65
+ # @return [Object] Deserialized data
66
+ def self._deserialize(type, value)
67
+ case type.to_sym
68
+ when :Time
69
+ Time.parse(value)
70
+ when :Date
71
+ Date.parse(value)
72
+ when :String
73
+ value.to_s
74
+ when :Integer
75
+ value.to_i
76
+ when :Float
77
+ value.to_f
78
+ when :Boolean
79
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
80
+ true
81
+ else
82
+ false
83
+ end
84
+ when :Object
85
+ # generic object (usually a Hash), return directly
86
+ value
87
+ when /\AArray<(?<inner_type>.+)>\z/
88
+ inner_type = Regexp.last_match[:inner_type]
89
+ value.map { |v| _deserialize(inner_type, v) }
90
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
91
+ k_type = Regexp.last_match[:k_type]
92
+ v_type = Regexp.last_match[:v_type]
93
+ {}.tap do |hash|
94
+ value.each do |k, v|
95
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
96
+ end
97
+ end
98
+ else # model
99
+ klass = AftershipAPI::Model.const_get(type)
100
+ klass.build_from_hash(value)
101
+ end
102
+ end
103
+
104
+ # Returns the string representation of the object
105
+ # @return [String] String presentation of the object
106
+ def to_s
107
+ to_hash.to_s
108
+ end
109
+
110
+ # to_body is an alias to to_hash (backward compatibility)
111
+ # @return [Hash] Returns the object in the form of hash
112
+ def to_body
113
+ to_hash
114
+ end
115
+
116
+ # Returns the object in the form of hash
117
+ # @return [Hash] Returns the object in the form of hash
118
+ def to_hash
119
+ hash = {}
120
+ self.class.attribute_map.each_pair do |attr, param|
121
+ value = self.send(attr)
122
+ next if value.nil?
123
+
124
+ hash[param] = _to_hash(value)
125
+ end
126
+ hash
127
+ end
128
+
129
+ # Outputs non-array value in the form of hash
130
+ # For object, use to_hash. Otherwise, just return the value
131
+ # @param value [Object] Any valid value
132
+ # @return [Hash] Returns the value in the form of hash
133
+ def _to_hash(value)
134
+ if value.is_a?(Array)
135
+ value.compact.map { |v| _to_hash(v) }
136
+ elsif value.is_a?(Hash)
137
+ {}.tap do |hash|
138
+ value.each { |k, v| hash[k] = _to_hash(v) }
139
+ end
140
+ elsif value.respond_to? :to_hash
141
+ value.to_hash
142
+ else
143
+ value
144
+ end
145
+ end
146
+
147
+ def to_json(*a)
148
+ to_hash.to_json(*a)
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,281 @@
1
+ # This code was auto generated by AfterShip SDK Generator.
2
+ # Do not edit the class manually.
3
+ module AftershipAPI::Model
4
+ class DataTrackingResponseGetMultipleV1
5
+ # Page to show. (Default: 1)
6
+ # page?: Integer;
7
+ attr_accessor :page
8
+
9
+ # Number of trackings each page contain. (Default: 100, Max: 200)
10
+ # limit?: Integer;
11
+ attr_accessor :limit
12
+
13
+ # Number of returned trackings
14
+ # count?: Integer;
15
+ attr_accessor :count
16
+
17
+ # Search the content of the tracking record fields: `tracking_number`, `title`, `order_id`, `customer_name`, `custom_fields`, `order_id`, `emails`, `smses`
18
+ # keyword?: String;
19
+ attr_accessor :keyword
20
+
21
+ # Unique
22
+ # slug?: String;
23
+ attr_accessor :slug
24
+
25
+ # Origin country/region of trackings. Use
26
+ # origin?: String[];
27
+ attr_accessor :origin
28
+
29
+ # Destination country/region of trackings. Use
30
+ # destination?: String[];
31
+ attr_accessor :destination
32
+
33
+ # Current status of tracking. (
34
+ # tag?: TagV1;
35
+ attr_accessor :tag
36
+
37
+ # Start date and time of trackings created. AfterShip only stores data of 120 days.
38
+ # created_at_min?: String;
39
+ attr_accessor :created_at_min
40
+
41
+ # End date and time of trackings created.
42
+ # created_at_max?: String;
43
+ attr_accessor :created_at_max
44
+
45
+ # Date and time the tracking was last updated
46
+ # last_updated_at?: String;
47
+ attr_accessor :last_updated_at
48
+
49
+ # Whether or not the shipment is returned to sender. Value is `true` when any of its checkpoints has subtag `Exception_010` (returning to sender) or `Exception_011` (returned to sender). Otherwise value is `false`
50
+ # return_to_sender?: Boolean[];
51
+ attr_accessor :return_to_sender
52
+
53
+ # Destination country/region of the tracking detected from the courier. ISO Alpha-3 (three letters). Value will be `null` if the courier doesn't provide the destination country.
54
+ # courier_destination_country_iso3?: String[];
55
+ attr_accessor :courier_destination_country_iso3
56
+
57
+ # Array of
58
+ # trackings?: Tracking[];
59
+ attr_accessor :trackings
60
+
61
+ # Initializes the object
62
+ # @param [Hash] attributes Model attributes in the form of hash
63
+ def initialize(attributes = {})
64
+ if (!attributes.is_a?(Hash))
65
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AftershipAPI::DataTrackingResponseGetMultipleV1` initialize method"
66
+ end
67
+
68
+ attributes = attributes.each_with_object({}) { |(k, v), h|
69
+ h[k.to_sym] = v
70
+ }
71
+
72
+ if attributes.key?(:'page')
73
+ self.page = attributes[:'page']
74
+ end
75
+
76
+ if attributes.key?(:'limit')
77
+ self.limit = attributes[:'limit']
78
+ end
79
+
80
+ if attributes.key?(:'count')
81
+ self.count = attributes[:'count']
82
+ end
83
+
84
+ if attributes.key?(:'keyword')
85
+ self.keyword = attributes[:'keyword']
86
+ end
87
+
88
+ if attributes.key?(:'slug')
89
+ self.slug = attributes[:'slug']
90
+ end
91
+
92
+ if attributes.key?(:'origin')
93
+ self.origin = attributes[:'origin']
94
+ end
95
+
96
+ if attributes.key?(:'destination')
97
+ self.destination = attributes[:'destination']
98
+ end
99
+
100
+ if attributes.key?(:'tag')
101
+ self.tag = attributes[:'tag']
102
+ end
103
+
104
+ if attributes.key?(:'created_at_min')
105
+ self.created_at_min = attributes[:'created_at_min']
106
+ end
107
+
108
+ if attributes.key?(:'created_at_max')
109
+ self.created_at_max = attributes[:'created_at_max']
110
+ end
111
+
112
+ if attributes.key?(:'last_updated_at')
113
+ self.last_updated_at = attributes[:'last_updated_at']
114
+ end
115
+
116
+ if attributes.key?(:'return_to_sender')
117
+ self.return_to_sender = attributes[:'return_to_sender']
118
+ end
119
+
120
+ if attributes.key?(:'courier_destination_country_iso3')
121
+ self.courier_destination_country_iso3 = attributes[:'courier_destination_country_iso3']
122
+ end
123
+
124
+ if attributes.key?(:'trackings')
125
+ self.trackings = attributes[:'trackings']
126
+ end
127
+ end
128
+
129
+ # Attribute type mapping.
130
+ def self.openapi_types
131
+ {
132
+ :'page' => :'Integer',
133
+ :'limit' => :'Integer',
134
+ :'count' => :'Integer',
135
+ :'keyword' => :'String',
136
+ :'slug' => :'String',
137
+ :'origin' => :'Array<String>',
138
+ :'destination' => :'Array<String>',
139
+ :'tag' => :'TagV1',
140
+ :'created_at_min' => :'String',
141
+ :'created_at_max' => :'String',
142
+ :'last_updated_at' => :'String',
143
+ :'return_to_sender' => :'Array<Boolean>',
144
+ :'courier_destination_country_iso3' => :'Array<String>',
145
+ :'trackings' => :'Array<Tracking>',
146
+ }
147
+ end
148
+
149
+ # Attribute mapping from ruby-style variable name to JSON key.
150
+ def self.attribute_map
151
+ {
152
+ :'page' => :'page',
153
+ :'limit' => :'limit',
154
+ :'count' => :'count',
155
+ :'keyword' => :'keyword',
156
+ :'slug' => :'slug',
157
+ :'origin' => :'origin',
158
+ :'destination' => :'destination',
159
+ :'tag' => :'tag',
160
+ :'created_at_min' => :'created_at_min',
161
+ :'created_at_max' => :'created_at_max',
162
+ :'last_updated_at' => :'last_updated_at',
163
+ :'return_to_sender' => :'return_to_sender',
164
+ :'courier_destination_country_iso3' => :'courier_destination_country_iso3',
165
+ :'trackings' => :'trackings',
166
+ }
167
+ end
168
+
169
+ # Builds the object from hash
170
+ # @param attributes [Hash] Model attributes in the form of hash
171
+ # @return [Object] Returns the model itself
172
+ def self.build_from_hash(attributes)
173
+ return nil unless attributes.is_a?(Hash)
174
+ attributes = attributes.transform_keys(&:to_sym)
175
+ transformed_hash = {}
176
+ openapi_types.each_pair do |key, type|
177
+ if attributes.key?(key) && attributes[key].nil?
178
+ transformed_hash["#{key}"] = nil
179
+ elsif type =~ /\AArray<(.*)>/i
180
+ # check to ensure the input is an array given that the attribute
181
+ # is documented as an array but the input is not
182
+ if attributes[key].is_a?(Array)
183
+ transformed_hash["#{key}"] = attributes[key].map { |v| _deserialize($1, v) }
184
+ end
185
+ elsif !attributes[key].nil?
186
+ transformed_hash["#{key}"] = _deserialize(type, attributes[key])
187
+ end
188
+ end
189
+ new(transformed_hash)
190
+ end
191
+
192
+ # Deserializes the data based on type
193
+ # @param type [String] Data type
194
+ # @param value [String] Value to be deserialized
195
+ # @return [Object] Deserialized data
196
+ def self._deserialize(type, value)
197
+ case type.to_sym
198
+ when :Time
199
+ Time.parse(value)
200
+ when :Date
201
+ Date.parse(value)
202
+ when :String
203
+ value.to_s
204
+ when :Integer
205
+ value.to_i
206
+ when :Float
207
+ value.to_f
208
+ when :Boolean
209
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
210
+ true
211
+ else
212
+ false
213
+ end
214
+ when :Object
215
+ # generic object (usually a Hash), return directly
216
+ value
217
+ when /\AArray<(?<inner_type>.+)>\z/
218
+ inner_type = Regexp.last_match[:inner_type]
219
+ value.map { |v| _deserialize(inner_type, v) }
220
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
221
+ k_type = Regexp.last_match[:k_type]
222
+ v_type = Regexp.last_match[:v_type]
223
+ {}.tap do |hash|
224
+ value.each do |k, v|
225
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
226
+ end
227
+ end
228
+ else # model
229
+ klass = AftershipAPI::Model.const_get(type)
230
+ klass.build_from_hash(value)
231
+ end
232
+ end
233
+
234
+ # Returns the string representation of the object
235
+ # @return [String] String presentation of the object
236
+ def to_s
237
+ to_hash.to_s
238
+ end
239
+
240
+ # to_body is an alias to to_hash (backward compatibility)
241
+ # @return [Hash] Returns the object in the form of hash
242
+ def to_body
243
+ to_hash
244
+ end
245
+
246
+ # Returns the object in the form of hash
247
+ # @return [Hash] Returns the object in the form of hash
248
+ def to_hash
249
+ hash = {}
250
+ self.class.attribute_map.each_pair do |attr, param|
251
+ value = self.send(attr)
252
+ next if value.nil?
253
+
254
+ hash[param] = _to_hash(value)
255
+ end
256
+ hash
257
+ end
258
+
259
+ # Outputs non-array value in the form of hash
260
+ # For object, use to_hash. Otherwise, just return the value
261
+ # @param value [Object] Any valid value
262
+ # @return [Hash] Returns the value in the form of hash
263
+ def _to_hash(value)
264
+ if value.is_a?(Array)
265
+ value.compact.map { |v| _to_hash(v) }
266
+ elsif value.is_a?(Hash)
267
+ {}.tap do |hash|
268
+ value.each { |k, v| hash[k] = _to_hash(v) }
269
+ end
270
+ elsif value.respond_to? :to_hash
271
+ value.to_hash
272
+ else
273
+ value
274
+ end
275
+ end
276
+
277
+ def to_json(*a)
278
+ to_hash.to_json(*a)
279
+ end
280
+ end
281
+ end
@@ -0,0 +1,151 @@
1
+ # This code was auto generated by AfterShip SDK Generator.
2
+ # Do not edit the class manually.
3
+ module AftershipAPI::Model
4
+ class DataTrackingResponseV1
5
+ # Object describes the tracking information.<div style="display:none; height: 0"></div>
6
+ # tracking?: Tracking;
7
+ attr_accessor :tracking
8
+
9
+ # Initializes the object
10
+ # @param [Hash] attributes Model attributes in the form of hash
11
+ def initialize(attributes = {})
12
+ if (!attributes.is_a?(Hash))
13
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AftershipAPI::DataTrackingResponseV1` initialize method"
14
+ end
15
+
16
+ attributes = attributes.each_with_object({}) { |(k, v), h|
17
+ h[k.to_sym] = v
18
+ }
19
+
20
+ if attributes.key?(:'tracking')
21
+ self.tracking = attributes[:'tracking']
22
+ end
23
+ end
24
+
25
+ # Attribute type mapping.
26
+ def self.openapi_types
27
+ {
28
+ :'tracking' => :'Tracking',
29
+ }
30
+ end
31
+
32
+ # Attribute mapping from ruby-style variable name to JSON key.
33
+ def self.attribute_map
34
+ {
35
+ :'tracking' => :'tracking',
36
+ }
37
+ end
38
+
39
+ # Builds the object from hash
40
+ # @param attributes [Hash] Model attributes in the form of hash
41
+ # @return [Object] Returns the model itself
42
+ def self.build_from_hash(attributes)
43
+ return nil unless attributes.is_a?(Hash)
44
+ attributes = attributes.transform_keys(&:to_sym)
45
+ transformed_hash = {}
46
+ openapi_types.each_pair do |key, type|
47
+ if attributes.key?(key) && attributes[key].nil?
48
+ transformed_hash["#{key}"] = nil
49
+ elsif type =~ /\AArray<(.*)>/i
50
+ # check to ensure the input is an array given that the attribute
51
+ # is documented as an array but the input is not
52
+ if attributes[key].is_a?(Array)
53
+ transformed_hash["#{key}"] = attributes[key].map { |v| _deserialize($1, v) }
54
+ end
55
+ elsif !attributes[key].nil?
56
+ transformed_hash["#{key}"] = _deserialize(type, attributes[key])
57
+ end
58
+ end
59
+ new(transformed_hash)
60
+ end
61
+
62
+ # Deserializes the data based on type
63
+ # @param type [String] Data type
64
+ # @param value [String] Value to be deserialized
65
+ # @return [Object] Deserialized data
66
+ def self._deserialize(type, value)
67
+ case type.to_sym
68
+ when :Time
69
+ Time.parse(value)
70
+ when :Date
71
+ Date.parse(value)
72
+ when :String
73
+ value.to_s
74
+ when :Integer
75
+ value.to_i
76
+ when :Float
77
+ value.to_f
78
+ when :Boolean
79
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
80
+ true
81
+ else
82
+ false
83
+ end
84
+ when :Object
85
+ # generic object (usually a Hash), return directly
86
+ value
87
+ when /\AArray<(?<inner_type>.+)>\z/
88
+ inner_type = Regexp.last_match[:inner_type]
89
+ value.map { |v| _deserialize(inner_type, v) }
90
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
91
+ k_type = Regexp.last_match[:k_type]
92
+ v_type = Regexp.last_match[:v_type]
93
+ {}.tap do |hash|
94
+ value.each do |k, v|
95
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
96
+ end
97
+ end
98
+ else # model
99
+ klass = AftershipAPI::Model.const_get(type)
100
+ klass.build_from_hash(value)
101
+ end
102
+ end
103
+
104
+ # Returns the string representation of the object
105
+ # @return [String] String presentation of the object
106
+ def to_s
107
+ to_hash.to_s
108
+ end
109
+
110
+ # to_body is an alias to to_hash (backward compatibility)
111
+ # @return [Hash] Returns the object in the form of hash
112
+ def to_body
113
+ to_hash
114
+ end
115
+
116
+ # Returns the object in the form of hash
117
+ # @return [Hash] Returns the object in the form of hash
118
+ def to_hash
119
+ hash = {}
120
+ self.class.attribute_map.each_pair do |attr, param|
121
+ value = self.send(attr)
122
+ next if value.nil?
123
+
124
+ hash[param] = _to_hash(value)
125
+ end
126
+ hash
127
+ end
128
+
129
+ # Outputs non-array value in the form of hash
130
+ # For object, use to_hash. Otherwise, just return the value
131
+ # @param value [Object] Any valid value
132
+ # @return [Hash] Returns the value in the form of hash
133
+ def _to_hash(value)
134
+ if value.is_a?(Array)
135
+ value.compact.map { |v| _to_hash(v) }
136
+ elsif value.is_a?(Hash)
137
+ {}.tap do |hash|
138
+ value.each { |k, v| hash[k] = _to_hash(v) }
139
+ end
140
+ elsif value.respond_to? :to_hash
141
+ value.to_hash
142
+ else
143
+ value
144
+ end
145
+ end
146
+
147
+ def to_json(*a)
148
+ to_hash.to_json(*a)
149
+ end
150
+ end
151
+ end