ups-ruby 0.9.6 → 0.11.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,52 +16,160 @@ describe UPS::Connection do
16
16
  let(:stub_path) { File.expand_path("../../../stubs", __FILE__) }
17
17
  let(:server) { UPS::Connection.new(test_mode: true) }
18
18
 
19
- describe "if requesting a shipment" do
20
- before do
21
- Excon.stub({:method => :post}) do |params|
22
- case params[:path]
23
- when UPS::Connection::SHIP_CONFIRM_PATH
24
- {body: File.read("#{stub_path}/ship_confirm_success.xml"), status: 200}
25
- when UPS::Connection::SHIP_ACCEPT_PATH
26
- {body: File.read("#{stub_path}/ship_accept_success.xml"), status: 200}
19
+ describe 'if requesting a shipment' do
20
+ describe 'single package shipment' do
21
+ before do
22
+ Excon.stub(method: :post) do |params|
23
+ case params[:path]
24
+ when UPS::Connection::SHIP_CONFIRM_PATH
25
+ {
26
+ body: File.read("#{stub_path}/ship_confirm_success.xml"), status: 200
27
+ }
28
+ when UPS::Connection::SHIP_ACCEPT_PATH
29
+ {
30
+ body: File.read("#{stub_path}/ship_accept_success.xml"), status: 200
31
+ }
32
+ end
27
33
  end
28
34
  end
29
- end
30
35
 
31
- subject do
32
- server.ship do |shipment_builder|
33
- shipment_builder.add_access_request ENV['UPS_LICENSE_NUMBER'], ENV['UPS_USER_ID'], ENV['UPS_PASSWORD']
34
- shipment_builder.add_shipper shipper
35
- shipment_builder.add_ship_from shipper
36
- shipment_builder.add_ship_to ship_to
37
- shipment_builder.add_package package
38
- shipment_builder.add_payment_information ENV['UPS_ACCOUNT_NUMBER']
39
- shipment_builder.add_service '07'
36
+ subject do
37
+ server.ship do |shipment_builder|
38
+ shipment_builder.add_access_request ENV['UPS_LICENSE_NUMBER'], ENV['UPS_USER_ID'], ENV['UPS_PASSWORD']
39
+ shipment_builder.add_shipper shipper
40
+ shipment_builder.add_ship_from shipper
41
+ shipment_builder.add_ship_to ship_to
42
+ shipment_builder.add_package package
43
+ shipment_builder.add_payment_information ENV['UPS_ACCOUNT_NUMBER']
44
+ shipment_builder.add_service '07'
45
+ end
40
46
  end
41
- end
42
47
 
43
- it "should do what ever it takes to get that shipment shipped!" do
44
- subject.wont_equal false
45
- subject.success?.must_equal true
46
- end
48
+ it 'does what ever it takes to get that shipment shipped!' do
49
+ subject.wont_equal false
50
+ subject.success?.must_equal true
51
+ end
52
+
53
+ it 'returns the packages data' do
54
+ subject.packages.must_be_kind_of Array
55
+ subject.packages.size.must_equal 1
56
+ end
47
57
 
48
- it "should return the label data" do
49
- subject.label_graphic_image.must_be_kind_of File
50
- subject.label_html_image.must_be_kind_of File
51
- subject.label_graphic_extension.must_equal '.gif'
58
+ it 'returns the label data' do
59
+ subject.label_graphic_image.must_be_kind_of File
60
+ subject.label_graphic_image.path.end_with?('.gif').must_equal true
61
+ subject.label_graphic_extension.must_equal '.gif'
52
62
 
53
- subject.graphic_image.must_be_kind_of File
54
- subject.html_image.must_be_kind_of File
55
- subject.graphic_extension.must_equal '.gif'
56
- end
63
+ subject.graphic_image.must_be_kind_of File
64
+ subject.graphic_image.path.end_with?('.gif').must_equal true
65
+ subject.graphic_extension.must_equal '.gif'
66
+
67
+ subject.html_image.must_be_kind_of File
68
+ subject.html_image.path.end_with?('.gif').must_equal true
57
69
 
