# frozen_string_literal: true
# This file was auto-generated by lib/tasks/api.rake
module Usps
module Api
module Endpoints
module SCAN
# The SCAN API allows integrators to consolidate
# multiple domestic and international labels and custom forms through one
# Electronic File Number (EFN) and physical SCAN Form (PS Form 5630 or 3152). The
# API operates as follows:
# @param [Hash] options
# @option options [required, Hash] scan_request API=SCAN
# * *:option* (Hash) — Groups form information
# * *:form* (String) — Designates desired label option selected by customer. Enter one of the valid entries: ‘3152’ generates PS Form 3152. ‘5630’ generates PS Form 5630. For example:
# * *:from_name* (required, String) — Name of sender. Example: Joe Smith
# * *:from_firm* (String) — Company name. Example: ABC Corp.
# * *:from_address1* (String) — From address line 1. Denote apartment or suite number. Example: Apt. 3C
# * *:from_address2* (required, String) — From address line 2. Denote street/structure number. Example: 475 L’Enfant Plaza SW
# * *:from_city* (required, String) — From city. Example: Greenbelt
# * *:from_state* (required, String) — From state. Example: MD
# * *:from_zip5* (required, String) — From ZIP Code. Must be a valid ZIP5 Code. Example: 20770
# * *:from_zip4* (String) — From ZIP Code+4. Example: 1234
# * *:shipment* (Hash) — Groups shipment information
# * *:package_detail* (Hash) — Groups package detail information
# * *:pkg_barcode* (required, String) — Individual package barcodes. Example: 42020260910180521390702413570 Note: The SCAN API can contain no more than 1,000 package barcodes in a single request. If exceeded, 'Total PackageDetail items exceeded 1000.’ error will return”
# * *:special_service* (Hash) — FOR FUTURE USE. Groups extra service information.
# * *:spc_serv_code* (required, String) — FOR FUTURE USE. If present, must be . From Extra Service Code table. Example: 01
# * *:spc_serv_fee* (required, String) — FOR FUTURE USE. Fee for Extra Service. Example: 00275
# * *:e_mail* (String) — FOR FUTURE USE. Email address of acceptance scan event recipient. Example: john.smith@abc.com
# * *:close_manifest* (Boolean) — Used to include all labels for the submitted UserID. There are two values: “ALL” will close all labels for the submitted USERID. “SHIPDATE” will close all the labels for the submitted USERID that have the tag matching the value in the tag. Note: When is indicated in the request, the following two response fields are eligible to return if conditions are met: · ·
# * *:mail_date* (required, String) — Date of mailing/Carrier Pickup. This denotes date mail to be tendered to Postal Service. YYYYMMDD format. Example: 20060103
# * *:mail_time* (required, String) — Time of mailing/Carrier Pickup. This is an approximation. This denotes time of mail to be tendered to Postal Service. HHMMSS (24 hour) format. Example: 143000
# * *:entry_facility* (required, String) — ZIP Code of Postal Service facility. Populate/required only if different from . Example: 07067
# * *:image_type* (required, String) — The form image format desired. Enter one of the valid entries: Example: TIF
# * *:customer_ref_no* (String) — Arbitrary number for customers own tracking or inventory systems, does not print to form or manifest with Product Tracking. May be any combination of alpha and numeric characters, up to a maximum of 30. Example: 123456
# * *:carrier_pickup* (Boolean) — FOR FUTURE USE.
def scan(options = {})
throw ArgumentError.new('Required arguments :scan_request missing') if options[:scan_request].nil?
request = build_request(:scan, options)
get('https://secure.shippingapis.com/ShippingAPI.dll', {
API: 'SCAN',
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_scan_request(xml, options = {})
xml.tag!('Option') do
tag_unless_blank(xml, 'Form', options[:scan_request][:option][:form])
xml.tag!('FromName', options[:scan_request][:option][:from_name])
tag_unless_blank(xml, 'FromFirm', options[:scan_request][:option][:from_firm])
tag_unless_blank(xml, 'FromAddress1', options[:scan_request][:option][:from_address1])
xml.tag!('FromAddress2', options[:scan_request][:option][:from_address2])
xml.tag!('FromCity', options[:scan_request][:option][:from_city])
xml.tag!('FromState', options[:scan_request][:option][:from_state])
xml.tag!('FromZip5', options[:scan_request][:option][:from_zip5])
tag_unless_blank(xml, 'FromZip4', options[:scan_request][:option][:from_zip4])
xml.tag!('Shipment') do
xml.tag!('PackageDetail') do
xml.tag!('PkgBarcode', options[:scan_request][:option][:shipment][:package_detail][:pkg_barcode])
xml.tag!('SpecialService') do
xml.tag!('SpcServCode', options[:scan_request][:option][:shipment][:package_detail][:special_service][:spc_serv_code])
xml.tag!('SpcServFee', options[:scan_request][:option][:shipment][:package_detail][:special_service][:spc_serv_fee])
tag_unless_blank(xml, 'EMail', options[:scan_request][:option][:shipment][:package_detail][:special_service][:e_mail])
tag_unless_blank(xml, 'CloseManifest', options[:scan_request][:option][:shipment][:package_detail][:special_service][:close_manifest])
xml.tag!('MailDate', options[:scan_request][:option][:shipment][:package_detail][:special_service][:mail_date])
xml.tag!('MailTime', options[:scan_request][:option][:shipment][:package_detail][:special_service][:mail_time])
xml.tag!('EntryFacility', options[:scan_request][:option][:shipment][:package_detail][:special_service][:entry_facility])
xml.tag!('ImageType', options[:scan_request][:option][:shipment][:package_detail][:special_service][:image_type])
tag_unless_blank(xml, 'CustomerRefNo', options[:scan_request][:option][:shipment][:package_detail][:special_service][:customer_ref_no])
tag_unless_blank(xml, 'CarrierPickup', options[:scan_request][:option][:shipment][:package_detail][:special_service][:carrier_pickup])
end if options[:scan_request][:option][:shipment][:package_detail][:special_service].present?
end if options[:scan_request][:option][:shipment][:package_detail].present?
end if options[:scan_request][:option][:shipment].present?
end if options[:scan_request][:option].present?
xml.target!
end
end
end
end
end