shipengine_sdk 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +96 -0
  4. data/lib/faraday/raise_http_exception.rb +77 -0
  5. data/lib/shipengine/configuration.rb +43 -0
  6. data/lib/shipengine/constants/base.rb +22 -0
  7. data/lib/shipengine/constants/countries.rb +16 -0
  8. data/lib/shipengine/constants.rb +4 -0
  9. data/lib/shipengine/domain/addresses/address_validation.rb +118 -0
  10. data/lib/shipengine/domain/addresses.rb +76 -0
  11. data/lib/shipengine/domain/carriers/list_carriers.rb +140 -0
  12. data/lib/shipengine/domain/carriers.rb +93 -0
  13. data/lib/shipengine/domain/labels/create_from_rate.rb +163 -0
  14. data/lib/shipengine/domain/labels/create_from_shipment_details.rb +163 -0
  15. data/lib/shipengine/domain/labels/void_label.rb +18 -0
  16. data/lib/shipengine/domain/labels.rb +297 -0
  17. data/lib/shipengine/domain/rates/get_with_shipment_details.rb +347 -0
  18. data/lib/shipengine/domain/rates.rb +379 -0
  19. data/lib/shipengine/domain/tracking/track_using_carrier_code_and_tracking_number.rb +45 -0
  20. data/lib/shipengine/domain/tracking/track_using_label_id.rb +45 -0
  21. data/lib/shipengine/domain/tracking.rb +103 -0
  22. data/lib/shipengine/domain.rb +7 -0
  23. data/lib/shipengine/exceptions/error_code.rb +254 -0
  24. data/lib/shipengine/exceptions/error_type.rb +49 -0
  25. data/lib/shipengine/exceptions.rb +132 -0
  26. data/lib/shipengine/internal_client.rb +91 -0
  27. data/lib/shipengine/utils/base58.rb +109 -0
  28. data/lib/shipengine/utils/pretty_print.rb +29 -0
  29. data/lib/shipengine/utils/request_id.rb +16 -0
  30. data/lib/shipengine/utils/user_agent.rb +24 -0
  31. data/lib/shipengine/utils/validate.rb +106 -0
  32. data/lib/shipengine/version.rb +5 -0
  33. data/lib/shipengine.rb +164 -0
  34. metadata +117 -0