58
- it "should return the requested customs form data" do
59
- subject.form_graphic_image.must_be_kind_of File
60
- subject.form_graphic_extension.must_equal '.pdf'
70
+ subject.label_html_image.must_be_kind_of File
71
+ subject.label_html_image.path.end_with?('.gif').must_equal true
72
+ end
73
+
74
+ it 'should return the requested customs form data' do
75
+ subject.form_graphic_image.must_be_kind_of File
76
+ subject.form_graphic_image.path.end_with?('.pdf').must_equal true
77
+ subject.form_graphic_extension.must_equal '.pdf'
78
+ end
79
+
80
+ it 'should return the tracking number' do
81
+ subject.tracking_number.must_equal '1Z2220060292353829'
82
+ end
61
83
  end
62
84
 
63
- it "should return the tracking number" do
64
- subject.tracking_number.must_equal '1Z2220060292353829'
85
+ describe 'multi package shipment' do
86
+ before do
87
+ Excon.stub(method: :post) do |params|
88
+ case params[:path]
89
+ when UPS::Connection::SHIP_CONFIRM_PATH
90
+ {
91
+ body: File.read("#{stub_path}/multi_package/ship_confirm_success.xml"), status: 200
92
+ }
93
+ when UPS::Connection::SHIP_ACCEPT_PATH
94
+ {
95
+ body: File.read("#{stub_path}/multi_package/ship_accept_success.xml"), status: 200
96
+ }
97
+ end
98
+ end
99
+ end
100
+
101
+ let(:first_package) { subject.packages[0] }
102
+ let(:second_package) { subject.packages[1] }
103
+
104
+ subject do
105
+ server.ship do |shipment_builder|
106
+ shipment_builder.add_access_request ENV['UPS_LICENSE_NUMBER'], ENV['UPS_USER_ID'], ENV['UPS_PASSWORD']
107
+ shipment_builder.add_shipper shipper
108
+ shipment_builder.add_ship_from shipper
109
+ shipment_builder.add_ship_to ship_to
110
+ shipment_builder.add_package package
111
+ shipment_builder.add_package large_package
112
+ shipment_builder.add_payment_information ENV['UPS_ACCOUNT_NUMBER']
113
+ shipment_builder.add_service '07'
114
+ end
115
+ end
116
+
117
+ describe 'legacy methods for first package' do
118
+ it 'returns the label data for the first package' do
119
+ subject.label_graphic_image.must_be_kind_of File
120
+ subject.label_graphic_image.path.end_with?('.gif').must_equal true
121
+ subject.label_graphic_extension.must_equal '.gif'
122
+
123
+ subject.graphic_image.must_be_kind_of File
124
+ subject.graphic_image.path.end_with?('.gif').must_equal true
125
+ subject.graphic_extension.must_equal '.gif'
126
+
127
+ subject.html_image.must_be_kind_of File
128
+ subject.html_image.path.end_with?('.gif').must_equal true
129
+
130
+ subject.label_html_image.must_be_kind_of File
131
+ subject.label_html_image.path.end_with?('.gif').must_equal true
132
+ end
133
+
134
+ it 'returns the tracking number of the first package' do
135
+ subject.tracking_number.must_equal '1Z2R466A6894635437'
136
+ end
137
+ end
138
+
139
+ it 'returns the packages data' do
140
+ subject.packages.must_be_kind_of Array
141
+ subject.packages.size.must_equal 2
142
+ end
143
+
144
+ describe 'data per package' do
145
+ describe 'package #1' do
146
+ it 'returns the correct label data' do
147
+ first_package.label_graphic_image.must_be_kind_of File
148
+ first_package.label_graphic_image.path.end_with?('.gif').must_equal true
149
+ first_package.label_html_image.must_be_kind_of File
150
+ first_package.label_html_image.path.end_with?('.gif').must_equal true
151
+ first_package.label_graphic_extension.must_equal '.gif'
152
+ end
153
+
154
+ it 'returns the correct tracking number' do
155
+ first_package.tracking_number.must_equal '1Z2R466A6894635437'
156
+ end
157
+ end
158
+
159
+ describe 'package #2' do
160
+ it 'returns the correct label data' do
161
+ second_package.label_graphic_image.must_be_kind_of File
162
+ second_package.label_graphic_image.path.end_with?('.gif').must_equal true
163
+ second_package.label_html_image.must_be_kind_of File
164
+ second_package.label_html_image.path.end_with?('.gif').must_equal true
165
+ second_package.label_graphic_extension.must_equal '.gif'
166
+ end
167
+
168
+ it 'returns the correct tracking_number' do
169
+ second_package.tracking_number.must_equal '1Z2R466A6893005048'
170
+ end
171
+ end
172
+ end
65
173
  end
