dhl-intraship 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
  Initialize a new API object using
23
23
 
24
24
  ```ruby
25
- api = Dhl::Infraship::API.new(config, options)
25
+ api = Dhl::Intraship::API.new(config, options)
26
26
  ```
27
27
 
28
28
  Config is the following hash:
@@ -43,11 +43,10 @@ module Dhl
43
43
 
44
44
  def createShipmentDD(shipments)
45
45
  begin
46
+ shipments = [shipments] unless shipments.respond_to?('each')
47
+
46
48
  # For some reason the class instance variables are not accessible inside of the request block
47
- user = @user
48
- signature = @signature
49
- ekp = @ekp
50
- procedure_id = @procedure_id
49
+ ekp = @ekp
51
50
  partner_id = @partner_id
52
51
 
53
52
  returnXML = @config && @config[:label_response_type] && @config[:label_response_type] == :xml;
@@ -55,12 +54,7 @@ module Dhl
55
54
  soap.xml do |xml|
56
55
  xml.soapenv(:Envelope, DEFAULT_NAMESPACES) do |xml|
57
56
  xml.soapenv(:Header) do |xml|
58
- xml.cis(:Authentification) do |xml|
59
- xml.cis(:user, user)
60
- xml.cis(:signature, signature)
61
- xml.cis(:accountNumber, "#{ekp}|#{procedure_id}|#{partner_id}")
62
- xml.cis(:type, '0')
63
- end
57
+ append_default_header_to_xml(xml)
64
58
  end
65
59
  xml.soapenv(:Body) do |xml|
66
60
  xml.de(:"CreateShipmentDDRequest") do |xml|
@@ -93,12 +87,62 @@ module Dhl
93
87
  end
94
88
 
95
89
  else
96
- raise "Intraship call failed with code #{r[:status][:status_code]}: #{r[:status][:status_message]}"
90
+ raise "Intraship call failed with code #{r[:status][:status_code]}: #{r[:status][:status_message]} (Status messages: #{r[:creation_state][:status].to_s})"
97
91
  end
98
92
  rescue Savon::Error => error
99
93
  raise error
100
94
  end
101
95
  end
96
+
97
+ def deleteShipmentDD(shipment_number)
98
+ begin
99
+ result = @client.request "de:DeleteShipmentDDRequest" do
100
+ soap.xml do |xml|
101
+ xml.soapenv(:Envelope, DEFAULT_NAMESPACES) do |xml|
102
+ xml.soapenv(:Header) do |xml|
103
+ append_default_header_to_xml(xml)
104
+ end
105
+ xml.soapenv(:Body) do |xml|
106
+ xml.de(:"DeleteShipmentDDRequest") do |xml|
107
+ xml.cis(:Version) do |xml|
108
+ xml.cis(:majorRelease, '1')
109
+ xml.cis(:minorRelease, '0')
110
+ end
111
+ xml.ShipmentNumber do |xml|
112
+ xml.cis(:shipmentNumber, shipment_number)
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ r = result.to_hash[:delete_shipment_response]
120
+
121
+ # Return true if successful
122
+ raise "Intraship call failed with code #{r[:status][:status_code]}: #{r[:status][:status_message]} (Status messages: #{r[:deletion_state][:status].to_s})" unless r[:status][:status_code] == '0'
123
+
124
+ true
125
+ rescue Savon::Error => error
126
+ raise error
127
+ end
128
+ end
129
+
130
+ protected
131
+ def append_default_header_to_xml(xml)
132
+ # For some reason the class instance variables are not accessible inside of the request block
133
+ user = @user
134
+ signature = @signature
135
+ ekp = @ekp
136
+ procedure_id = @procedure_id
137
+ partner_id = @partner_id
138
+
139
+ xml.cis(:Authentification) do |xml|
140
+ xml.cis(:user, user)
141
+ xml.cis(:signature, signature)
142
+ xml.cis(:accountNumber, "#{ekp}|#{procedure_id}|#{partner_id}")
143
+ xml.cis(:type, '0')
144
+ end
145
+ end
102
146
  end
103
147
  end
104
- end
148
+ end
@@ -54,4 +54,4 @@ module Dhl
54
54
  end
55
55
  end
56
56
  end
57
- end
57
+ end
@@ -1,5 +1,5 @@
1
1
  module Dhl
2
2
  module Intraship
3
- VERSION = "0.0.8"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module Dhl
4
4
  module Intraship
5
5
 
6
- TEST_RESPONSE = <<EOS
6
+ CREATE_RESPONSE = <<EOS
7
7
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
8
8
  <soapenv:Body>
9
9
  <ns2:CreateShipmentResponse xmlns:ns2="http://de.ws.intraship">
@@ -43,7 +43,7 @@ EOS
43
43
  end
44
44
 
45
45
  it "should create an API call" do
46
- savon.expects("de:CreateShipmentDDRequest" ).returns( code: 200, headers: {},body: TEST_RESPONSE )
46
+ savon.expects("de:CreateShipmentDDRequest" ).returns( code: 200, headers: {},body: CREATE_RESPONSE )
47
47
 
