dhl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ # require (File.expand_path('./../../spec_helper', __FILE__))
2
+ # For Ruby > 1.9.3, use this instead of require
3
+ require_relative '../../spec_helper'
4
+
5
+ describe Dhl::Client do
6
+
7
+ let(:client) { Dhl.client(username: 'username', password: 'password', account: 123456789) }
8
+
9
+ after do
10
+ VCR.eject_cassette
11
+ end
12
+
13
+ describe '#request_shipment' do
14
+ before do
15
+ VCR.insert_cassette 'shipment', record: :new_episodes
16
+ end
17
+
18
+ let(:shipment_request) { Dhl::ShipmentRequest.new }
19
+ let(:shipper) { FactoryGirl.build(:contact) }
20
+ let(:recipient) { FactoryGirl.build(:contact) }
21
+ let(:packages) { shipment_request.packages }
22
+ let(:shipment) { FactoryGirl.build(:shipment) }
23
+
24
+ it "should return a PDF shipping label" do
25
+ shipment_request.shipper = shipper
26
+ shipment_request.recipient = recipient
27
+ shipment.pickup_time = (Time.now + 86400)
28
+ shipment_request.shipment = shipment
29
+
30
+ packages.add(50, 10, 15, 20, 'Ref 1')
31
+ packages.add(100, 40, 45, 35, 'Ref 2')
32
+
33
+ response = client.request_shipment(shipment_request)
34
+ response[:tracking_numbers].should == ["JD012038742880323158", "JD012038742880323159"]
35
+ File.exists?('labels/9085882330.pdf').should be_true
36
+ end
37
+ end
38
+
39
+ # describe '#track' do
40
+ # before do
41
+ # VCR.insert_cassette 'tracking', record: :new_episodes
42
+ # end
43
+
44
+ # it "should give back a tracking status" do
45
+ # response = client.track ["JD012038742880323158"]
46
+ # response[:tracking_response][:awb_info][:array].should_have 1.item
47
+ # end
48
+ # end
49
+
50
+ end
@@ -0,0 +1,36 @@
1
+ require (File.expand_path('./../../../spec_helper', __FILE__))
2
+ # For Ruby > 1.9.3, use this instead of require
3
+ # require_relative '../../spec_helper'
4
+
5
+ describe Dhl::Contact do
6
+
7
+ let(:contact) { FactoryGirl.build(:contact) }
8
+
9
+ describe '#to_hash' do
10
+ it "should return the expected hash structure" do
11
+ hash = contact.to_hash
12
+ hash.should == {
13
+ contact: {
14
+ person_name: 'John Doe',
15
+ company_name: 'ACME Inc',
16
+ phone_number: '+391234567890',
17
+ email_address: 'john@example.com' # Optional
18
+ },
19
+ address: {
20
+ street_lines: 'Piazza Duomo, 1234',
21
+ street_lines_2: 'Scala B', # Optional
22
+ city: 'Milano',
23
+ postal_code: '20121',
24
+ country_code: 'IT',
25
+ street_name: 'Piazza Duomo', # Optional
26
+ street_number: '1234', # Optional
27
+ state_or_province_code: 'MI' # Optional
28
+ }
29
+ }
30
+ hash[:address].should_not have_key(:street_lines_3)
31
+ end
32
+
33
+ # it "should raise an exception if not all required fields are present"
34
+ end
35
+
36
+ end
@@ -0,0 +1,43 @@
1
+ require (File.expand_path('./../../../spec_helper', __FILE__))
2
+ # For Ruby > 1.9.3, use this instead of require
3
+ # require_relative '../../spec_helper'
4
+
5
+ describe Dhl::Packages do
6
+
7
+ let(:packages) { Dhl::Packages.new }
8
+
9
+ describe '#to_hash' do
10
+ it "should return the expected hash structure" do
11
+ packages.add(50, 10, 15, 20, 'Ref 1')
12
+ packages.add(100, 40, 45, 35, 'Ref 2')
13
+
14
+ hash = packages.to_hash
15
+ hash.should == {
16
+ requested_packages: [
17
+ {
18
+ weight: 50,
19
+ dimensions: {
20
+ width: 10,
21
+ height: 15,
22
+ length: 20
23
+ },
24
+ customer_references: 'Ref 1'
25
+ },
26
+ {
27
+ weight: 100,
28
+ dimensions: {
29
+ width: 40,
30
+ height: 45,
31
+ length: 35
32
+ },
33
+ customer_references: 'Ref 2'
34
+ }
35
+ ],
36
+ :attributes! => { requested_packages: { number: [1, 2] } }
37
+ }
38
+ end
39
+
40
+ # it "should raise an exception if not all required fields are present"
41
+ end
42
+
43
+ end
@@ -0,0 +1,108 @@
1
+ require (File.expand_path('./../../../spec_helper', __FILE__))
2
+ # For Ruby > 1.9.3, use this instead of require
3
+ # require_relative '../../spec_helper'
4
+
5
+ describe Dhl::ShipmentRequest do
6
+
7
+ let(:shipment_request) { Dhl::ShipmentRequest.new }
8
+ let(:shipper) { FactoryGirl.build(:contact) }
9
+ let(:recipient) { FactoryGirl.build(:contact) }
10
+ let(:packages) { shipment_request.packages }
11
+ let(:shipment) { FactoryGirl.build(:shipment) }
12
+
13
+ describe '#to_hash' do
14
+ it "should return the expected hash structure" do
15
+ Dhl.config.account = 123456789
16
+ shipment_request.shipper = shipper
17
+ shipment_request.recipient = recipient
18
+ shipment_request.shipment = shipment
19
+
20
+ packages.add(50, 10, 15, 20, 'Ref 1')
21
+ packages.add(100, 40, 45, 35, 'Ref 2')
22
+
23
+ hash = shipment_request.to_hash
24
+ hash.should == {
25
+ requested_shipment: {
26
+ shipment_info: {
27
+ drop_off_type: "REGULAR_PICKUP",
28
+ service_type: 'N',
29
+ currency: 'EUR',
30
+ unit_of_measurement: 'SI', # Or SU, UK, US
31
+ account: 123456789
32
+ },
33
+ ship_timestamp: '2013-12-31T16:45:10GMT+00:00', # When is the shipment going to be ready for pickup?
34
+ payment_info: 'DDP',
35
+ international_detail: {
36
+ commodities: {
37
+ number_of_pieces: 2,
38
+ description: 'General goods'
39
+ }
40
+ },
41
+ ship: {
42
+ shipper: {
43
+ contact: {
44
+ person_name: 'John Doe',
45
+ company_name: 'ACME Inc',
46
+ phone_number: '+391234567890',
47
+ email_address: 'john@example.com' # Optional
48
+ },
49
+ address: {
50
+ street_lines: 'Piazza Duomo, 1234',
51
+ street_lines_2: 'Scala B', # Optional
52
+ city: 'Milano',
53
+ postal_code: '20121',
54
+ country_code: 'IT',
55
+ street_name: 'Piazza Duomo', # Optional
56
+ street_number: '1234', # Optional
57
+ state_or_province_code: 'MI' # Optional
58
+ }
59
+ },
60
+ recipient: {
61
+ contact: {
62
+ person_name: 'John Doe',
63
+ company_name: 'ACME Inc',
64
+ phone_number: '+391234567890',
65
+ email_address: 'john@example.com' # Optional
66
+ },
67
+ address: {
68
+ street_lines: 'Piazza Duomo, 1234',
69
+ street_lines_2: 'Scala B', # Optional
70
+ city: 'Milano',
71
+ postal_code: '20121',
72
+ country_code: 'IT',
73
+ street_name: 'Piazza Duomo', # Optional
74
+ street_number: '1234', # Optional
75
+ state_or_province_code: 'MI' # Optional
76
+ }
77
+ }
78
+ },
79
+ packages: {
80
+ requested_packages: [
81
+ {
82
+ weight: 50,
83
+ dimensions: {
84
+ width: 10,
85
+ height: 15,
86
+ length: 20
87
+ },
88
+ customer_references: 'Ref 1'
89
+ },
90
+ {
91
+ weight: 100,
92
+ dimensions: {
93
+ width: 40,
94
+ height: 45,
95
+ length: 35
96
+ },
97
+ customer_references: 'Ref 2'
98
+ }
99
+ ],
100
+ :attributes! => { requested_packages: { number: [1, 2] } }
101
+ }
102
+ }
103
+ }
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,39 @@
1
+ require (File.expand_path('./../../../spec_helper', __FILE__))
2
+ # For Ruby > 1.9.3, use this instead of require
3
+ # require_relative '../../spec_helper'
4
+
5
+ describe Dhl::Shipment do
6
+
7
+ let(:shipment) { Dhl::Shipment.new }
8
+
9
+ describe '#to_hash' do
10
+ it "should return the expected hash structure" do
11
+ Dhl.config.account = 123456789
12
+ shipment.pickup_time = Time.parse("16:45:10 31/12/2013 GMT+2")
13
+ shipment.pieces = 2
14
+ shipment.description = 'General goods'
15
+
16
+ hash = shipment.to_hash
17
+ hash.should == {
18
+ shipment_info: {
19
+ drop_off_type: "REGULAR_PICKUP",
20
+ service_type: 'N',
21
+ currency: 'EUR',
22
+ unit_of_measurement: 'SI', # Or SU, UK, US
23
+ account: 123456789
24
+ },
25
+ ship_timestamp: '2013-12-31T16:45:10GMT+00:00', # When is the shipment going to be ready for pickup?
26
+ payment_info: 'DDP',
27
+ international_detail: {
28
+ commodities: {
29
+ number_of_pieces: 2,
30
+ description: 'General goods'
31
+ }
32
+ }
33
+ }
34
+ end
35
+
36
+ # it "should raise an exception if not all required fields are present"
37
+ end
38
+
39
+ end
@@ -0,0 +1,42 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+
18
+ config.after(:all) do
19
+ FileUtils.rm_rf('labels')
20
+ end
21
+
22
+ end
23
+
24
+ require_relative '../lib/dhl'
25
+ # For Ruby < 1.9.3, use this instead of require_relative
26
+ # require(File.expand_path('../../lib/dish', __FILE__))
27
+
28
+ require 'time'
29
+ require 'factory_girl'
30
+ FactoryGirl.find_definitions
31
+ require 'pry'
32
+
33
+ require 'rspec/autorun'
34
+ require 'webmock/rspec'
35
+ require 'vcr'
36
+
37
+ #VCR config
38
+ VCR.configure do |config|
39
+ config.cassette_library_dir = 'spec/fixtures/dhl_cassettes'
40
+ config.hook_into :webmock
41
+ config.allow_http_connections_when_no_cassette = true
42
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dhl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Mencarini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.13.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_girl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 4.2.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 4.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.9.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.9.0
111
+ description: 'A wrapper for DHL SOAP interface. '
112
+ email:
113
+ - a.mencarini@freegoweb.it
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - dhl.gemspec
126
+ - lib/dhl.rb
127
+ - lib/dhl/client.rb
128
+ - lib/dhl/configuration.rb
129
+ - lib/dhl/contact.rb
130
+ - lib/dhl/examples.rb
131
+ - lib/dhl/package.rb
132
+ - lib/dhl/packages.rb
133
+ - lib/dhl/shipment.rb
134
+ - lib/dhl/shipment_request.rb
135
+ - lib/dhl/tracking_request.rb
136
+ - lib/dhl/version.rb
137
+ - spec/factories/contact_factory.rb
138
+ - spec/factories/shipment_factory.rb
139
+ - spec/fixtures/dhl_cassettes/shipment.yml
140
+ - spec/lib/dhl/client_spec.rb
141
+ - spec/lib/dhl/contact_spec.rb
142
+ - spec/lib/dhl/packages_spec.rb
143
+ - spec/lib/dhl/shipment_request_spec.rb
144
+ - spec/lib/dhl/shipment_spec.rb
145
+ - spec/spec_helper.rb
146
+ homepage: http://momitians.github.io/dhl
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.0.2
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: This gem will provide a wrapper to DHL SOAP API. Given DHL credentials and
170
+ the addresses, will generate a shipping label.
171
+ test_files:
172
+ - spec/factories/contact_factory.rb
173
+ - spec/factories/shipment_factory.rb
174
+ - spec/fixtures/dhl_cassettes/shipment.yml
175
+ - spec/lib/dhl/client_spec.rb
176
+ - spec/lib/dhl/contact_spec.rb
177
+ - spec/lib/dhl/packages_spec.rb
178
+ - spec/lib/dhl/shipment_request_spec.rb
179
+ - spec/lib/dhl/shipment_spec.rb
180
+ - spec/spec_helper.rb