dhl-intraship 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -87,6 +87,23 @@ shipment_number = result[:shipment_number]
87
87
  label_url = result[:label_url] # Or result[:xml_label] in case XML label was set in the options
88
88
  ```
89
89
 
90
+ #### Add cash on delivery
91
+
92
+ For the "cash on delivery" service you need to create a Bankdata object with the payee information.
93
+ Give that together with the amount and the currency to a CODService object. Finally add the service to your shipment:
94
+
95
+ ```ruby
96
+ bankdata = Dhl::Intraship::Bankdata.new(owner: 'John Smith',
97
+ account_number: '1212121212',
98
+ bank_code: '12345679',
99
+ bank_name: 'Testbank 2',
100
+ note: 'OrderID 12345')
101
+ cod_service = Dhl::Intraship::CODService.new(amount: 15.00,
102
+ currency: 'EUR',
103
+ bankdata: bankdata)
104
+ shipment.add_service(cod_service)
105
+ ```
106
+
90
107
  ### Delete a shipment
91
108
 
92
109
  You can create and delete shipments as much as you like, they will not get into the "real" DHL system until you manifest them.
@@ -3,5 +3,9 @@ require "dhl-intraship/api"
3
3
  require "dhl-intraship/address"
4
4
  require "dhl-intraship/person_address"
5
5
  require "dhl-intraship/company_address"
6
+ require "dhl-intraship/packstation_address"
6
7
  require "dhl-intraship/shipment"
7
- require "dhl-intraship/product_code"
8
+ require "dhl-intraship/product_code"
9
+ require "dhl-intraship/bankdata"
10
+ require "dhl-intraship/service"
11
+ require "dhl-intraship/service/cod_service"
@@ -1,11 +1,10 @@
1
1
  module Dhl
2
2
  module Intraship
3
3
  class Address
4
- attr_accessor :street, :house_number, :street_additional, :street_additional_above_street,
5
- :zip, :city, :country_code, :email, :phone
4
+ attr_accessor :street, :house_number, :street_additional,
5
+ :zip, :city, :country_code, :contact_person, :email, :phone
6
6
 
7
7
  def initialize(attributes = {})
8
- self.street_additional_above_street = true
9
8
  attributes.each do |key, value|
10
9
  setter = :"#{key.to_s}="
11
10
  if self.respond_to?(setter)
@@ -18,10 +17,6 @@ module Dhl
18
17
  !self.company.blank?
19
18
  end
20
19
 
21
- def street_additional_above_street?
22
- self.street_additional_above_street
23
- end
24
-
25
20
  def country_code=(country_code)
26
21
  raise "Country code must be an ISO-3166 two digit code" unless country_code.length == 2
27
22
  @country_code = country_code
@@ -34,7 +29,7 @@ module Dhl
34
29
  xml.Address do |xml|
35
30
  xml.cis(:streetName, street)
36
31
  xml.cis(:streetNumber, house_number)
37
- xml.cis(:careOfName, street_additional) if !street_additional.blank? && !street_additional_above_street?
32
+ xml.cis(:careOfName, street_additional) unless street_additional.blank?
38
33
  xml.cis(:Zip) do |xml|
39
34
  if country_code == 'DE'
40
35
  xml.cis(:germany, zip)
@@ -52,7 +47,7 @@ module Dhl
52
47
  xml.Communication do |xml|
53
48
  xml.cis(:phone, self.phone) unless self.phone.blank?
54
49
  xml.cis(:email, self.email) unless self.email.blank?
55
- communication_xml(xml)
50
+ xml.cis(:contactPerson, contact_person.blank? ? "" : contact_person)
56
51
  end
57
52
  end
58
53
 
@@ -84,7 +84,7 @@ module Dhl
84
84
  end
85
85
 
86
86
  else
87
- raise "Intraship call failed with code #{r[:status][:status_code]}: #{r[:status][:status_message]} (Status messages: #{r[:creation_state][:status].to_s})"
87
+ raise "Intraship call failed with code #{r[:status][:status_code]}: #{r[:status][:status_message]} (Status messages: #{r[:creation_state][:status_message].to_s})"
88
88
  end
89
89
  rescue Savon::Error => error
90
90
  raise error
@@ -0,0 +1,28 @@
1
+ module Dhl
2
+ module Intraship
3
+ class Bankdata
4
+ attr_accessor :owner, :account_number, :bank_code, :bank_name, :iban, :bic, :note
5
+
6
+ def initialize(attributes = {})
7
+ attributes.each do |key, value|
8
+ setter = :"#{key.to_s}="
9
+ if self.respond_to?(setter)
10
+ self.send(setter, value)
11
+ end
12
+ end
13
+ end
14
+
15
+ def append_to_xml(xml)
16
+ xml.BankData do |xml|
17
+ xml.cis(:accountOwner, owner)
18
+ xml.cis(:accountNumber, account_number) unless account_number.blank?
19
+ xml.cis(:bankCode, bank_code) unless bank_code.blank?
20
+ xml.cis(:bankName, bank_name) unless bank_name.blank?
21
+ xml.cis(:iban, iban) unless iban.blank?
22
+ xml.cis(:note, note) unless note.blank?
23
+ xml.cis(:bic, bic) unless bic.blank?
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,20 +1,15 @@
1
1
  module Dhl
2
2
  module Intraship
3
3
  class CompanyAddress < Address
4
- attr_accessor :company, :contact_person
4
+ attr_accessor :company
5
5
 
6
6
  protected
7
7
 
8
8
  def company_xml(xml)
9
9
  xml.cis(:Company) do |xml|
10
10
  xml.cis(:name1, company)
11
- xml.cis(:name2, street_additional) if !street_additional.blank? && street_additional_above_street?
12
11
  end
13
12
  end
14
-
15
- def communication_xml(xml)
16
- xml.cis(:contactPerson, contact_person)
17
- end
18
13
  end
19
14
  end
20
15
  end
@@ -0,0 +1,25 @@
1
+ module Dhl
2
+ module Intraship
3
+ class PackstationAddress < CompanyAddress
4
+ attr_accessor :packstation, :postnumber
5
+
6
+ def append_to_xml(xml)
7
+ xml.Company do |xml|
8
+ company_xml(xml)
9
+ end
10
+ # this element has no namespace
11
+ xml.Packstation do |xml|
12
+ xml.PackstationNumber packstation
13
+ xml.PostNumber postnumber
14
+ xml.Zip zip
15
+ xml.City city
16
+ end
17
+ xml.Communication do |xml|
18
+ xml.cis(:phone, phone) unless phone.blank?
19
+ xml.cis(:email, email) unless email.blank?
20
+ xml.cis(:contactPerson, contact_person.blank? ? "" : contact_person)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -12,14 +12,6 @@ module Dhl
12
12
  xml.cis(:lastname, lastname)
13
13
  end
14
14
  end
15
-
16
- def communication_xml(xml)
17
- if !self.street_additional.blank? && street_additional_above_street?
18
- xml.cis(:contactPerson, street_additional)
19
- else
20
- xml.cis(:contactPerson, "") # This line is hiding the contact person line for receivers
21
- end
22
- end
23
15
  end
24
16
  end
25
17
  end
@@ -0,0 +1,16 @@
1
+ module Dhl
2
+ module Intraship
3
+ class Service
4
+
5
+ def initialize(attributes = {})
6
+ attributes.each do |key, value|
7
+ setter = :"#{key.to_s}="
8
+ if self.respond_to?(setter)
9
+ self.send(setter, value)
10
+ end
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ module Dhl
2
+ module Intraship
3
+ class CODService < Service
4
+ attr_accessor :amount, :currency, :bankdata
5
+
6
+ def append_to_xml(xml)
7
+ xml.Service do |xml|
8
+ xml.ServiceGroupOther do |xml|
9
+ xml.COD do |xml|
10
+ xml.CODAmount(amount)
11
+ xml.CODCurrency(currency)
12
+ end
13
+ end
14
+ end
15
+ bankdata.append_to_xml(xml)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -5,10 +5,12 @@ module Dhl
5
5
  class Shipment
6
6
  PACKAGE_TYPE = 'PK'
7
7
 
8
- attr_accessor :sender_address, :receiver_address, :shipment_date, :weight, :length, :height, :width, :product_code
8
+ attr_accessor :sender_address, :receiver_address, :shipment_date, :weight, :length, :height, :width, :product_code,
9
+ :customer_reference, :services
9
10
 
10
11
  def initialize(attributes = {})
11
12
  self.product_code = ProductCode::DHL_PACKAGE
13
+ self.services = []
12
14
  attributes.each do |key, value|
13
15
  setter = :"#{key.to_s}="
14
16
  if self.respond_to?(setter)
@@ -17,6 +19,10 @@ module Dhl
17
19
  end
18
20
  end
19
21
 
22
+ def add_service(newservice)
23
+ @services << newservice
24
+ end
25
+
20
26
  def product_code=(product_code)
21
27
  raise "No valid product code #{product_code}" unless ProductCode::VALID_PRODUCT_CODES.include?(product_code)
22
28
  @product_code = product_code
@@ -34,6 +40,7 @@ module Dhl
34
40
  xml.Attendance do |xml|
35
41
  xml.cis(:partnerID, partner_id)
36
42
  end
43
+ xml.CustomerReference(customer_reference) unless customer_reference.blank?
37
44
  xml.ShipmentItem do |xml|
38
45
  xml.WeightInKG(weight)
39
46
  xml.LengthInCM(length) unless length.nil?
@@ -41,6 +48,9 @@ module Dhl
41
48
  xml.HeightInCM(height) unless height.nil?
42
49
  xml.PackageType(PACKAGE_TYPE)
43
50
  end
51
+ services.each do |service|
52
+ service.append_to_xml(xml)
53
+ end
44
54
  end
45
55
  # Shipper information
46
56
  xml.Shipper do |xml|
@@ -1,5 +1,5 @@
1
1
  module Dhl
2
2
  module Intraship
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dhl-intraship
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-23 00:00:00.000000000 Z
12
+ date: 2014-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
@@ -75,10 +75,14 @@ files:
75
75
  - lib/dhl-intraship.rb
76
76
  - lib/dhl-intraship/address.rb
77
77
  - lib/dhl-intraship/api.rb
78
+ - lib/dhl-intraship/bankdata.rb
78
79
  - lib/dhl-intraship/booking_information.rb
79
80
  - lib/dhl-intraship/company_address.rb
81
+ - lib/dhl-intraship/packstation_address.rb
80
82
  - lib/dhl-intraship/person_address.rb
81
83
  - lib/dhl-intraship/product_code.rb
84
+ - lib/dhl-intraship/service.rb
85
+ - lib/dhl-intraship/service/cod_service.rb
82
86
  - lib/dhl-intraship/shipment.rb
83
87
  - lib/dhl-intraship/version.rb
84
88
  - spec/dhl-intraship/book_pickup_spec.rb
@@ -106,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
110
  version: '0'
107
111
  requirements: []
108
112
  rubyforge_project:
109
- rubygems_version: 1.8.23
113
+ rubygems_version: 1.8.24
110
114
  signing_key:
111
115
  specification_version: 3
112
116
  summary: This wraps the DHL Intraship SOAP Interface for creating shipments