dhl-intraship 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -46,23 +46,24 @@ options = {test: true, # If test is set, all API calls go against the Intraship
46
46
  To send a shipment to DHL you need to create it first:
47
47
 
48
48
  ```ruby
49
- sender_address = Dhl::Intraship::Address.new(company: 'Team Europe Ventures',
50
- street: 'Mohrenstraße',
51
- house_number: '60',
52
- zip: '10117',
53
- city: 'Berlin',
54
- country_code: 'DE',
55
- email: 'info@teameurope.net')
56
-
57
- receiver_address = Dhl::Intraship::Address.new(firstname: 'John',
58
- lastname: 'Doe',
59
- street: 'Mainstreet',
60
- house_number: '10',
61
- street_additional: 'Appartment 2a',
62
- zip: '90210',
63
- city: 'Springfield',
64
- country_code: 'DE',
65
- email: 'john.doe@example.com')
49
+ sender_address = Dhl::Intraship::CompanyAddress.new(company: 'Team Europe Ventures',
50
+ contact_person: 'John Smith',
51
+ street: 'Mohrenstraße',
52
+ house_number: '60',
53
+ zip: '10117',
54
+ city: 'Berlin',
55
+ country_code: 'DE',
56
+ email: 'info@teameurope.net')
57
+
58
+ receiver_address = Dhl::Intraship::PersonAddress.new(firstname: 'John',
59
+ lastname: 'Doe',
60
+ street: 'Mainstreet',
61
+ house_number: '10',
62
+ street_additional: 'Appartment 2a',
63
+ zip: '90210',
64
+ city: 'Springfield',
65
+ country_code: 'DE',
66
+ email: 'john.doe@example.com')
66
67
 
67
68
  # Note that the weight parameter is in kg and the length/height/width in cm
68
69
  shipment = Dhl::Intraship::Shipment.new(sender_address: sender_address,
@@ -73,8 +74,9 @@ shipment = Dhl::Intraship::Shipment.new(sender_address: sender_address,
73
74
  height:15,
74
75
  width: 25)
75
76
  ```
76
-
77
- Note that the actual api-call takes an array of shipments
77
+ Beware, that due to DHL Intraship restrictions, the sender address must be a
78
+ CompanyAddress and requires a contact_person.
79
+ Also, note that the actual api-call takes an array of shipments:
78
80
 
79
81
  ```ruby
80
82
  result = api.createShipmentDD([shipment])
@@ -1,5 +1,7 @@
1
1
  require "dhl-intraship/version"
2
2
  require "dhl-intraship/api"
3
3
  require "dhl-intraship/address"
4
+ require "dhl-intraship/person_address"
5
+ require "dhl-intraship/company_address"
4
6
  require "dhl-intraship/shipment"
5
7
  require "dhl-intraship/product_code"
@@ -1,10 +1,11 @@
1
1
  module Dhl
2
2
  module Intraship
3
3
  class Address
4
- attr_accessor :company, :salutation, :firstname, :lastname, :street, :house_number, :street_additional,
4
+ attr_accessor :street, :house_number, :street_additional, :street_additional_above_street,
5
5
  :zip, :city, :country_code, :email
6
6
 
7
7
  def initialize(attributes = {})
8
+ self.street_additional_above_street = true
8
9
  attributes.each do |key, value|
9
10
  setter = :"#{key.to_s}="
10
11
  if self.respond_to?(setter)
@@ -16,6 +17,10 @@ module Dhl
16
17
  def company?
17
18
  !self.company.blank?
18
19
  end
20
+
21
+ def street_additional_above_street?
22
+ self.street_additional_above_street
23
+ end
19
24
 
20
25
  def country_code=(country_code)
21
26
  raise "Country code must be an ISO-3166 two digit code" unless country_code.length == 2
@@ -32,28 +37,15 @@ module Dhl
32
37
 
33
38
  @email = "#{local_part}@#{split[1]}"
34
39
  end
35
-
40
+
36
41
  def append_to_xml(xml)
37
42
  xml.Company do |xml|
38
- if company?
39
- xml.cis(:Company) do |xml|
40
- xml.cis(:name1, company)
41
- if !street_additional.blank?
42
- xml.cis(:name2, street_additional)
43
- end
44
- end
45
- else
46
- xml.cis(:Person) do |xml|
47
- xml.cis(:salutation, salutation)
48
- xml.cis(:firstname, firstname)
49
- xml.cis(:lastname, lastname)
50
- end
51
- end
43
+ company_xml(xml)
52
44
  end
53
45
  xml.Address do |xml|
54
46
  xml.cis(:streetName, street)
55
47
  xml.cis(:streetNumber, house_number)
56
- xml.cis(:careOfName, street_additional) unless street_additional.nil?
48
+ xml.cis(:careOfName, street_additional) if !street_additional.blank? && !street_additional_above_street?
57
49
  xml.cis(:Zip) do |xml|
58
50
  if country_code == 'DE'
59
51
  xml.cis(:germany, zip)
@@ -69,10 +61,20 @@ module Dhl
69
61
  end
70
62
  end
71
63
  xml.Communication do |xml|
72
- xml.cis(:email, self.email)
73
- xml.cis(:contactPerson, "#{firstname} #{lastname}")
64
+ xml.cis(:email, self.email) unless self.email.blank?
65
+ communication_xml(xml)
74
66
  end
75
67
  end
68
+
69
+ protected
70
+
71
+ def company_xml(xml)
72
+ raise "Use one of the two subclasses: PersonAddress or CompanyAddress!"
73
+ end
74
+
75
+ def communication_xml(xml)
76
+ raise "Use one of the two subclasses: PersonAddress or CompanyAddress!"
77
+ end
76
78
  end
77
79
  end
78
80
  end
@@ -0,0 +1,20 @@
1
+ module Dhl
2
+ module Intraship
3
+ class CompanyAddress < Address
4
+ attr_accessor :company, :contact_person
5
+
6
+ protected
7
+
8
+ def company_xml(xml)
9
+ xml.cis(:Company) do |xml|
10
+ xml.cis(:name1, company)
11
+ xml.cis(:name2, street_additional) if !street_additional.blank? && street_additional_above_street?
12
+ end
13
+ end
14
+
15
+ def communication_xml(xml)
16
+ xml.cis(:contactPerson, contact_person)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ module Dhl
2
+ module Intraship
3
+ class PersonAddress < Address
4
+ attr_accessor :salutation, :firstname, :lastname
5
+
6
+ protected
7
+
8
+ def company_xml(xml)
9
+ xml.cis(:Person) do |xml|
10
+ xml.cis(:salutation, salutation)
11
+ xml.cis(:firstname, firstname)
12
+ xml.cis(:lastname, lastname)
13
+ end
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
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module Dhl
2
2
  module Intraship
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -47,8 +47,8 @@ EOS
47
47
 
48
48
  shipment = Shipment.new(shipment_date: Date.today + 1)
49
49
 
50
- sender = Address.new
51
- receiver = Address.new
50
+ sender = CopmanyAddress.new
51
+ receiver = PersonAddress.new
52
52
  shipment.receiver_address=receiver
53
53
  shipment.sender_address=sender
54
54
 
@@ -2,6 +2,8 @@ require 'savon/spec'
2
2
  require 'dhl-intraship/api'
3
3
  require 'dhl-intraship/shipment'
4
4
  require 'dhl-intraship/address'
5
+ require 'dhl-intraship/person_address'
6
+ require 'dhl-intraship/company_address'
5
7
 
6
8
  RSpec.configure do |config|
7
9
  config.include Savon::Spec::Macros
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.1.0
4
+ version: 0.1.1
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-05-14 00:00:00.000000000 Z
12
+ date: 2012-06-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
@@ -75,6 +75,8 @@ 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/company_address.rb
79
+ - lib/dhl-intraship/person_address.rb
78
80
  - lib/dhl-intraship/product_code.rb
79
81
  - lib/dhl-intraship/shipment.rb
80
82
  - lib/dhl-intraship/version.rb
@@ -102,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
104
  version: '0'
103
105
  requirements: []
104
106
  rubyforge_project:
105
- rubygems_version: 1.8.24
107
+ rubygems_version: 1.8.18
106
108
  signing_key:
107
109
  specification_version: 3
108
110
  summary: This wraps the DHL Intraship SOAP Interface for creating shipments