Class: Dhl::Intraship::Shipment

Inherits:
Object
  • Object
show all
Defined in:
lib/dhl-intraship/shipment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Shipment

Returns a new instance of Shipment.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dhl-intraship/shipment.rb', line 8

def initialize(attributes = {})
  self.product_code = ProductCode::DHL_PACKAGE
  self.services = []
  self.shipment_items = []

  # If an initial shipment is given we have to create a new
  # ShipmentItem (for backward compatibility). Maybe we can drop
  # this in a new major release ...
  if attributes.has_key?(:weight) or attributes.has_key?(:length) or
      attributes.has_key?(:width) or attributes.has_key?(:height)
    warn "[DEPRECATION] The single shipment constructor is deprecated, please pass in a ShipmentItem"
    @shipment_items << ShipmentItem.new(attributes)
  else
    @shipment_items.push(*attributes.delete(:shipment_items))
  end

  attributes.each do |key, value|
    setter = :"#{key.to_s}="
    if self.respond_to?(setter)
      self.send(setter, value)
    end
  end
end

Instance Attribute Details

#customer_referenceObject

Returns the value of attribute customer_reference.



5
6
7
# File 'lib/dhl-intraship/shipment.rb', line 5

def customer_reference
  @customer_reference
end

#dhl_express_serviceObject

Returns the value of attribute dhl_express_service.



5
6
7
# File 'lib/dhl-intraship/shipment.rb', line 5

def dhl_express_service
  @dhl_express_service
end

#product_codeObject

Returns the value of attribute product_code.



5
6
7
# File 'lib/dhl-intraship/shipment.rb', line 5

def product_code
  @product_code
end

#receiver_addressObject

Returns the value of attribute receiver_address.



5
6
7
# File 'lib/dhl-intraship/shipment.rb', line 5

def receiver_address
  @receiver_address
end

#sender_addressObject

Returns the value of attribute sender_address.



5
6
7
# File 'lib/dhl-intraship/shipment.rb', line 5

def sender_address
  @sender_address
end

#servicesObject

Returns the value of attribute services.



5
6
7
# File 'lib/dhl-intraship/shipment.rb', line 5

def services
  @services
end

#shipment_dateObject

Returns the value of attribute shipment_date.



5
6
7
# File 'lib/dhl-intraship/shipment.rb', line 5

def shipment_date
  @shipment_date
end

#shipment_itemsObject

Returns the value of attribute shipment_items.



5
6
7
# File 'lib/dhl-intraship/shipment.rb', line 5

def shipment_items
  @shipment_items
end

Instance Method Details

#add_service(newservice) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/dhl-intraship/shipment.rb', line 32

def add_service(newservice)
  case newservice
  when DhlExpressService
    unless dhl_domestic_express?
    end
  end
  @services << newservice
end

#add_shipment_item(shipment_item) ⇒ Object



41
42
43
# File 'lib/dhl-intraship/shipment.rb', line 41

def add_shipment_item(shipment_item)
  @shipment_items << shipment_item
end

#append_to_xml(ekp, partner_id, xml) ⇒ Object



50
51
52
53
54
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
# File 'lib/dhl-intraship/shipment.rb', line 50

def append_to_xml(ekp, partner_id, xml)
  raise "Shipment date must be set!" if shipment_date.blank?
  raise "Sender address must be set!" if sender_address.blank?
  raise "Receiver address must be set!" if receiver_address.blank?

  add_and_validate_service_dependencies

  xml.Shipment do |xml|
    xml.ShipmentDetails do |xml|
      xml.ProductCode(product_code)
      xml.ShipmentDate(shipment_date.strftime("%Y-%m-%d"))
      xml.cis(:EKP, ekp)
      xml.Attendance do |xml|
        xml.cis(:partnerID, partner_id)
      end
      xml.CustomerReference(customer_reference) unless customer_reference.blank?

      # multiple parcels
      shipment_items.each do |shipment_item|
        shipment_item.append_to_xml(xml)
      end
      services.each do |service|
        service.append_to_xml(xml)
      end
    end
    # Shipper information
    xml.Shipper do |xml|
      sender_address.append_to_xml(xml)
    end
    # Receiver information
    xml.Receiver do |xml|
      receiver_address.append_to_xml(xml)
    end
  end
end