@@ -0,0 +1,379 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'hashie'
4
+ require_relative 'rates/get_with_shipment_details'
5
+
6
+ module ShipEngine
7
+ module Domain
8
+ class Rates # rubocop:todo Metrics/ClassLength
9
+ require 'shipengine/constants'
10
+
11
+ # @param [ShipEngine::InternalClient] internal_client
12
+ def initialize(internal_client)
13
+ @internal_client = internal_client
14
+ end
15
+
16
+ # @param shipment_details [Hash]
17
+ # @param config [Hash?]
18
+ #
19
+ # @return [ShipEngine::Domain::Rates::GetWithShipmentDetails::Response]
20
+ #
21
+ # @see https://shipengine.github.io/shipengine-openapi/#operation/validate_address
22
+ def get_rates_with_shipment_details(shipment_details, config)
23
+ response = @internal_client.post('/v1/rates', shipment_details, config)
24
+ rates_api_result = response.body
25
+ mash_result = Hashie::Mash.new(rates_api_result)
26
+
27
+ items = mash_result.items.map do |item|
28
+ GetWithShipmentDetails::Response::Item.new(
29
+ name: item.name,
30
+ sales_order_id: item.sales_order_id,
31
+ sales_order_item_id: item.sales_order_item_id,
32
+ quantity: item.quantity,
33
+ sku: item.sku,
34
+ external_order_id: item.external_order_id,
35
+ external_order_item_id: item.external_order_item_id,
36
+ asin: item.asin,
37
+ order_source_code: item.order_source_code
38
+ )
39
+ end
40
+
41
+ tax_identifiers = nil
42
+ if mash_result.tax_identifiers
43
+ tax_identifiers = mash_result.tax_identifiers.map do |tax_identifier|
44
+ GetWithShipmentDetails::Response::TaxIdentifier.new(
45
+ taxable_entity_type: tax_identifier.taxable_entity_type,
46
+ identifier_type: tax_identifier.identifier_type,
47
+ issuing_authority: tax_identifier.issuing_authority,
48
+ value: tax_identifier.value
49
+ )
50
+ end
51
+ end
52
+
53
+ tags = mash_result.tags.map do |tag|
54
+ GetWithShipmentDetails::Response::Tag.new(
55
+ name: tag.name
56
+ )
57
+ end
58
+
59
+ packages = mash_result.packages.map do |package|
60
+ weight = GetWithShipmentDetails::Response::Weight.new(
61
+ value: package.weight.value,
62
+ unit: package.weight.unit
63
+ )
64
+
65
+ dimensions = nil
66
+ if package.dimensions
67
+ dimensions = GetWithShipmentDetails::Response::Dimensions.new(
68
+ unit: package.dimensions.unit,
69
+ length: package.dimensions['length'],
70
+ width: package.dimensions.width,
71
+ height: package.dimensions.height
72
+ )
73
+ end
74
+
75
+ insured_value = nil
76
+ if package.insured_value
77
+ insured_value = GetWithShipmentDetails::Response::MonetaryValue.new(
78
+ currency: package.insured_value.currency,
79
+ amount: package.insured_value.amount
80
+ )
81
+ end
82
+
83
+ label_messages = nil
84
+ if package.label_messages
85
+ label_messages = GetWithShipmentDetails::Response::Package::LabelMessages.new(
86
+ reference1: package.label_messages.reference1,
87
+ reference2: package.label_messages.reference2,
88
+ reference3: package.label_messages.reference3
89
+ )
90
+ end
91
+
92
+ GetWithShipmentDetails::Response::Package.new(
93
+ package_code: package.package_code,
94
+ weight:,
95
+ dimensions:,
96
+ insured_value:,
97
+ tracking_number: package.tracking_number,
98
+ label_messages:,
99
+ external_package_id: package.external_package_id
100
+ )
101
+ end
102
+
103
+ customs = nil
104
+ if mash_result.customs&.customs_items
105
+ customs_items = mash_result.customs.customs_items.map do |customs_item|
106
+ value = nil
107
+ if customs_item.value
108
+ value = GetWithShipmentDetails::Response::MonetaryValue.new(
109
+ currency: customs_item.value.currency,
110
+ amount: customs_item.value.amount
111
+ )
112
+ end
113
+
114
+ GetWithShipmentDetails::Response::Customs::CustomsItem.new(
115
+ customs_item_id: customs_item.customs_item_id,
116
+ description: customs_item.description,
117
+ quantity: customs_item.quantity,
118
+ value:,
119
+ harmonized_tariff_code: customs_item.harmonized_tariff_code,
120
+ country_of_origin: customs_item.country_of_origin,
121
+ unit_of_measure: customs_item.unit_of_measure,
122
+ sku: customs_item.sku,
123
+ sku_description: customs_item.sku_description
124
+ )
125
+ end
126
+
127
+ customs = GetWithShipmentDetails::Response::Customs.new(
128
+ contents: mash_result.customs.contents,
129
+ non_delivery: mash_result.customs.non_delivery,
130
+ customs_items:
131
+ )
132
+ end
133
+
134
+ ship_to = GetWithShipmentDetails::Response::Address.new(
135
+ address_line1: mash_result.ship_to.address_line1,
136
+ address_line2: mash_result.ship_to.address_line2,
137
+ address_line3: mash_result.ship_to.address_line3,
138
+ name: mash_result.ship_to.name,
139
+ company_name: mash_result.ship_to.company_name,
140
+ phone: mash_result.ship_to.phone,
141
+ city_locality: mash_result.ship_to.city_locality,
142
+ state_province: mash_result.ship_to.state_province,
143
+ postal_code: mash_result.ship_to.postal_code,
144
+ country_code: mash_result.ship_to.country_code,
145
+ address_residential_indicator: mash_result.ship_to.address_residential_indicator
146
+ )
147
+
148
+ ship_from = GetWithShipmentDetails::Response::Address.new(
149
+ address_line1: mash_result.ship_from.address_line1,
150
+ address_line2: mash_result.ship_from.address_line2,
151
+ address_line3: mash_result.ship_from.address_line3,
152
+ name: mash_result.ship_from.name,
153
+ company_name: mash_result.ship_from.company_name,
154
+ phone: mash_result.ship_from.phone,
155
+ city_locality: mash_result.ship_from.city_locality,
156
+ state_province: mash_result.ship_from.state_province,
157
+ postal_code: mash_result.ship_from.postal_code,
158
+ country_code: mash_result.ship_from.country_code,
159
+ address_residential_indicator: mash_result.ship_from.address_residential_indicator
160
+ )
161
+
162
+ return_to = GetWithShipmentDetails::Response::Address.new(
163
+ address_line1: mash_result.return_to.address_line1,
164
+ address_line2: mash_result.return_to.address_line2,
165
+ address_line3: mash_result.return_to.address_line3,
166
+ name: mash_result.return_to.name,
167
+ company_name: mash_result.return_to.company_name,
168
+ phone: mash_result.return_to.phone,
169
+ city_locality: mash_result.return_to.city_locality,
170
+ state_province: mash_result.return_to.state_province,
171
+ postal_code: mash_result.return_to.postal_code,
172
+ country_code: mash_result.return_to.country_code,
173
+ address_residential_indicator: mash_result.return_to.address_residential_indicator
174
+ )
175
+
176
+ dry_ice_weight = nil
177
+ if mash_result.advanced_options.dry_ice_weight
178
+ dry_ice_weight = GetWithShipmentDetails::Response::Weight.new(
179
+ value: mash_result.advanced_options.dry_ice_weight.value,
180
+ unit: mash_result.advanced_options.dry_ice_weight.unit
181
+ )
182
+ end
183
+
184
+ collect_on_delivery = nil
185
+ if mash_result.advanced_options.collect_on_delivery
186
+
187
+ payment_amount = nil
188
+ if mash_result.advanced_options.collect_on_delivery.payment_amount
189
+ payment_amount = GetWithShipmentDetails::Response::MonetaryValue.new(
190
+ currency: mash_result.advanced_options.collect_on_delivery.payment_amount.currency,
191
+ amount: mash_result.advanced_options.collect_on_delivery.payment_amount.amount
192
+ )
193
+ end
194
+
195
+ collect_on_delivery = GetWithShipmentDetails::Response::AdvancedOptions::CollectOnDelivery.new(
196
+ payment_type: mash_result.advanced_options.collect_on_delivery.payment_type,
197
+ payment_amount:
198
+ )
199
+ end
200
+
201
+ advanced_options = GetWithShipmentDetails::Response::AdvancedOptions.new(
202
+ bill_to_account: mash_result.advanced_options.bill_to_account,
203
+ bill_to_country_code: mash_result.advanced_options.bill_to_country_code,
204
+ bill_to_party: mash_result.advanced_options.bill_to_party,
205
+ bill_to_postal_code: mash_result.advanced_options.bill_to_postal_code,
206
+ contains_alcohol: mash_result.advanced_options.contains_alcohol,
207
+ delivered_duty_paid: mash_result.advanced_options.delivered_duty_paid,
208
+ dry_ice: mash_result.advanced_options.dry_ice,
209
+ dry_ice_weight:,
210
+ non_machinable: mash_result.advanced_options.non_machinable,
211
+ saturday_delivery: mash_result.advanced_options.saturday_delivery,
212
+ use_ups_ground_freight_pricing: mash_result.advanced_options.use_ups_ground_freight_pricing,
213
+ freight_class: mash_result.advanced_options.freight_class,
214
+ custom_field1: mash_result.advanced_options.custom_field1,
215
+ custom_field2: mash_result.advanced_options.custom_field2,
216
+ custom_field3: mash_result.advanced_options.custom_field3,
217
+ origin_type: mash_result.advanced_options.origin_type,
218
+ shipper_release: mash_result.advanced_options.shipper_release,
219
+ collect_on_delivery:
220
+ )
221
+
222
+ total_weight = nil
223
+ if mash_result.total_weight
224
+ total_weight = GetWithShipmentDetails::Response::Weight.new(
225
+ value: mash_result.total_weight.value,
226
+ unit: mash_result.total_weight.unit
227
+ )
228
+ end
229
+
230
+ rates = mash_result.rate_response.rates.map do |rate|
231
+ tax_amount = nil
232
+ if rate.tax_amount
233
+ tax_amount = GetWithShipmentDetails::Response::MonetaryValue.new(
234
+ currency: rate.tax_amount.currency,
235
+ amount: rate.tax_amount.amount
236
+ )
237
+ end
238
+
239
+ GetWithShipmentDetails::Response::RateResponse::Rate.new(
240
+ rate_id: rate.rate_id,
241
+ rate_type: rate.rate_type,
242
+ carrier_id: rate.carrier_id,
243
+ shipping_amount: GetWithShipmentDetails::Response::MonetaryValue.new(
244
+ currency: rate.shipping_amount.currency,
245
+ amount: rate.shipping_amount.amount
246
+ ),
247
+ insurance_amount: GetWithShipmentDetails::Response::MonetaryValue.new(
248
+ currency: rate.insurance_amount.currency,
249
+ amount: rate.insurance_amount.amount
250
+ ),
251
+ confirmation_amount: GetWithShipmentDetails::Response::MonetaryValue.new(
252
+ currency: rate.confirmation_amount.currency,
253
+ amount: rate.confirmation_amount.amount
254
+ ),
255
+ other_amount: GetWithShipmentDetails::Response::MonetaryValue.new(
256
+ currency: rate.other_amount.currency,
257
+ amount: rate.other_amount.amount
258
+ ),
259
+ tax_amount:,
260
+ zone: rate.zone,
261
+ package_type: rate.package_type,
262
+ delivery_days: rate.delivery_days,
263
+ guaranteed_service: rate.guaranteed_service,
264
+ estimated_delivery_date: rate.estimated_delivery_date,
265
+ carrier_delivery_days: rate.carrier_delivery_days,
266
+ ship_date: rate.ship_date,
267
+ negotiated_rate: rate.negotiated_rate,
268
+ service_type: rate.service_type,
269
+ service_code: rate.service_code,
270
+ trackable: rate.trackable,
271
+ carrier_code: rate.carrier_code,
272
+ carrier_nickname: rate.carrier_nickname,
273
+ carrier_friendly_name: rate.carrier_friendly_name,
274
+ validation_status: rate.validation_status,
275
+ warning_messages: rate.warning_messages,
276
+ error_messages: rate.error_messages
277
+ )
278
+ end
279
+
280
+ invalid_rates = mash_result.rate_response.invalid_rates.map do |rate|
281
+ tax_amount = nil
282
+ if rate.tax_amount
283
+ tax_amount = GetWithShipmentDetails::Response::MonetaryValue.new(
284
+ currency: rate.tax_amount.currency,
285
+ amount: rate.tax_amount.amount
286
+ )
287
+ end
288
+
289
+ GetWithShipmentDetails::Response::RateResponse::Rate.new(
290
+ rate_id: rate.rate_id,
291
+ rate_type: rate.rate_type,
292
+ carrier_id: rate.carrier_id,
293
+ shipping_amount: GetWithShipmentDetails::Response::MonetaryValue.new(
294
+ currency: rate.shipping_amount.currency,
295
+ amount: rate.shipping_amount.amount
296
+ ),
297
+ insurance_amount: GetWithShipmentDetails::Response::MonetaryValue.new(
298
+ currency: rate.insurance_amount.currency,
299
+ amount: rate.insurance_amount.amount
300
+ ),
301
+ confirmation_amount: GetWithShipmentDetails::Response::MonetaryValue.new(
302
+ currency: rate.confirmation_amount.currency,
303
+ amount: rate.confirmation_amount.amount
304
+ ),
305
+ other_amount: GetWithShipmentDetails::Response::MonetaryValue.new(
306
+ currency: rate.other_amount.currency,
307
+ amount: rate.other_amount.amount
308
+ ),
309
+ tax_amount:,
310
+ zone: rate.zone,
311
+ package_type: rate.package_type,
312
+ delivery_days: rate.delivery_days,
313
+ guaranteed_service: rate.guaranteed_service,
314
+ estimated_delivery_date: rate.estimated_delivery_date,
315
+ carrier_delivery_days: rate.carrier_delivery_days,
316
+ ship_date: rate.ship_date,
317
+ negotiated_rate: rate.negotiated_rate,
318
+ service_type: rate.service_type,
319
+ service_code: rate.service_code,
320
+ trackable: rate.trackable,
321
+ carrier_code: rate.carrier_code,
322
+ carrier_nickname: rate.carrier_nickname,
323
+ carrier_friendly_name: rate.carrier_friendly_name,
324
+ validation_status: rate.validation_status,
325
+ warning_messages: rate.warning_messages,
326
+ error_messages: rate.error_messages
327
+ )
328
+ end
329
+
330
+ errors = mash_result.rate_response.errors.map do |error|
331
+ GetWithShipmentDetails::Response::RateResponse::Error.new(
332
+ error_source: error.error_source,
333
+ error_type: error.error_type,
334
+ error_code: error.error_code,
335
+ message: error['message']
336
+ )
337
+ end
338
+
339
+ rate_response = GetWithShipmentDetails::Response::RateResponse.new(
340
+ rates:,
341
+ invalid_rates:,
342
+ rate_request_id: mash_result.rate_response.rate_request_id,
343
+ shipment_id: mash_result.rate_response.shipment_id,
344
+ created_at: mash_result.rate_response.created_at,
345
+ status: mash_result.rate_response.status,
346
+ errors:
347
+ )
348
+
349
+ GetWithShipmentDetails::Response.new(
350
+ shipment_id: mash_result.shipment_id,
351
+ carrier_id: mash_result.carrier_id,
352
+ service_code: mash_result.service_code,
353
+ external_order_id: mash_result.external_order_id,
354
+ items:,
355
+ tax_identifiers:,
356
+ external_shipment_id: mash_result.external_shipment_id,
357
+ ship_date: mash_result.ship_date,
358
+ created_at: mash_result.created_at,
359
+ modified_at: mash_result.modified_at,
360
+ shipment_status: mash_result.shipment_status,
361
+ ship_to:,
362
+ ship_from:,
363
+ warehouse_id: mash_result.warehouse_id,
364
+ return_to:,
365
+ confirmation: mash_result.confirmation,
366
+ customs:,
367
+ advanced_options:,
368
+ origin_type: mash_result.origin_type,
369
+ insurance_provider: mash_result.insurance_provider,
370
+ tags:,
371
+ order_source_code: mash_result.order_source_code,
372
+ packages:,
373
+ total_weight:,
374
+ rate_response:
375
+ )
376
+ end
377
+ end
378
+ end
379
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShipEngine
4
+ module Domain
5
+ class Tracking
6
+ module TrackUsingCarrierCodeAndTrackingNumber
7
+ class Response
8
+ attr_reader :tracking_number, :status_code, :status_description, :carrier_status_code, :carrier_status_description, :shipped_date, :estimated_delivery_date, :actual_delivery_date, :exception_description, :events
9
+
10
+ def initialize(tracking_number:, status_code:, status_description:, carrier_status_code:, carrier_status_description:, shipped_date:, estimated_delivery_date:, actual_delivery_date:, exception_description:, events:) # rubocop:todo Metrics/ParameterLists
11
+ @tracking_number = tracking_number
12
+ @status_code = status_code
13
+ @status_description = status_description
14
+ @carrier_status_code = carrier_status_code
15
+ @carrier_status_description = carrier_status_description
16
+ @shipped_date = shipped_date
17
+ @estimated_delivery_date = estimated_delivery_date
18
+ @actual_delivery_date = actual_delivery_date
19
+ @exception_description = exception_description
20
+ @events = events
21
+ end
22
+ end
23
+
24
+ class Event
25
+ attr_reader :occurred_at, :carrier_occurred_at, :description, :city_locality, :state_province, :postal_code, :country_code, :company_name, :signer, :event_code, :latitude, :longitude
26
+
27
+ def initialize(occurred_at:, carrier_occurred_at:, description:, city_locality:, state_province:, postal_code:, country_code:, company_name:, signer:, event_code:, latitude:, longitude:) # rubocop:todo Metrics/ParameterLists
28
+ @occurred_at = occurred_at
29
+ @carrier_occurred_at = carrier_occurred_at
30
+ @description = description
31
+ @city_locality = city_locality
32
+ @state_province = state_province
33
+ @postal_code = postal_code
34
+ @country_code = country_code
35
+ @company_name = company_name
36
+ @signer = signer
37
+ @event_code = event_code
38
+ @latitude = latitude
39
+ @longitude = longitude
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShipEngine
4
+ module Domain
5
+ class Tracking
6
+ module TrackUsingLabelId
7
+ class Response
8
+ attr_reader :tracking_number, :status_code, :status_description, :carrier_status_code, :carrier_status_description, :shipped_date, :estimated_delivery_date, :actual_delivery_date, :exception_description, :events
9
+
10
+ def initialize(tracking_number:, status_code:, status_description:, carrier_status_code:, carrier_status_description:, shipped_date:, estimated_delivery_date:, actual_delivery_date:, exception_description:, events:) # rubocop:todo Metrics/ParameterLists
11
+ @tracking_number = tracking_number
12
+ @status_code = status_code
13
+ @status_description = status_description
14
+ @carrier_status_code = carrier_status_code
15
+ @carrier_status_description = carrier_status_description
16
+ @shipped_date = shipped_date
17
+ @estimated_delivery_date = estimated_delivery_date
18
+ @actual_delivery_date = actual_delivery_date
19
+ @exception_description = exception_description
20
+ @events = events
21
+ end
22
+ end
23
+
24
+ class Event
25
+ attr_reader :occurred_at, :carrier_occurred_at, :description, :city_locality, :state_province, :postal_code, :country_code, :company_name, :signer, :event_code, :latitude, :longitude
26
+
27
+ def initialize(occurred_at:, carrier_occurred_at:, description:, city_locality:, state_province:, postal_code:, country_code:, company_name:, signer:, event_code:, latitude:, longitude:) # rubocop:todo Metrics/ParameterLists
28
+ @occurred_at = occurred_at
29
+ @carrier_occurred_at = carrier_occurred_at
30
+ @description = description
31
+ @city_locality = city_locality
32
+ @state_province = state_province
33
+ @postal_code = postal_code
34
+ @country_code = country_code
35
+ @company_name = company_name
36
+ @signer = signer
37
+ @event_code = event_code
38
+ @latitude = latitude
39
+ @longitude = longitude
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'hashie'
4
+ require_relative 'tracking/track_using_label_id'
5
+ require_relative 'tracking/track_using_carrier_code_and_tracking_number'
6
+
7
+ module ShipEngine
8
+ module Domain
9
+ class Tracking
10
+ require 'shipengine/constants'
11
+
12
+ # @param [ShipEngine::InternalClient] internal_client
13
+ def initialize(internal_client)
14
+ @internal_client = internal_client
15
+ end
16
+
17
+ # @param label_id [String]
18
+ # @param config [Hash?]
19
+ #
20
+ # @return [ShipEngine::Domain::Tracking::TrackUsingLabelId::Response]
21
+ #
22
+ # @see https://shipengine.github.io/shipengine-openapi/#operation/validate_address
23
+ def track_using_label_id(label_id, config)
24
+ response = @internal_client.get("/v1/labels/#{label_id}/track", {}, config)
25
+ tracking_api_result = response.body
26
+ mash_result = Hashie::Mash.new(tracking_api_result)
27
+
28
+ events = mash_result.events.map do |event|
29
+ TrackUsingLabelId::Event.new(
30
+ occurred_at: event.occurred_at,
31
+ carrier_occurred_at: event.carrier_occurred_at,
32
+ description: event.description,
33
+ city_locality: event.city_locality,
34
+ state_province: event.state_province,
35
+ postal_code: event.postal_code,
36
+ country_code: event.country_code,
37
+ company_name: event.company_name,
38
+ signer: event.signer,
39
+ event_code: event.event_code,
40
+ latitude: event.latitude,
41
+ longitude: event.longitude
42
+ )
43
+ end
44
+
45
+ TrackUsingLabelId::Response.new(
46
+ tracking_number: mash_result.tracking_number,
47
+ status_code: mash_result.status_code,
48
+ status_description: mash_result.status_description,
49
+ carrier_status_code: mash_result.carrier_status_code,
50
+ carrier_status_description: mash_result.carrier_status_description,
51
+ shipped_date: mash_result.shipped_date,
52
+ estimated_delivery_date: mash_result.estimated_delivery_date,
53
+ actual_delivery_date: mash_result.actual_delivery_date,
54
+ exception_description: mash_result.exception_description,
55
+ events:
56
+ )
57
+ end
58
+
59
+ # @param carrier_code [String]
60
+ # @param tracking_number [String]
61
+ # @param config [Hash?]
62
+ #
63
+ # @return [ShipEngine::Domain::Tracking::TrackUsingCarrierCodeAndTrackingNumber::Response]
64
+ #
65
+ # @see https://shipengine.github.io/shipengine-openapi/#operation/validate_address
66
+ def track_using_carrier_code_and_tracking_number(carrier_code, tracking_number, config)
67
+ response = @internal_client.get('/v1/tracking', { carrier_code:, tracking_number: }, config)
68
+ tracking_api_result = response.body
69
+ mash_result = Hashie::Mash.new(tracking_api_result)
70
+
71
+ events = mash_result.events.map do |event|
72
+ TrackUsingCarrierCodeAndTrackingNumber::Event.new(
73
+ occurred_at: event.occurred_at,
74
+ carrier_occurred_at: event.carrier_occurred_at,
75
+ description: event.description,
76
+ city_locality: event.city_locality,
77
+ state_province: event.state_province,
78
+ postal_code: event.postal_code,
79
+ country_code: event.country_code,
80
+ company_name: event.company_name,
81
+ signer: event.signer,
82
+ event_code: event.event_code,
83
+ latitude: event.latitude,
84
+ longitude: event.longitude
85
+ )
86
+ end
87
+
88
+ TrackUsingCarrierCodeAndTrackingNumber::Response.new(
89
+ tracking_number: mash_result.tracking_number,
90
+ status_code: mash_result.status_code,
91
+ status_description: mash_result.status_description,
92
+ carrier_status_code: mash_result.carrier_status_code,
93
+ carrier_status_description: mash_result.carrier_status_description,
94
+ shipped_date: mash_result.shipped_date,
95
+ estimated_delivery_date: mash_result.estimated_delivery_date,
96
+ actual_delivery_date: mash_result.actual_delivery_date,
97
+ exception_description: mash_result.exception_description,
98
+ events:
99
+ )
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('domain/addresses')
4
+ require_relative('domain/carriers')
5
+ require_relative('domain/labels')
6
+ require_relative('domain/rates')
7
+ require_relative('domain/tracking')