From 36f88e24015be04018bd6ed1b70817fa61c98555 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Thu, 6 Nov 2025 10:42:26 -0700 Subject: [PATCH] feat: add RetrieveBatch tracker function --- CHANGELOG.md | 1 + .../ServicesTests/TrackerServiceTest.cs | 21 +++- .../net/tracker_service/retrieve_batch.json | 101 ++++++++++++++++++ EasyPost/Services/TrackerService.cs | 13 +++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 EasyPost.Tests/cassettes/net/tracker_service/retrieve_batch.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 3893cb080..81530433e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next Release - Adds support for `UspsShipAccount` +- Adds `Tracker.RetrieveBatch` function - Disposes of Luma service after use ## v7.2.0 (2025-06-18) diff --git a/EasyPost.Tests/ServicesTests/TrackerServiceTest.cs b/EasyPost.Tests/ServicesTests/TrackerServiceTest.cs index fc6146ac9..52311f3ad 100644 --- a/EasyPost.Tests/ServicesTests/TrackerServiceTest.cs +++ b/EasyPost.Tests/ServicesTests/TrackerServiceTest.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Threading.Tasks; using EasyPost.Exceptions.General; @@ -148,6 +147,26 @@ public async Task TestRetrieve() Assert.Equal(tracker.Id, retrievedTracker.Id); } + [Fact] + [CrudOperations.Read] + [Testing.Function] + public async Task TestRetrieveBatch() + { + UseVCR("retrieve_batch"); + + Tracker tracker = await Client.Tracker.Create(Fixtures.Usps, "EZ1000000001"); + + List trackingCodes = new() { tracker.TrackingCode }; + TrackerCollection trackerCollection = await Client.Tracker.RetrieveBatch(new Dictionary { { "tracking_codes", trackingCodes } }); + + List trackers = trackerCollection.Trackers; + + foreach (Tracker singleTracker in trackers) + { + Assert.IsType(singleTracker); + } + } + #endregion #endregion diff --git a/EasyPost.Tests/cassettes/net/tracker_service/retrieve_batch.json b/EasyPost.Tests/cassettes/net/tracker_service/retrieve_batch.json new file mode 100644 index 000000000..f16da4b0a --- /dev/null +++ b/EasyPost.Tests/cassettes/net/tracker_service/retrieve_batch.json @@ -0,0 +1,101 @@ +[ + { + "Duration": 837, + "RecordedAt": "2025-11-06T10:40:40.72857-07:00", + "Request": { + "Body": "{\"tracker\":{\"carrier\":\"USPS\",\"tracking_code\":\"EZ1000000001\"}}", + "BodyContentType": "Json", + "ContentHeaders": { + "Content-Type": "application/json; charset=utf-8", + "Content-Length": "61" + }, + "Method": "POST", + "RequestHeaders": { + "Authorization": "", + "User-Agent": "" + }, + "Uri": "https://api.easypost.com/v2/trackers" + }, + "Response": { + "Body": "{\"id\":\"trk_b88311999eaa4429bd11ce27ea62d302\",\"object\":\"Tracker\",\"mode\":\"test\",\"tracking_code\":\"EZ1000000001\",\"status\":\"pre_transit\",\"status_detail\":\"status_update\",\"created_at\":\"2025-11-06T17:40:39Z\",\"updated_at\":\"2025-11-06T17:40:39Z\",\"signed_by\":null,\"weight\":null,\"est_delivery_date\":\"2025-11-06T17:40:39Z\",\"shipment_id\":null,\"carrier\":\"USPS\",\"tracking_details\":[{\"object\":\"TrackingDetail\",\"message\":\"Pre-Shipment Info Sent to USPS\",\"description\":\"\",\"status\":\"pre_transit\",\"status_detail\":\"status_update\",\"datetime\":\"2025-10-06T17:40:39Z\",\"source\":\"USPS\",\"carrier_code\":\"\",\"tracking_location\":{\"object\":\"TrackingLocation\",\"city\":null,\"state\":null,\"country\":null,\"zip\":null},\"est_delivery_date\":null},{\"object\":\"TrackingDetail\",\"message\":\"Shipping Label Created\",\"description\":\"\",\"status\":\"pre_transit\",\"status_detail\":\"status_update\",\"datetime\":\"2025-10-07T06:17:39Z\",\"source\":\"USPS\",\"carrier_code\":\"\",\"tracking_location\":{\"object\":\"TrackingLocation\",\"city\":\"HOUSTON\",\"state\":\"TX\",\"country\":null,\"zip\":\"77063\"},\"est_delivery_date\":null}],\"carrier_detail\":{\"object\":\"CarrierDetail\",\"service\":\"First-Class Package Service\",\"container_type\":null,\"est_delivery_date_local\":null,\"est_delivery_time_local\":null,\"origin_location\":\"HOUSTON TX, 77001\",\"origin_tracking_location\":{\"object\":\"TrackingLocation\",\"city\":\"HOUSTON\",\"state\":\"TX\",\"country\":null,\"zip\":\"77063\"},\"destination_location\":\"CHARLESTON SC, 29401\",\"destination_tracking_location\":null,\"guaranteed_delivery_date\":null,\"alternate_identifier\":null,\"initial_delivery_attempt\":null},\"delivery_evidence\":[],\"finalized\":true,\"is_return\":false,\"public_url\":\"https://track.easypost.com/djE6dHJrX2I4ODMxMTk5OWVhYTQ0MjliZDExY2UyN2VhNjJkMzAy\"}", + "BodyContentType": "Json", + "ContentHeaders": { + "Expires": "0", + "Content-Type": "application/json; charset=utf-8", + "Content-Length": "1691" + }, + "HttpVersion": "1.1", + "ResponseHeaders": { + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "X-Content-Type-Options": "nosniff", + "x-download-options": "noopen", + "x-permitted-cross-domain-policies": "none", + "Referrer-Policy": "strict-origin-when-cross-origin", + "x-ep-request-uuid": "bcd4371f690cdd98e2b7cd6b0113cbab", + "Cache-Control": "no-store, no-cache, private", + "Pragma": "no-cache", + "Location": "/api/v2/trackers/trk_b88311999eaa4429bd11ce27ea62d302", + "x-runtime": "0.072554", + "x-node": "bigweb38nuq", + "x-version-label": "easypost-202511061639-9e7dc69a6b-master", + "x-backend": "easypost", + "x-proxied": "intlb5nuq c0061e0a2e,extlb2nuq cbbd141214", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload" + }, + "Status": { + "Code": 200, + "Message": "OK" + } + } + }, + { + "Duration": 100, + "RecordedAt": "2025-11-06T10:40:40.907915-07:00", + "Request": { + "Body": "{\"tracking_codes\":[\"EZ1000000001\"]}", + "BodyContentType": "Json", + "ContentHeaders": { + "Content-Type": "application/json; charset=utf-8", + "Content-Length": "35" + }, + "Method": "POST", + "RequestHeaders": { + "Authorization": "", + "User-Agent": "" + }, + "Uri": "https://api.easypost.com/v2/trackers/batch" + }, + "Response": { + "Body": "{\"trackers\":[{\"id\":\"trk_b88311999eaa4429bd11ce27ea62d302\",\"object\":\"Tracker\",\"mode\":\"test\",\"tracking_code\":\"EZ1000000001\",\"status\":\"pre_transit\",\"status_detail\":\"status_update\",\"created_at\":\"2025-11-06T17:40:39Z\",\"updated_at\":\"2025-11-06T17:40:39Z\",\"signed_by\":null,\"weight\":null,\"est_delivery_date\":\"2025-11-06T17:40:39Z\",\"shipment_id\":null,\"carrier\":\"USPS\",\"tracking_details\":[{\"object\":\"TrackingDetail\",\"message\":\"Pre-Shipment Info Sent to USPS\",\"description\":\"\",\"status\":\"pre_transit\",\"status_detail\":\"status_update\",\"datetime\":\"2025-10-06T17:40:39Z\",\"source\":\"USPS\",\"carrier_code\":\"\",\"tracking_location\":{\"object\":\"TrackingLocation\",\"city\":null,\"state\":null,\"country\":null,\"zip\":null},\"est_delivery_date\":null},{\"object\":\"TrackingDetail\",\"message\":\"Shipping Label Created\",\"description\":\"\",\"status\":\"pre_transit\",\"status_detail\":\"status_update\",\"datetime\":\"2025-10-07T06:17:39Z\",\"source\":\"USPS\",\"carrier_code\":\"\",\"tracking_location\":{\"object\":\"TrackingLocation\",\"city\":\"HOUSTON\",\"state\":\"TX\",\"country\":null,\"zip\":\"77063\"},\"est_delivery_date\":null}],\"fees\":[{\"object\":\"Fee\",\"type\":\"TrackerFee\",\"amount\":\"0.00000\",\"charged\":true,\"refunded\":false}],\"carrier_detail\":{\"object\":\"CarrierDetail\",\"service\":\"First-Class Package Service\",\"container_type\":null,\"est_delivery_date_local\":null,\"est_delivery_time_local\":null,\"origin_location\":\"HOUSTON TX, 77001\",\"origin_tracking_location\":{\"object\":\"TrackingLocation\",\"city\":\"HOUSTON\",\"state\":\"TX\",\"country\":null,\"zip\":\"77063\"},\"destination_location\":\"CHARLESTON SC, 29401\",\"destination_tracking_location\":null,\"guaranteed_delivery_date\":null,\"alternate_identifier\":null,\"initial_delivery_attempt\":null},\"delivery_evidence\":[],\"public_url\":\"https://track.easypost.com/djE6dHJrX2I4ODMxMTk5OWVhYTQ0MjliZDExY2UyN2VhNjJkMzAy\"}],\"has_more\":false}", + "BodyContentType": "Json", + "ContentHeaders": { + "Expires": "0", + "Content-Type": "application/json; charset=utf-8", + "Content-Length": "1785" + }, + "HttpVersion": "1.1", + "ResponseHeaders": { + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "X-Content-Type-Options": "nosniff", + "x-download-options": "noopen", + "x-permitted-cross-domain-policies": "none", + "Referrer-Policy": "strict-origin-when-cross-origin", + "x-ep-request-uuid": "bcd4371f690cdd98e2b7cd6b0113cc8d", + "Cache-Control": "no-store, no-cache, private", + "Pragma": "no-cache", + "x-runtime": "0.059364", + "x-node": "bigweb53nuq", + "x-version-label": "easypost-202511061639-9e7dc69a6b-master", + "x-backend": "easypost", + "x-proxied": "intlb3nuq c0061e0a2e,extlb2nuq cbbd141214", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload" + }, + "Status": { + "Code": 200, + "Message": "OK" + } + } + } +] diff --git a/EasyPost/Services/TrackerService.cs b/EasyPost/Services/TrackerService.cs index 3c0b3b198..0eccc9ed2 100644 --- a/EasyPost/Services/TrackerService.cs +++ b/EasyPost/Services/TrackerService.cs @@ -114,6 +114,19 @@ public async Task All(Parameters.Tracker.All parameters, Canc [CrudOperations.Read] public async Task Retrieve(string id, CancellationToken cancellationToken = default) => await RequestAsync(Method.Get, $"trackers/{id}", cancellationToken); + /// + /// Retrieves a batch of s. + /// + /// A dictionary of parameters to filter the list of s with. + /// to use for the HTTP request. + /// A instance. + [CrudOperations.Read] + public async Task RetrieveBatch(Dictionary? parameters = null, CancellationToken cancellationToken = default) + { + TrackerCollection collection = await RequestAsync(Method.Post, "trackers/batch", cancellationToken, parameters); + return collection; + } + #endregion } }