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,161 @@
1
+ # This code was auto generated by AfterShip SDK Generator.
2
+ # Do not edit the class manually.
3
+ module AftershipAPI::Model
4
+ class TrackingDeleteResponseV1
5
+ # Meta data
6
+ # meta: MetaV1;
7
+ attr_accessor :meta
8
+
9
+ #
10
+ # data: DataTrackingDeleteResponseV1;
11
+ attr_accessor :data
12
+
13
+ # Initializes the object
14
+ # @param [Hash] attributes Model attributes in the form of hash
15
+ def initialize(attributes = {})
16
+ if (!attributes.is_a?(Hash))
17
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AftershipAPI::TrackingDeleteResponseV1` initialize method"
18
+ end
19
+
20
+ attributes = attributes.each_with_object({}) { |(k, v), h|
21
+ h[k.to_sym] = v
22
+ }
23
+
24
+ if attributes.key?(:'meta')
25
+ self.meta = attributes[:'meta']
26
+ end
27
+
28
+ if attributes.key?(:'data')
29
+ self.data = attributes[:'data']
30
+ end
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.openapi_types
35
+ {
36
+ :'meta' => :'MetaV1',
37
+ :'data' => :'DataTrackingDeleteResponseV1',
38
+ }
39
+ end
40
+
41
+ # Attribute mapping from ruby-style variable name to JSON key.
42
+ def self.attribute_map
43
+ {
44
+ :'meta' => :'meta',
45
+ :'data' => :'data',
46
+ }
47
+ end
48
+
49
+ # Builds the object from hash
50
+ # @param attributes [Hash] Model attributes in the form of hash
51
+ # @return [Object] Returns the model itself
52
+ def self.build_from_hash(attributes)
53
+ return nil unless attributes.is_a?(Hash)
54
+ attributes = attributes.transform_keys(&:to_sym)
55
+ transformed_hash = {}
56
+ openapi_types.each_pair do |key, type|
57
+ if attributes.key?(key) && attributes[key].nil?
58
+ transformed_hash["#{key}"] = nil
59
+ elsif type =~ /\AArray<(.*)>/i
60
+ # check to ensure the input is an array given that the attribute
61
+ # is documented as an array but the input is not
62
+ if attributes[key].is_a?(Array)
63
+ transformed_hash["#{key}"] = attributes[key].map { |v| _deserialize($1, v) }
64
+ end
65
+ elsif !attributes[key].nil?
66
+ transformed_hash["#{key}"] = _deserialize(type, attributes[key])
67
+ end
68
+ end
69
+ new(transformed_hash)
70
+ end
71
+
72
+ # Deserializes the data based on type
73
+ # @param type [String] Data type
74
+ # @param value [String] Value to be deserialized
75
+ # @return [Object] Deserialized data
76
+ def self._deserialize(type, value)
77
+ case type.to_sym
78
+ when :Time
79
+ Time.parse(value)
80
+ when :Date
81
+ Date.parse(value)
82
+ when :String
83
+ value.to_s
84
+ when :Integer
85
+ value.to_i
86
+ when :Float
87
+ value.to_f
88
+ when :Boolean
89
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
90
+ true
91
+ else
92
+ false
93
+ end
94
+ when :Object
95
+ # generic object (usually a Hash), return directly
96
+ value
97
+ when /\AArray<(?<inner_type>.+)>\z/
98
+ inner_type = Regexp.last_match[:inner_type]
99
+ value.map { |v| _deserialize(inner_type, v) }
100
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
101
+ k_type = Regexp.last_match[:k_type]
102
+ v_type = Regexp.last_match[:v_type]
103
+ {}.tap do |hash|
104
+ value.each do |k, v|
105
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
106
+ end
107
+ end
108
+ else # model
109
+ klass = AftershipAPI::Model.const_get(type)
110
+ klass.build_from_hash(value)
111
+ end
112
+ end
113
+
114
+ # Returns the string representation of the object
115
+ # @return [String] String presentation of the object
116
+ def to_s
117
+ to_hash.to_s
118
+ end
119
+
120
+ # to_body is an alias to to_hash (backward compatibility)
121
+ # @return [Hash] Returns the object in the form of hash
122
+ def to_body
123
+ to_hash
124
+ end
125
+
126
+ # Returns the object in the form of hash
127
+ # @return [Hash] Returns the object in the form of hash
128
+ def to_hash
129
+ hash = {}
130
+ self.class.attribute_map.each_pair do |attr, param|
131
+ value = self.send(attr)
132
+ next if value.nil?
133
+
134
+ hash[param] = _to_hash(value)
135
+ end
136
+ hash
137
+ end
138
+
139
+ # Outputs non-array value in the form of hash
140
+ # For object, use to_hash. Otherwise, just return the value
141
+ # @param value [Object] Any valid value
142
+ # @return [Hash] Returns the value in the form of hash
143
+ def _to_hash(value)
144
+ if value.is_a?(Array)
145
+ value.compact.map { |v| _to_hash(v) }
146
+ elsif value.is_a?(Hash)
147
+ {}.tap do |hash|
148
+ value.each { |k, v| hash[k] = _to_hash(v) }
149
+ end
150
+ elsif value.respond_to? :to_hash
151
+ value.to_hash
152
+ else
153
+ value
154
+ end
155
+ end
156
+
157
+ def to_json(*a)
158
+ to_hash.to_json(*a)
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,261 @@
1
+ # This code was auto generated by AfterShip SDK Generator.
2
+ # Do not edit the class manually.
3
+ module AftershipAPI::Model
4
+ class TrackingDetectCourierRequest
5
+ # Tracking number of a shipment.
6
+ # tracking_number: String;
7
+ attr_accessor :tracking_number
8
+
9
+ # If not specified, Aftership will automatically detect the courier based on the tracking number format and your . Use array or comma separated to input a list of couriers for auto detect. Cannot be used with slug_group at the same time.
10
+ # slug?: String[];
11
+ attr_accessor :slug
12
+
13
+ # The postal code of receiver's address. Required by some couriers. Refer to for more details
14
+ # tracking_postal_code?: String;
15
+ attr_accessor :tracking_postal_code
16
+
17
+ # Shipping date in `YYYYMMDD` format. Required by some couriers. Refer to for more details
18
+ # tracking_ship_date?: String;
19
+ attr_accessor :tracking_ship_date
20
+
21
+ # Account number of the shipper for a specific courier. Required by some couriers. Refer to for more details
22
+ # tracking_account_number?: String;
23
+ attr_accessor :tracking_account_number
24
+
25
+ # Key of the shipment for a specific courier. Required by some couriers. Refer to for more details
26
+ # tracking_key?: String;
27
+ attr_accessor :tracking_key
28
+
29
+ # Origin Country/Region of the shipment for a specific courier. Required by some couriers.
30
+ # tracking_origin_country?: String;
31
+ attr_accessor :tracking_origin_country
32
+
33
+ # Destination Country/Region of the shipment for a specific courier. Required by some couriers. Refer to for more details
34
+ # tracking_destination_country?: String;
35
+ attr_accessor :tracking_destination_country
36
+
37
+ # State of the destination shipping address of the shipment. Required by some couriers.
38
+ # tracking_state?: String;
39
+ attr_accessor :tracking_state
40
+
41
+ # Slug group is a group of slugs which belong to same courier. For example, when you inpit "fedex-group" as slug_group, AfterShip will detect the tracking with "fedex-uk", "fedex-fims", and other slugs which belong to "fedex". It cannot be used with slug at the same time. (
42
+ # slug_group?: SlugGroupV1;
43
+ attr_accessor :slug_group
44
+
45
+ # Enter .
46
+ # origin_country_iso3?: String;
47
+ attr_accessor :origin_country_iso3
48
+
49
+ # Enter .
50
+ # destination_country_iso3?: String;
51
+ attr_accessor :destination_country_iso3
52
+
53
+ # Initializes the object
54
+ # @param [Hash] attributes Model attributes in the form of hash
55
+ def initialize(attributes = {})
56
+ if (!attributes.is_a?(Hash))
57
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AftershipAPI::TrackingDetectCourierRequest` initialize method"
58
+ end
59
+
60
+ attributes = attributes.each_with_object({}) { |(k, v), h|
61
+ h[k.to_sym] = v
62
+ }
63
+
64
+ if attributes.key?(:'tracking_number')
65
+ self.tracking_number = attributes[:'tracking_number']
66
+ end
67
+
68
+ if attributes.key?(:'slug')
69
+ self.slug = attributes[:'slug']
70
+ end
71
+
72
+ if attributes.key?(:'tracking_postal_code')
73
+ self.tracking_postal_code = attributes[:'tracking_postal_code']
74
+ end
75
+
76
+ if attributes.key?(:'tracking_ship_date')
77
+ self.tracking_ship_date = attributes[:'tracking_ship_date']
78
+ end
79
+
80
+ if attributes.key?(:'tracking_account_number')
81
+ self.tracking_account_number = attributes[:'tracking_account_number']
82
+ end
83
+
84
+ if attributes.key?(:'tracking_key')
85
+ self.tracking_key = attributes[:'tracking_key']
86
+ end
87
+
88
+ if attributes.key?(:'tracking_origin_country')
89
+ self.tracking_origin_country = attributes[:'tracking_origin_country']
90
+ end
91
+
92
+ if attributes.key?(:'tracking_destination_country')
93
+ self.tracking_destination_country = attributes[:'tracking_destination_country']
94
+ end
95
+
96
+ if attributes.key?(:'tracking_state')
97
+ self.tracking_state = attributes[:'tracking_state']
98
+ end
99
+
100
+ if attributes.key?(:'slug_group')
101
+ self.slug_group = attributes[:'slug_group']
102
+ end
103
+
104
+ if attributes.key?(:'origin_country_iso3')
105
+ self.origin_country_iso3 = attributes[:'origin_country_iso3']
106
+ end
107
+
108
+ if attributes.key?(:'destination_country_iso3')
109
+ self.destination_country_iso3 = attributes[:'destination_country_iso3']
110
+ end
111
+ end
112
+
113
+ # Attribute type mapping.
114
+ def self.openapi_types
115
+ {
116
+ :'tracking_number' => :'String',
117
+ :'slug' => :'Array<String>',
118
+ :'tracking_postal_code' => :'String',
119
+ :'tracking_ship_date' => :'String',
120
+ :'tracking_account_number' => :'String',
121
+ :'tracking_key' => :'String',
122
+ :'tracking_origin_country' => :'String',
123
+ :'tracking_destination_country' => :'String',
124
+ :'tracking_state' => :'String',
125
+ :'slug_group' => :'SlugGroupV1',
126
+ :'origin_country_iso3' => :'String',
127
+ :'destination_country_iso3' => :'String',
128
+ }
129
+ end
130
+
131
+ # Attribute mapping from ruby-style variable name to JSON key.
132
+ def self.attribute_map
133
+ {
134
+ :'tracking_number' => :'tracking_number',
135
+ :'slug' => :'slug',
136
+ :'tracking_postal_code' => :'tracking_postal_code',
137
+ :'tracking_ship_date' => :'tracking_ship_date',
138
+ :'tracking_account_number' => :'tracking_account_number',
139
+ :'tracking_key' => :'tracking_key',
140
+ :'tracking_origin_country' => :'tracking_origin_country',
141
+ :'tracking_destination_country' => :'tracking_destination_country',
142
+ :'tracking_state' => :'tracking_state',
143
+ :'slug_group' => :'slug_group',
144
+ :'origin_country_iso3' => :'origin_country_iso3',
145
+ :'destination_country_iso3' => :'destination_country_iso3',
146
+ }
147
+ end
148
+
149
+ # Builds the object from hash
150
+ # @param attributes [Hash] Model attributes in the form of hash
151
+ # @return [Object] Returns the model itself
152
+ def self.build_from_hash(attributes)
153
+ return nil unless attributes.is_a?(Hash)
154
+ attributes = attributes.transform_keys(&:to_sym)
155
+ transformed_hash = {}
156
+ openapi_types.each_pair do |key, type|
157
+ if attributes.key?(key) && attributes[key].nil?
158
+ transformed_hash["#{key}"] = nil
159
+ elsif type =~ /\AArray<(.*)>/i
160
+ # check to ensure the input is an array given that the attribute
161
+ # is documented as an array but the input is not
162
+ if attributes[key].is_a?(Array)
163
+ transformed_hash["#{key}"] = attributes[key].map { |v| _deserialize($1, v) }
164
+ end
165
+ elsif !attributes[key].nil?
166
+ transformed_hash["#{key}"] = _deserialize(type, attributes[key])
167
+ end
168
+ end
169
+ new(transformed_hash)
170
+ end
171
+
172
+ # Deserializes the data based on type
173
+ # @param type [String] Data type
174
+ # @param value [String] Value to be deserialized
175
+ # @return [Object] Deserialized data
176
+ def self._deserialize(type, value)
177
+ case type.to_sym
178
+ when :Time
179
+ Time.parse(value)
180
+ when :Date
181
+ Date.parse(value)
182
+ when :String
183
+ value.to_s
184
+ when :Integer
185
+ value.to_i
186
+ when :Float
187
+ value.to_f
188
+ when :Boolean
189
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
190
+ true
191
+ else
192
+ false
193
+ end
194
+ when :Object
195
+ # generic object (usually a Hash), return directly
196
+ value
197
+ when /\AArray<(?<inner_type>.+)>\z/
198
+ inner_type = Regexp.last_match[:inner_type]
199
+ value.map { |v| _deserialize(inner_type, v) }
200
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
201
+ k_type = Regexp.last_match[:k_type]
202
+ v_type = Regexp.last_match[:v_type]
203
+ {}.tap do |hash|
204
+ value.each do |k, v|
205
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
206
+ end
207
+ end
208
+ else # model
209
+ klass = AftershipAPI::Model.const_get(type)
210
+ klass.build_from_hash(value)
211
+ end
212
+ end
213
+
214
+ # Returns the string representation of the object
215
+ # @return [String] String presentation of the object
216
+ def to_s
217
+ to_hash.to_s
218
+ end
219
+
220
+ # to_body is an alias to to_hash (backward compatibility)
221
+ # @return [Hash] Returns the object in the form of hash
222
+ def to_body
223
+ to_hash
224
+ end
225
+
226
+ # Returns the object in the form of hash
227
+ # @return [Hash] Returns the object in the form of hash
228
+ def to_hash
229
+ hash = {}
230
+ self.class.attribute_map.each_pair do |attr, param|
231
+ value = self.send(attr)
232
+ next if value.nil?
233
+
234
+ hash[param] = _to_hash(value)
235
+ end
236
+ hash
237
+ end
238
+
239
+ # Outputs non-array value in the form of hash
240
+ # For object, use to_hash. Otherwise, just return the value
241
+ # @param value [Object] Any valid value
242
+ # @return [Hash] Returns the value in the form of hash
243
+ def _to_hash(value)
244
+ if value.is_a?(Array)
245
+ value.compact.map { |v| _to_hash(v) }
246
+ elsif value.is_a?(Hash)
247
+ {}.tap do |hash|
248
+ value.each { |k, v| hash[k] = _to_hash(v) }
249
+ end
250
+ elsif value.respond_to? :to_hash
251
+ value.to_hash
252
+ else
253
+ value
254
+ end
255
+ end
256
+
257
+ def to_json(*a)
258
+ to_hash.to_json(*a)
259
+ end
260
+ end
261
+ end
@@ -0,0 +1,161 @@
1
+ # This code was auto generated by AfterShip SDK Generator.
2
+ # Do not edit the class manually.
3
+ module AftershipAPI::Model
4
+ class TrackingResponseGetMultipleV1
5
+ # Meta data
6
+ # meta: MetaV1;
7
+ attr_accessor :meta
8
+
9
+ #
10
+ # data?: DataTrackingResponseGetMultipleV1;
11
+ attr_accessor :data
12
+
13
+ # Initializes the object
14
+ # @param [Hash] attributes Model attributes in the form of hash
15
+ def initialize(attributes = {})
16
+ if (!attributes.is_a?(Hash))
17
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AftershipAPI::TrackingResponseGetMultipleV1` initialize method"
18
+ end
19
+
20
+ attributes = attributes.each_with_object({}) { |(k, v), h|
21
+ h[k.to_sym] = v
22
+ }
23
+
24
+ if attributes.key?(:'meta')
25
+ self.meta = attributes[:'meta']
26
+ end
27
+
28
+ if attributes.key?(:'data')
29
+ self.data = attributes[:'data']
30
+ end
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.openapi_types
35
+ {
36
+ :'meta' => :'MetaV1',
37
+ :'data' => :'DataTrackingResponseGetMultipleV1',
38
+ }
39
+ end
40
+
41
+ # Attribute mapping from ruby-style variable name to JSON key.
42
+ def self.attribute_map
43
+ {
44
+ :'meta' => :'meta',
45
+ :'data' => :'data',
46
+ }
47
+ end
48
+
49
+ # Builds the object from hash
50
+ # @param attributes [Hash] Model attributes in the form of hash
51
+ # @return [Object] Returns the model itself
52
+ def self.build_from_hash(attributes)
53
+ return nil unless attributes.is_a?(Hash)
54
+ attributes = attributes.transform_keys(&:to_sym)
55
+ transformed_hash = {}
56
+ openapi_types.each_pair do |key, type|
57
+ if attributes.key?(key) && attributes[key].nil?
58
+ transformed_hash["#{key}"] = nil
59
+ elsif type =~ /\AArray<(.*)>/i
60
+ # check to ensure the input is an array given that the attribute
61
+ # is documented as an array but the input is not
62
+ if attributes[key].is_a?(Array)
63
+ transformed_hash["#{key}"] = attributes[key].map { |v| _deserialize($1, v) }
64
+ end
65
+ elsif !attributes[key].nil?
66
+ transformed_hash["#{key}"] = _deserialize(type, attributes[key])
67
+ end
68
+ end
69
+ new(transformed_hash)
70
+ end
71
+
72
+ # Deserializes the data based on type
73
+ # @param type [String] Data type
74
+ # @param value [String] Value to be deserialized
75
+ # @return [Object] Deserialized data
76
+ def self._deserialize(type, value)
77
+ case type.to_sym
78
+ when :Time
79
+ Time.parse(value)
80
+ when :Date
81
+ Date.parse(value)
82
+ when :String
83
+ value.to_s
84
+ when :Integer
85
+ value.to_i
86
+ when :Float
87
+ value.to_f
88
+ when :Boolean
89
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
90
+ true
91
+ else
92
+ false
93
+ end
94
+ when :Object
95
+ # generic object (usually a Hash), return directly
96
+ value
97
+ when /\AArray<(?<inner_type>.+)>\z/
98
+ inner_type = Regexp.last_match[:inner_type]
99
+ value.map { |v| _deserialize(inner_type, v) }
100
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
101
+ k_type = Regexp.last_match[:k_type]
102
+ v_type = Regexp.last_match[:v_type]
103
+ {}.tap do |hash|
104
+ value.each do |k, v|
105
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
106
+ end
107
+ end
108
+ else # model
109
+ klass = AftershipAPI::Model.const_get(type)
110
+ klass.build_from_hash(value)
111
+ end
112
+ end
113
+
114
+ # Returns the string representation of the object
115
+ # @return [String] String presentation of the object
116
+ def to_s
117
+ to_hash.to_s
118
+ end
119
+
120
+ # to_body is an alias to to_hash (backward compatibility)
121
+ # @return [Hash] Returns the object in the form of hash
122
+ def to_body
123
+ to_hash
124
+ end
125
+
126
+ # Returns the object in the form of hash
127
+ # @return [Hash] Returns the object in the form of hash
128
+ def to_hash
129
+ hash = {}
130
+ self.class.attribute_map.each_pair do |attr, param|
131
+ value = self.send(attr)
132
+ next if value.nil?
133
+
134
+ hash[param] = _to_hash(value)
135
+ end
136
+ hash
137
+ end
138
+
139
+ # Outputs non-array value in the form of hash
140
+ # For object, use to_hash. Otherwise, just return the value
141
+ # @param value [Object] Any valid value
142
+ # @return [Hash] Returns the value in the form of hash
143
+ def _to_hash(value)
144
+ if value.is_a?(Array)
145
+ value.compact.map { |v| _to_hash(v) }
146
+ elsif value.is_a?(Hash)
147
+ {}.tap do |hash|
148
+ value.each { |k, v| hash[k] = _to_hash(v) }
149
+ end
150
+ elsif value.respond_to? :to_hash
151
+ value.to_hash
152
+ else
153
+ value
154
+ end
155
+ end
156
+
157
+ def to_json(*a)
158
+ to_hash.to_json(*a)
159
+ end
160
+ end
161
+ end