Class: Shipping::UPS
- Inherits:
-
Object
- Object
- Shipping::UPS
- Defined in:
- lib/ups_shipping.rb
Defined Under Namespace
Classes: Http
Constant Summary collapse
- TEST_URL =
"https://wwwcie.ups.com"
- LIVE_URL =
"https://onlinetools.ups.com"
Instance Method Summary collapse
- #cancel_shipment(shipment_id) ⇒ Object
- #find_rates(package, origin, destination, options = {}) ⇒ Object
-
#initialize(user, password, license, options = {}) ⇒ UPS
constructor
A new instance of UPS.
- #request_shipment(package, origin, destination, service, options = {}) ⇒ Object
- #track_shipment(tracking_number) ⇒ Object
- #validate_address(address) ⇒ Object
Constructor Details
#initialize(user, password, license, options = {}) ⇒ UPS
Returns a new instance of UPS.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ups_shipping.rb', line 35 def initialize(user, password, license, ={}) @options = @shipper = [:shipper] @access_request = access_request(user, password, license) @http = Http.new(@access_request, :test => @options[:test]) @services = { "01" => "Next Day Air", "02" => "2nd Day Air", "03" => "Ground", "07" => "Express", "08" => "Expedited", "11" => "UPS Standard", "12" => "3 Day Select", "13" => "Next Day Air Saver", "14" => "Next Day Air Early AM", "54" => "Express Plus", "59" => "2nd Day Air A.M.", "65" => "UPS Saver", "82" => "UPS Today Standard", "83" => "UPS Today Dedicated Courier", "84" => "UPS Today Intercity", "85" => "UPS Today Express", "86" => "UPS Today Express Saver" } end |
Instance Method Details
#cancel_shipment(shipment_id) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/ups_shipping.rb', line 152 def cancel_shipment(shipment_id) cancel_request = Nokogiri::XML::Builder.new do |xml| xml.VoidShipmentRequest { xml.Request { xml.RequestAction "1" xml.RequestOption "1" } xml.ShipmentIdentificationNumber shipment_id } end @http.commit("/ups.app/xml/Void", cancel_request.to_xml) end |
#find_rates(package, origin, destination, options = {}) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ups_shipping.rb', line 86 def find_rates(package, origin, destination, ={}) rate_request = Nokogiri::XML::Builder.new do |xml| xml.RatingServiceSelectionRequest { xml.Request { xml.RequestAction "Rate" xml.RequestOption "Rate" } if [:pickup] @options[:pickup].build_type(xml) end @shipper.build(xml, "Shipper") destination.build(xml, "ShipTo") origin.build(xml, "ShipFrom") xml.PaymentInformation { xml.Prepaid { xml.BillShipper { xml.AccountNumber "Ship Number" } } } package.build(xml) } end @http.commit("/ups.app/xml/Rate", rate_request.to_xml) end |
#request_shipment(package, origin, destination, service, options = {}) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ups_shipping.rb', line 112 def request_shipment(package, origin, destination, service, ={}) shipment_request = Nokogiri::XML::Builder.new do |xml| xml.ShipmentConfirmRequest { xml.Request { xml.RequestAction "ShipConfirm" xml.RequestOptions "validate" } if [:label] xml.LabelSpecification { xml.LabelPrintMethod { xml.Code "GIF" xml.Description "gif file" } xml.HTTPUserAgent "Mozilla/4.5" xml.LabelImageFormat { xml.Code "GIF" xml.Description "gif" } } end @shipper.build(xml, "Shipper") destination.build(xml, "ShipTo") origin.build(xml, "ShipFrom") xml.PaymentInformation { xml.Prepaid { xml.BillShipper { xml.AccountNumber "Ship Number" } } } xml.Service { xml.Code service xml.Description @services[service] } package.build(xml) } end @http.commit("/ups.app/xml/ShipConfirm", shipment_request.to_xml) end |
#track_shipment(tracking_number) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/ups_shipping.rb', line 165 def track_shipment(tracking_number) track_request = Nokogiri::XML::Builder.new do TrackRequest { Request { RequestAction "Track" RequestOption "activity" } TrackingNumber tracking_number } end @http.commit("/ups.app/xml/Track", track_request.to_xml) end |
#validate_address(address) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ups_shipping.rb', line 62 def validate_address(address) validate_request = Nokogiri::XML::Builder.new do |xml| xml.AddressValidationRequest { xml.Request { xml.TransactionReference { xml.CustomerContext xml.XpciVersion 1.0001 } xml.RequestAction "XAV" xml.RequestOption "3" } xml.MaximumListSize 3 xml.AddressKeyFormat { xml.AddressLine address.address_lines[0] xml.PoliticalDivision2 address.city xml.PoliticalDivision1 address.state xml.PostcodePrimaryLow address.zip xml.CountryCode address.country } } end @http.commit("/ups.app/xml/XAV", validate_request.to_xml) end |