# frozen_string_literal: true
# This file was auto-generated by lib/tasks/api.rake
module Usps
module Api
module Endpoints
module SCAN
#
# SCAN API
#
# 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:
#
# @option option [(Alias)] :SCANRequest (Required)
# - API=SCAN
# @option option [(Group)] :Option (Optional)
# - Groups form information
# @option option [String] :Form (Optional)
# - 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:
# @option option [String] :FromName (Required)
# - Name of sender. Example: Joe Smith
# @option option [String] :FromFirm (Optional)
# - Company name. Example: ABC Corp.
# @option option [String] :FromAddress1 (Optional)
# - From address line 1. Denote apartment or suite number. Example: Apt. 3C
# @option option [String] :FromAddress2 (Required)
# - From address line 2. Denote street/structure number. Example: 475 L’Enfant Plaza SW
# @option option [String] :FromCity (Required)
# - From city. Example: Greenbelt
# @option option [String] :FromState (Required)
# - From state. Example: MD
# @option option [String] :FromZip5 (Required)
# - From ZIP Code. Must be a valid ZIP5 Code. Example: 20770
# @option option [String] :FromZip4 (Optional)
# - From ZIP Code+4. Example: 1234
# @option option [(Group)] :Shipment (Optional)
# - Groups shipment information
# @option option [(Group)] :PackageDetail (Optional)
# - Groups package detail information
# @option option [String] :PkgBarcode (Required)
# - 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”
# @option option [(Group)] :SpecialService (Optional)
# - FOR FUTURE USE. Groups extra service information.
# @option option [String] :SpcServCode (Required)
# - FOR FUTURE USE. If present, must be . From Extra Service Code table. Example: 01
# @option option [String] :SpcServFee (Required)
# - FOR FUTURE USE. Fee for Extra Service. Example: 00275
# @option option [String] :EMail (Optional)
# - FOR FUTURE USE. Email address of acceptance scan event recipient. Example: john.smith@abc.com
# @option option [Boolean] :CloseManifest (Optional)
# - 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: · ·
# @option option [String] :MailDate (Required)
# - Date of mailing/Carrier Pickup. This denotes date mail to be tendered to Postal Service. YYYYMMDD format. Example: 20060103
# @option option [String] :MailTime (Required)
# - 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
# @option option [String] :EntryFacility (Required)
# - ZIP Code of Postal Service facility. Populate/required only if different from . Example: 07067
# @option option [String] :ImageType (Required)
# - The form image format desired. Enter one of the valid entries: Example: TIF
# @option option [String] :CustomerRefNo (Optional)
# - 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
# @option option [Boolean] :CarrierPickup (Optional)
# - FOR FUTURE USE.
#
# @see
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