# frozen_string_literal: true # This file was auto-generated by lib/tasks/api.rake module Usps module Api module Endpoints module TrackV2 # The Package Tracking “Fields” API is similar # to the Package Track API # except for the request fields, API name, and the return information. Data # returned still contains the detail and summary information, but this # information is broken down into fields instead of having only one line of text. # Up to 10 tracking IDs may be contained in each API request to the Web Tools # server. # @param [Hash] options # @option options [required, Hash] track_field_request # * *:revision* (required, Integer) # * *:client_ip* (String) # * *:source_id* (required, String) # * *:track_id* (required, String) # * *:destination_zip_code* (String) # * *:mailing_date* (String) def track_v2(options = {}) throw ArgumentError.new('Required arguments :track_field_request missing') if options[:track_field_request].nil? throw ArgumentError.new('Required arguments :track_field_request, :revision missing') if options[:track_field_request][:revision].nil? throw ArgumentError.new('Required arguments :track_field_request, :source_id missing') if options[:track_field_request][:source_id].nil? throw ArgumentError.new('Required arguments :track_field_request, :track_id missing') if options[:track_field_request][:track_id].nil? request = build_request(:track_v2, options) get('https://secure.shippingapis.com/ShippingAPI.dll', { API: 'TrackV2', XML: request, }) end private def tag_unless_blank(xml, tag_name, data) xml.tag!(tag_name, data) unless data.blank? || data.nil? end def build_track_v2_request(xml, options = {}) xml.tag!('Revision', options[:track_field_request][:revision]) tag_unless_blank(xml, 'ClientIp', options[:track_field_request][:client_ip]) xml.tag!('SourceId', options[:track_field_request][:source_id]) xml.tag!('TrackID', options[:track_field_request][:track_id]) tag_unless_blank(xml, 'DestinationZipCode', options[:track_field_request][:destination_zip_code]) tag_unless_blank(xml, 'MailingDate', options[:track_field_request][:mailing_date]) xml.target! end end end end end