48
48
  shipment = Shipment.new(shipment_date: Date.today + 1)
49
49
 
@@ -52,7 +52,7 @@ EOS
52
52
  shipment.receiver_address=receiver
53
53
  shipment.sender_address=sender
54
54
 
55
- @api.createShipmentDD([shipment]).should_not be_nil
55
+ @api.createShipmentDD(shipment).should_not be_nil
56
56
  end
57
57
  end
58
58
 
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ module Dhl
4
+ module Intraship
5
+
6
+ ERROR_DELETE_RESPONSE = <<EOS
7
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
8
+ <soapenv:Body>
9
+ <ns4:DeleteShipmentResponse xmlns:ns4="http://de.ws.intraship">
10
+ <Version xmlns="http://dhl.de/webservice/cisbase">
11
+ <majorRelease>1</majorRelease>
12
+ <minorRelease>0</minorRelease>
13
+ <build>14</build>
14
+ </Version>
15
+ <Status>
16
+ <StatusCode>1050</StatusCode>
17
+ <StatusMessage>at least on shipment could not be deleted</StatusMessage>
18
+ </Status>
19
+ <DeletionState>
20
+ <ShipmentNumber>
21
+ <ns1:shipmentNumber xmlns:ns1="http://dhl.de/webservice/cisbase">123</ns1:shipmentNumber>
22
+ </ShipmentNumber>
23
+ <Status>
24
+ <StatusCode>2000</StatusCode>
25
+ <StatusMessage>shipment not found or is deleted.</StatusMessage>
26
+ </Status>
27
+ </DeletionState>
28
+ </ns4:DeleteShipmentResponse>
29
+ </soapenv:Body>
30
+ </soapenv:Envelope>
31
+ EOS
32
+
33
+ DELETE_RESPONSE = <<EOS
34
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
35
+ <soapenv:Body>
36
+ <ns4:DeleteShipmentResponse xmlns:ns4="http://de.ws.intraship">
37
+ <Version xmlns="http://dhl.de/webservice/cisbase">
38
+ <majorRelease>1</majorRelease>
39
+ <minorRelease>0</minorRelease>
40
+ <build>11</build>
41
+ </Version>
42
+ <status>
43
+ <StatusCode>0</StatusCode>
44
+ <StatusMessage>ok</StatusMessage>
45
+ </status>
46
+ <DeletionState>
47
+ <StatusCode>0</StatusCode>
48
+ <StatusMessage>ok</StatusMessage>
49
+ <ShipmentNumber>
50
+ <ns1:shipmentNumber xmlns:ns1="http://dhl.de/webservice/cisbase">123</ns1:shipmentNumber>
51
+ </ShipmentNumber>
52
+ </DeletionState>
53
+ </ns4:DeleteShipmentResponse>
54
+ </soapenv:Body>
55
+ </soapenv:Envelope>
56
+ EOS
57
+
58
+ describe API do
59
+ before(:each) do
60
+ config = {user: 'user', signature: 'signature', ekp: 'ekp12345'}
61
+ options = {test: true}
62
+ @api = API.new(config, options)
63
+ end
64
+
65
+ it "should raise an exception on a failed call" do
66
+ savon.expects("de:DeleteShipmentDDRequest").returns( code: 200, headers: {},body: ERROR_DELETE_RESPONSE )
67
+
68
+ expect { @api.deleteShipmentDD("123") }.should raise_error
69
+ end
70
+
71
+ it "should return true on successful call" do
72
+ savon.expects("de:DeleteShipmentDDRequest").returns( code: 200, headers: {},body: DELETE_RESPONSE )
73
+
74
+ @api.deleteShipmentDD("123").should be_true
75
+ end
76
+ end
77
+
78
+ end
79
+ 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.0.8
4
+ version: 0.1.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-04-26 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
@@ -80,6 +80,7 @@ files:
80
80
  - lib/dhl-intraship/version.rb
81
81
  - spec/dhl-intraship/address_spec.rb
82
82
  - spec/dhl-intraship/create_shipment_dd_spec.rb
83
+ - spec/dhl-intraship/delete_shipment_dd_spec.rb
83
84
  - spec/spec_helper.rb
84
85
  homepage: https://github.com/teameurope/dhl-intraship
85
86
  licenses: []
@@ -101,11 +102,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  version: '0'
102
103
  requirements: []
103
104
  rubyforge_project:
104
- rubygems_version: 1.8.23
105
+ rubygems_version: 1.8.24
105
106
  signing_key:
106
107
  specification_version: 3
107
108
  summary: This wraps the DHL Intraship SOAP Interface for creating shipments
108
109
  test_files:
109
110
  - spec/dhl-intraship/address_spec.rb
110
111
  - spec/dhl-intraship/create_shipment_dd_spec.rb
112
+ - spec/dhl-intraship/delete_shipment_dd_spec.rb
111
113
  - spec/spec_helper.rb