Class: Brownie::Shipment
- Inherits:
-
Object
- Object
- Brownie::Shipment
- Defined in:
- lib/brownie/shipment.rb
Instance Attribute Summary collapse
-
#account_number ⇒ Object
Returns the value of attribute account_number.
-
#api_domain ⇒ Object
Returns the value of attribute api_domain.
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#data ⇒ Object
Returns the value of attribute data.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#label_binary ⇒ Object
Returns the value of attribute label_binary.
-
#package ⇒ Object
Returns the value of attribute package.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#service_code ⇒ Object
Returns the value of attribute service_code.
-
#ship_from ⇒ Object
Returns the value of attribute ship_from.
-
#ship_to ⇒ Object
Returns the value of attribute ship_to.
-
#shipment_digest ⇒ Object
Returns the value of attribute shipment_digest.
-
#shipment_xml ⇒ Object
Returns the value of attribute shipment_xml.
-
#shipper ⇒ Object
Returns the value of attribute shipper.
-
#template ⇒ Object
Returns the value of attribute template.
-
#tracking_number ⇒ Object
Returns the value of attribute tracking_number.
Instance Method Summary collapse
- #confirm ⇒ Object
-
#initialize(shipment = nil) ⇒ Shipment
constructor
A new instance of Shipment.
- #label(_shipment_digest, path) ⇒ Object
Constructor Details
#initialize(shipment = nil) ⇒ Shipment
Returns a new instance of Shipment.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/brownie/shipment.rb', line 13 def initialize(shipment=nil) self.shipment_data = shipment if !shipment.nil? self.credentials = Credentials.new self.shipper = Shipper.new self.ship_to = ShipTo.new self.ship_from = ShipFrom.new self.package = Package.new self.template = Common::template_to_hash(:ship_confirm) end |
Instance Attribute Details
#account_number ⇒ Object
Returns the value of attribute account_number.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def account_number @account_number end |
#api_domain ⇒ Object
Returns the value of attribute api_domain.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def api_domain @api_domain end |
#credentials ⇒ Object
Returns the value of attribute credentials.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def credentials @credentials end |
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def data @data end |
#environment ⇒ Object
Returns the value of attribute environment.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def environment @environment end |
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def errors @errors end |
#label_binary ⇒ Object
Returns the value of attribute label_binary.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def label_binary @label_binary end |
#package ⇒ Object
Returns the value of attribute package.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def package @package end |
#request ⇒ Object
Returns the value of attribute request.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def response @response end |
#service_code ⇒ Object
Returns the value of attribute service_code.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def service_code @service_code end |
#ship_from ⇒ Object
Returns the value of attribute ship_from.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def ship_from @ship_from end |
#ship_to ⇒ Object
Returns the value of attribute ship_to.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def ship_to @ship_to end |
#shipment_digest ⇒ Object
Returns the value of attribute shipment_digest.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def shipment_digest @shipment_digest end |
#shipment_xml ⇒ Object
Returns the value of attribute shipment_xml.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def shipment_xml @shipment_xml end |
#shipper ⇒ Object
Returns the value of attribute shipper.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def shipper @shipper end |
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def template @template end |
#tracking_number ⇒ Object
Returns the value of attribute tracking_number.
8 9 10 |
# File 'lib/brownie/shipment.rb', line 8 def tracking_number @tracking_number end |
Instance Method Details
#confirm ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/brownie/shipment.rb', line 26 def confirm data = self.template["Shipment"] data["PaymentInformation"]["Prepaid"]["BillShipper"]["AccountNumber"] = self.account_number data["Service"]["Code"] = self.service_code data["Package"] = self.package.create data["Shipper"] = self.shipper.create data["ShipTo"] = self.ship_to.create data["ShipFrom"] = self.ship_from.create self.template["Shipment"] = data request_template = {"ShipmentConfirmRequest" => self.template} shipment_xml_str = request_template["ShipmentConfirmRequest"].to_xml(:root => "ShipmentConfirmRequest") self.response = RestClient.post("https://#{Common::domain}/ups.app/xml/ShipConfirm","#{access_request_header}#{shipment_xml_str}") if self.response.code.eql?(200) response_hash = Hash.from_xml(response) if response_hash["ShipmentConfirmResponse"]["Response"]["ResponseStatusCode"].eql?("0") self.errors = response_hash["ShipmentConfirmResponse"]["Response"]["Error"] return false end self.tracking_number = response_hash["ShipmentConfirmResponse"]["ShipmentIdentificationNumber"] self.shipment_digest = response_hash["ShipmentConfirmResponse"]["ShipmentDigest"] return true else raise "In-valid request #{response}" end end |
#label(_shipment_digest, path) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/brownie/shipment.rb', line 57 def label(_shipment_digest,path) shipment_digest = _shipment_digest.nil? ? @shipment_digest : _shipment_digest label_xml = '<?xml version="1.0" encoding="ISO-8859-1"?> <ShipmentAcceptRequest> <Request> <TransactionReference> <CustomerContext></CustomerContext> </TransactionReference> <RequestAction>ShipAccept</RequestAction> <RequestOption>1</RequestOption> </Request> <ShipmentDigest>' + shipment_digest + '</ShipmentDigest> </ShipmentAcceptRequest>' label_response = RestClient.post("https://#{Common::domain}/ups.app/xml/ShipAccept","#{access_request_header}#{label_xml}") label_hash = Hash.from_xml(label_response) self.label_binary = label_hash["ShipmentAcceptResponse"]["ShipmentResults"]["PackageResults"]["LabelImage"]["GraphicImage"] File.open(path, 'wb') do|f| f.write(Base64.decode64(self.label_binary)) end end |