66
174
  end
67
175
 
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ups-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.11.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Veeqo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-23 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ox
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.2'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 2.2.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.2'
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: 2.2.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: excon
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +112,24 @@ files:
112
112
  - lib/ups/data/ie_county_prefixes.rb
113
113
  - lib/ups/data/us_states.rb
114
114
  - lib/ups/exceptions.rb
115
+ - lib/ups/models/package_result.rb
115
116
  - lib/ups/packaging.rb
116
- - lib/ups/parsers/parser_base.rb
117
+ - lib/ups/parsers/base_parser.rb
118
+ - lib/ups/parsers/rate_parser.rb
117
119
  - lib/ups/parsers/rates_parser.rb
118
120
  - lib/ups/parsers/ship_accept_parser.rb
119
121
  - lib/ups/parsers/ship_confirm_parser.rb
120
122
  - lib/ups/services.rb
123
+ - lib/ups/utils.rb
121
124
  - lib/ups/version.rb
122
125
  - spec/spec_helper.rb
126
+ - spec/stubs/multi_package/ship_accept_success.xml
127
+ - spec/stubs/multi_package/ship_confirm_success.xml
128
+ - spec/stubs/rates_error_multi_error.xml
129
+ - spec/stubs/rates_error_single_error.xml
123
130
  - spec/stubs/rates_negotiated_success.xml
124
131
  - spec/stubs/rates_success.xml
132
+ - spec/stubs/rates_success_single_rate.xml
125
133
  - spec/stubs/ship_accept_failure.xml
126
134
  - spec/stubs/ship_accept_success.xml
127
135
  - spec/stubs/ship_confirm_failure.xml
@@ -133,6 +141,7 @@ files:
133
141
  - spec/support/shipping_options.rb
134
142
  - spec/support/xsd_validator.rb
135
143
  - spec/ups/builders/address_builder_spec.rb
144
+ - spec/ups/builders/organisation_builder_spec.rb
136
145
  - spec/ups/builders/rate_builder_spec.rb
137
146
  - spec/ups/builders/ship_accept_builder_spec.rb
138
147
  - spec/ups/builders/ship_confirm_builder_spec.rb
@@ -160,8 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
169
  - !ruby/object:Gem::Version
161
170
  version: 1.3.6
162
171
  requirements: []
163
- rubyforge_project:
164
- rubygems_version: 2.6.14
172
+ rubygems_version: 3.0.6
165
173
  signing_key:
166
174
  specification_version: 4
167
175
  summary: UPS
@@ -1,52 +0,0 @@
1
- require 'uri'
2
- require 'ox'
3
-
4
- module UPS
5
- module Parsers
6
- class ParserBase < ::Ox::Sax
7
- attr_accessor :switches,
8
- :status_code,
9
- :status_description,
10
- :error_description
11
-
12
- def initialize
13
- self.switches = {}
14
- end
15
-
16
- def start_element(name)
17
- element_tracker_switch name, true
18
- end
19
-
20
- def end_element(name)
21
- element_tracker_switch name, false
22
- end
23
-
24
- def value(value)
25
- data = value.as_s
26
- self.status_code = data if switch_active? :ResponseStatusCode
27
-
28
- if switch_active?(:ResponseStatusDescription)
29
- self.status_description = data
30
- end
31
-
32
- self.error_description = data if switch_active? :ErrorDescription
33
- end
34
-
35
- def element_tracker_switch(element, currently_in)
36
- switches[element] = currently_in
37
- end
38
-
39
- def switch_active?(*elements)
40
- elements.flatten.all? { |element| switches[element] == true }
41
- end
42
-
43
- def build_switch_path(*paths)
44
- paths.flatten
45
- end
46
-
47
- def success?
48
- ['1', 1].include? status_code
49
- end
50
- end
51
- end
52
- end