diff --git a/CHANGELOG.md b/CHANGELOG.md index 28b70d20..380ef0a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v7.1.0 (2025-06-18) - Adds support for `UspsShipAccount` +- Adds `tracker.retrieve_batch` function ## v7.1.0 (2025-06-18) diff --git a/lib/easypost/services/tracker.rb b/lib/easypost/services/tracker.rb index 19ad7a84..6a51c436 100644 --- a/lib/easypost/services/tracker.rb +++ b/lib/easypost/services/tracker.rb @@ -29,6 +29,13 @@ def all(params = {}) get_all_helper('trackers', MODEL_CLASS, params, filters) end + # Retrieve a batch of Trackers + def retrieve_batch(params = {}) + response = @client.make_request(:post, 'trackers/batch', params) + + EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) + end + # Get the next page of trackers. def get_next_page(collection, page_size = nil) raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection) diff --git a/spec/cassettes/tracker/EasyPost_Services_Tracker_retrieve_batch_retrieves_a_batch_of_trackers.yml b/spec/cassettes/tracker/EasyPost_Services_Tracker_retrieve_batch_retrieves_a_batch_of_trackers.yml new file mode 100644 index 00000000..1197580e --- /dev/null +++ b/spec/cassettes/tracker/EasyPost_Services_Tracker_retrieve_batch_retrieves_a_batch_of_trackers.yml @@ -0,0 +1,141 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.easypost.com/v2/trackers + body: + encoding: UTF-8 + string: '{"tracker":{"tracking_code":"EZ1000000001"}}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: "" + Host: + - api.easypost.com + Content-Type: + - application/json + Authorization: "" + response: + status: + code: 201 + message: Created + headers: + 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: + - e13b8f22690bd1f2e79959a9024cafc5 + Cache-Control: + - private, no-cache, no-store + Pragma: + - no-cache + Expires: + - '0' + Location: + - "/api/v2/trackers/trk_33b935fbb2c549548ac308e9650703ea" + Content-Type: + - application/json; charset=utf-8 + X-Runtime: + - '0.123966' + Transfer-Encoding: + - chunked + X-Node: + - bigweb34nuq + X-Version-Label: + - easypost-202511052124-83d556159a-master + X-Backend: + - easypost + X-Proxied: + - extlb1nuq cbbd141214 + - intlb3nuq c0061e0a2e + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + body: + encoding: UTF-8 + string: '{"id":"trk_33b935fbb2c549548ac308e9650703ea","object":"Tracker","mode":"test","tracking_code":"EZ1000000001","status":"pre_transit","status_detail":"status_update","created_at":"2025-11-05T22:38:42Z","updated_at":"2025-11-05T22:38:42Z","signed_by":null,"weight":null,"est_delivery_date":"2025-11-05T22:38:42Z","shipment_id":null,"carrier":"USPS","tracking_details":[{"object":"TrackingDetail","message":"Pre-Shipment + Info Sent to USPS","description":null,"status":"pre_transit","status_detail":"status_update","datetime":"2025-10-05T22:38:42Z","source":"USPS","carrier_code":null,"tracking_location":{"object":"TrackingLocation","city":null,"state":null,"country":null,"zip":null},"est_delivery_date":null},{"object":"TrackingDetail","message":"Shipping + Label Created","description":null,"status":"pre_transit","status_detail":"status_update","datetime":"2025-10-06T11:15:42Z","source":"USPS","carrier_code":null,"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/djE6dHJrXzMzYjkzNWZiYjJjNTQ5NTQ4YWMzMDhlOTY1MDcwM2Vh","fees":[{"object":"Fee","type":"TrackerFee","amount":"0.00000","charged":false,"refunded":false}]}' + recorded_at: Wed, 05 Nov 2025 22:38:42 GMT +- request: + method: post + uri: https://api.easypost.com/v2/trackers/batch + body: + encoding: UTF-8 + string: '{"tracking_codes":["EZ1000000001"]}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: "" + Host: + - api.easypost.com + Content-Type: + - application/json + Authorization: "" + response: + status: + code: 200 + message: OK + headers: + 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: + - e13b8f27690bd1f3e7995cba024cb02b + Cache-Control: + - private, no-cache, no-store + Pragma: + - no-cache + Expires: + - '0' + Content-Type: + - application/json; charset=utf-8 + X-Runtime: + - '0.056696' + Transfer-Encoding: + - chunked + X-Node: + - bigweb65nuq + X-Version-Label: + - easypost-202511052124-83d556159a-master + X-Backend: + - easypost + X-Proxied: + - extlb1nuq cbbd141214 + - intlb4nuq c0061e0a2e + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + body: + encoding: UTF-8 + string: '{"trackers":[{"id":"trk_33b935fbb2c549548ac308e9650703ea","object":"Tracker","mode":"test","tracking_code":"EZ1000000001","status":"pre_transit","status_detail":"status_update","created_at":"2025-11-05T22:38:42Z","updated_at":"2025-11-05T22:38:42Z","signed_by":null,"weight":null,"est_delivery_date":"2025-11-05T22:38:42Z","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-05T22:38:42Z","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-06T11:15:42Z","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/djE6dHJrXzMzYjkzNWZiYjJjNTQ5NTQ4YWMzMDhlOTY1MDcwM2Vh"}],"has_more":false}' + recorded_at: Wed, 05 Nov 2025 22:38:43 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/tracker_spec.rb b/spec/tracker_spec.rb index cedf153c..ec1676e2 100644 --- a/spec/tracker_spec.rb +++ b/spec/tracker_spec.rb @@ -60,6 +60,20 @@ end end + describe '.retrieve_batch' do + it 'retrieves a batch of trackers' do + tracker = client.tracker.create( + tracking_code: 'EZ1000000001', + ) + + trackers = client.tracker.retrieve_batch( + tracking_codes: [tracker.tracking_code], + ) + + expect(trackers).to be_an_instance_of(EasyPost::Models::Tracker) + end + end + describe '.get_next_page' do it 'retrieves the next page of a collection' do first_page = client.tracker.all(