Class: Dhl::Bcs::V2::Shipment
- Inherits:
-
Object
- Object
- Dhl::Bcs::V2::Shipment
- Defined in:
- lib/dhl/bcs/v2/shipment.rb
Constant Summary collapse
- PRODUCT_PROCEDURE_NUMBERS =
{ 'V01PAK' => '01', # DHL Paket 'V01PRIO' => '01', # DHL Paket Prio 'V06PAK' => '06', # DHL Paket Taggleich 'V53WPAK' => '53', # DHL Paket International 'V54EPAK' => '54', # DHL Europaket 'V55PAK' => '55', # DHL Paket Connect 'V06TG' => '01', # DHL Kurier Taggleich 'V06WZ' => '01', # DHL Kurier Wunschzeit 'V86PARCEL' => '86', # DHL Paket Austria 'V87PARCEL' => '87', # DHL PAKET Connect 'V82PARCEL' => '82' # DHL PAKET International }.freeze
- PRODUCTS =
DHL PAKET International
PRODUCT_PROCEDURE_NUMBERS.keys.freeze
Instance Attribute Summary collapse
-
#bank_data ⇒ Object
Returns the value of attribute bank_data.
-
#customer_reference ⇒ Object
Returns the value of attribute customer_reference.
-
#export_document ⇒ Object
Returns the value of attribute export_document.
-
#height ⇒ Object
Returns the value of attribute height.
-
#length ⇒ Object
Returns the value of attribute length.
-
#notification_email ⇒ Object
Returns the value of attribute notification_email.
-
#product ⇒ Object
Returns the value of attribute product.
-
#receiver ⇒ Object
Returns the value of attribute receiver.
-
#services ⇒ Object
Returns the value of attribute services.
-
#shipment_date ⇒ Object
Returns the value of attribute shipment_date.
-
#shipper ⇒ Object
Returns the value of attribute shipper.
-
#weight ⇒ Object
Returns the value of attribute weight.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
-
.build(shipper:, receiver:, bank_data: nil, export_document: nil, **shipment_attributes) ⇒ Object
build a shipment from hash data.
Instance Method Summary collapse
- #assign_attributes(attributes) ⇒ Object
-
#initialize(**attributes) ⇒ Shipment
constructor
A new instance of Shipment.
- #to_soap_hash(ekp, participation_number) ⇒ Object
Constructor Details
#initialize(**attributes) ⇒ Shipment
Returns a new instance of Shipment.
33 34 35 36 37 38 39 40 41 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 33 def initialize(**attributes) assign_attributes( { product: 'V01PAK', shipment_date: Date.today, services: [] }.merge(attributes) ) end |
Instance Attribute Details
#bank_data ⇒ Object
Returns the value of attribute bank_data.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def bank_data @bank_data end |
#customer_reference ⇒ Object
Returns the value of attribute customer_reference.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def customer_reference @customer_reference end |
#export_document ⇒ Object
Returns the value of attribute export_document.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def export_document @export_document end |
#height ⇒ Object
Returns the value of attribute height.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def height @height end |
#length ⇒ Object
Returns the value of attribute length.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def length @length end |
#notification_email ⇒ Object
Returns the value of attribute notification_email.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def notification_email @notification_email end |
#product ⇒ Object
Returns the value of attribute product.
7 8 9 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 7 def product @product end |
#receiver ⇒ Object
Returns the value of attribute receiver.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def receiver @receiver end |
#services ⇒ Object
Returns the value of attribute services.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def services @services end |
#shipment_date ⇒ Object
Returns the value of attribute shipment_date.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def shipment_date @shipment_date end |
#shipper ⇒ Object
Returns the value of attribute shipper.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def shipper @shipper end |
#weight ⇒ Object
Returns the value of attribute weight.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def weight @weight end |
#width ⇒ Object
Returns the value of attribute width.
4 5 6 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 4 def width @width end |
Class Method Details
.build(shipper:, receiver:, bank_data: nil, export_document: nil, **shipment_attributes) ⇒ Object
build a shipment from hash data
25 26 27 28 29 30 31 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 25 def self.build(shipper:, receiver:, bank_data: nil, export_document: nil, **shipment_attributes) shipper = Shipper.build(**shipper) if shipper.is_a?(Hash) receiver = Receiver.build(**receiver) if receiver.is_a?(Hash) bank_data = BankData.build(**bank_data) if bank_data.is_a?(Hash) export_document = ExportDocument.build(export_document.delete(:export_doc_positions), **export_document) if export_document.is_a?(Hash) new(**{ shipper: shipper, receiver: receiver, bank_data: bank_data, export_document: export_document }.merge(shipment_attributes)) end |
Instance Method Details
#assign_attributes(attributes) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 43 def assign_attributes(attributes) attributes.each do |key, value| setter = :"#{key}=" send(setter, value) if respond_to?(setter) end end |
#to_soap_hash(ekp, participation_number) ⇒ Object
55 56 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 82 83 84 85 86 87 88 89 |
# File 'lib/dhl/bcs/v2/shipment.rb', line 55 def to_soap_hash(ekp, participation_number) raise Dhl::Bcs::Error, 'Packing weight in kilo must be set!' unless weight raise Dhl::Bcs::Error, 'Sender address must be set!' unless shipper raise Dhl::Bcs::Error, 'Receiver address must be set!' unless receiver raise Dhl::Bcs::Error, 'Product must be set!' unless product raise Dhl::Bcs::Error, 'In order to do an international shipment --product:V53WPAK--, :export_document muse be set!' unless !((product == 'V53WPAK') ^ export_document ) account_number = "#{ekp}#{PRODUCT_PROCEDURE_NUMBERS[product]}#{participation_number}" raise Dhl::Bcs::Error, 'Need a 14 character long account number. Check EKP and participation_number' if account_number.size != 14 { 'ShipmentDetails' => {}.tap { |h| h['product'] = product h['shipmentDate'] = shipment_date.strftime("%Y-%m-%d") h['cis:accountNumber'] = account_number h['customerReference'] = customer_reference if !customer_reference.blank? # just one ShipmentItem possible h['ShipmentItem'] = { 'weightInKG' => weight }.tap { |si| si['lengthInCM'] = length if length si['widthInCM'] = width if width si['heightInCM'] = height if height } h['Service'] = services.map(&:to_soap_hash) unless services.empty? h['Notification'] = { 'recipientEmailAddress' => notification_email } if notification_email h['BankData'] = bank_data.to_soap_hash if bank_data }, # Shipper information 'Shipper' => shipper.to_soap_hash, # Receiver information 'Receiver' => receiver.to_soap_hash }.tap{|h| #ExportDocuemnt information h['ExportDocument'] = export_document.to_soap_hash if export_document } end |