ups-ruby 0.14.1 → 0.23.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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -4
  3. data/lib/ups/builders/builder_base.rb +38 -24
  4. data/lib/ups/builders/international_invoice_builder.rb +12 -2
  5. data/lib/ups/builders/organisation_builder.rb +22 -0
  6. data/lib/ups/builders/package_builder.rb +69 -0
  7. data/lib/ups/builders/ship_confirm_builder.rb +40 -1
  8. data/lib/ups/builders/track_builder.rb +37 -0
  9. data/lib/ups/connection.rb +22 -0
  10. data/lib/ups/parsers/ship_accept_parser.rb +26 -0
  11. data/lib/ups/parsers/track_parser.rb +51 -0
  12. data/lib/ups/version.rb +2 -2
  13. data/lib/ups.rb +3 -0
  14. data/spec/stubs/rates_success_with_packaging_type.xml +187 -0
  15. data/spec/stubs/rates_success_with_packaging_type_and_dimensions.xml +185 -0
  16. data/spec/stubs/ship_accept_success_with_packaging_type.xml +69 -0
  17. data/spec/stubs/ship_accept_success_without_negotiated_price.xml +59 -0
  18. data/spec/stubs/ship_confirm_success_with_packaging_type.xml +33 -0
  19. data/spec/stubs/track_success.xml +105 -0
  20. data/spec/support/AccessRequest.xsd +12 -0
  21. data/spec/support/IF.xsd +352 -0
  22. data/spec/support/RateRequest.xsd +454 -1
  23. data/spec/support/ShipAcceptRequest.xsd +4 -15
  24. data/spec/support/ShipConfirmRequest.xsd +99 -367
  25. data/spec/support/shipping_options.rb +42 -0
  26. data/spec/support/xsd_validator.rb +1 -1
  27. data/spec/ups/builders/organisation_builder_spec.rb +51 -0
  28. data/spec/ups/builders/rate_builder_spec.rb +1 -0
  29. data/spec/ups/builders/ship_confirm_builder_spec.rb +2 -0
  30. data/spec/ups/connection/rates_standard_spec.rb +94 -1
  31. data/spec/ups/connection/ship_spec.rb +55 -1
  32. data/spec/ups/connection/track_spec.rb +47 -0
  33. metadata +15 -3
@@ -0,0 +1,51 @@
1
+ require 'uri'
2
+ require 'ox'
3
+
4
+ module UPS
5
+ module Parsers
6
+ class TrackParser < BaseParser
7
+ def initialize(response)
8
+ # Unescape double/triple quoted first line: "<?xml version=\\\"1.0\\\"?>\\n<TrackResponse>\n"
9
+ super(response.gsub(/\\"/, '"').gsub(/\\n/, "\n"))
10
+ end
11
+
12
+ def to_h
13
+ {
14
+ status_date: status_date,
15
+ status_type_description: status_type_description,
16
+ status_type_code: status_type_code
17
+ }
18
+ end
19
+
20
+ def activities
21
+ normalize_response_into_array(root_response[:Shipment][:Package][:Activity])
22
+ end
23
+
24
+ def status_date
25
+ Date.parse(latest_activity[:Date])
26
+ end
27
+
28
+ def status_type_description
29
+ status_type[:Description]
30
+ end
31
+
32
+ def status_type_code
33
+ status_type[:Code]
34
+ end
35
+
36
+ private
37
+
38
+ def status_type
39
+ latest_activity[:Status][:StatusType]
40
+ end
41
+
42
+ def latest_activity
43
+ activities.sort_by {|a| [a[:GMTDate], a[:GMTTime]] }.last
44
+ end
45
+
46
+ def root_response
47
+ parsed_response[:TrackResponse]
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/ups/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module UPS
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 14
5
- PATCH = 1
4
+ MINOR = 23
5
+ PATCH = 0
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
data/lib/ups.rb CHANGED
@@ -27,6 +27,7 @@ module UPS
27
27
  autoload :RateParser, 'ups/parsers/rate_parser'
28
28
  autoload :ShipConfirmParser, 'ups/parsers/ship_confirm_parser'
29
29
  autoload :ShipAcceptParser, 'ups/parsers/ship_accept_parser'
30
+ autoload :TrackParser, 'ups/parsers/track_parser'
30
31
  end
31
32
 
32
33
  module Builders
@@ -38,6 +39,8 @@ module UPS
38
39
  autoload :InternationalInvoiceProductBuilder, 'ups/builders/international_invoice_product_builder'
39
40
  autoload :ShipAcceptBuilder, 'ups/builders/ship_accept_builder'
40
41
  autoload :OrganisationBuilder, 'ups/builders/organisation_builder'
42
+ autoload :PackageBuilder, 'ups/builders/package_builder'
41
43
  autoload :ShipperBuilder, 'ups/builders/shipper_builder'
44
+ autoload :TrackBuilder, 'ups/builders/track_builder'
42
45
  end
43
46
  end
@@ -0,0 +1,187 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <RatingServiceSelectionResponse>
3
+ <Response>
4
+ <ResponseStatusCode>1</ResponseStatusCode>
5
+ <ResponseStatusDescription>Success</ResponseStatusDescription>
6
+ </Response>
7
+ <RatedShipment>
8
+ <Service>
9
+ <Code>07</Code>
10
+ </Service>
11
+ <RatedShipmentWarning>
12
+ The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight.
13
+ </RatedShipmentWarning>
14
+ <RatedShipmentWarning>
15
+ Your invoice may vary from the displayed reference rates
16
+ </RatedShipmentWarning>
17
+ <BillingWeight>
18
+ <UnitOfMeasurement>
19
+ <Code>KGS</Code>
20
+ </UnitOfMeasurement>
21
+ <Weight>8.0</Weight>
22
+ </BillingWeight>
23
+ <TransportationCharges>
24
+ <CurrencyCode>GBP</CurrencyCode>
25
+ <MonetaryValue>172.77</MonetaryValue>
26
+ </TransportationCharges>
27
+ <ServiceOptionsCharges>
28
+ <CurrencyCode>GBP</CurrencyCode>
29
+ <MonetaryValue>0.00</MonetaryValue>
30
+ </ServiceOptionsCharges>
31
+ <TotalCharges>
32
+ <CurrencyCode>GBP</CurrencyCode>
33
+ <MonetaryValue>172.77</MonetaryValue>
34
+ </TotalCharges>
35
+ <GuaranteedDaysToDelivery/>
36
+ <ScheduledDeliveryTime/>
37
+ <RatedPackage>
38
+ <TransportationCharges>
39
+ <CurrencyCode/>
40
+ <MonetaryValue/>
41
+ </TransportationCharges>
42
+ <ServiceOptionsCharges>
43
+ <CurrencyCode/>
44
+ <MonetaryValue/>
45
+ </ServiceOptionsCharges>
46
+ <TotalCharges>
47
+ <CurrencyCode/>
48
+ <MonetaryValue/>
49
+ </TotalCharges>
50
+ <Weight>8.0</Weight>
51
+ <BillingWeight>
52
+ <UnitOfMeasurement>
53
+ <Code/>
54
+ </UnitOfMeasurement>
55
+ <Weight/>
56
+ </BillingWeight>
57
+ </RatedPackage>
58
+ <NegotiatedRates>
59
+ <NetSummaryCharges>
60
+ <GrandTotal>
61
+ <CurrencyCode>GBP</CurrencyCode>
62
+ <MonetaryValue>171.04</MonetaryValue>
63
+ </GrandTotal>
64
+ </NetSummaryCharges>
65
+ </NegotiatedRates>
66
+ </RatedShipment>
67
+ <RatedShipment>
68
+ <Service>
69
+ <Code>65</Code>
70
+ </Service>
71
+ <RatedShipmentWarning>
72
+ The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight.
73
+ </RatedShipmentWarning>
74
+ <RatedShipmentWarning>
75
+ Your invoice may vary from the displayed reference rates
76
+ </RatedShipmentWarning>
77
+ <BillingWeight>
78
+ <UnitOfMeasurement>
79
+ <Code>KGS</Code>
80
+ </UnitOfMeasurement>
81
+ <Weight>8.0</Weight>
82
+ </BillingWeight>
83
+ <TransportationCharges>
84
+ <CurrencyCode>GBP</CurrencyCode>
85
+ <MonetaryValue>162.38</MonetaryValue>
86
+ </TransportationCharges>
87
+ <ServiceOptionsCharges>
88
+ <CurrencyCode>GBP</CurrencyCode>
89
+ <MonetaryValue>0.00</MonetaryValue>
90
+ </ServiceOptionsCharges>
91
+ <TotalCharges>
92
+ <CurrencyCode>GBP</CurrencyCode>
93
+ <MonetaryValue>162.38</MonetaryValue>
94
+ </TotalCharges>
95
+ <GuaranteedDaysToDelivery/>
96
+ <ScheduledDeliveryTime/>
97
+ <RatedPackage>
98
+ <TransportationCharges>
99
+ <CurrencyCode/>
100
+ <MonetaryValue/>
101
+ </TransportationCharges>
102
+ <ServiceOptionsCharges>
103
+ <CurrencyCode/>
104
+ <MonetaryValue/>
105
+ </ServiceOptionsCharges>
106
+ <TotalCharges>
107
+ <CurrencyCode/>
108
+ <MonetaryValue/>
109
+ </TotalCharges>
110
+ <Weight>8.0</Weight>
111
+ <BillingWeight>
112
+ <UnitOfMeasurement>
113
+ <Code/>
114
+ </UnitOfMeasurement>
115
+ <Weight/>
116
+ </BillingWeight>
117
+ </RatedPackage>
118
+ <NegotiatedRates>
119
+ <NetSummaryCharges>
120
+ <GrandTotal>
121
+ <CurrencyCode>GBP</CurrencyCode>
122
+ <MonetaryValue>160.76</MonetaryValue>
123
+ </GrandTotal>
124
+ </NetSummaryCharges>
125
+ </NegotiatedRates>
126
+ </RatedShipment>
127
+ <RatedShipment>
128
+ <Service>
129
+ <Code>54</Code>
130
+ </Service>
131
+ <RatedShipmentWarning>
132
+ The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight.
133
+ </RatedShipmentWarning>
134
+ <RatedShipmentWarning>
135
+ Your invoice may vary from the displayed reference rates
136
+ </RatedShipmentWarning>
137
+ <BillingWeight>
138
+ <UnitOfMeasurement>
139
+ <Code>KGS</Code>
140
+ </UnitOfMeasurement>
141
+ <Weight>8.0</Weight>
142
+ </BillingWeight>
143
+ <TransportationCharges>
144
+ <CurrencyCode>GBP</CurrencyCode>
145
+ <MonetaryValue>229.18</MonetaryValue>
146
+ </TransportationCharges>
147
+ <ServiceOptionsCharges>
148
+ <CurrencyCode>GBP</CurrencyCode>
149
+ <MonetaryValue>0.00</MonetaryValue>
150
+ </ServiceOptionsCharges>
151
+ <TotalCharges>
152
+ <CurrencyCode>GBP</CurrencyCode>
153
+ <MonetaryValue>229.18</MonetaryValue>
154
+ </TotalCharges>
155
+ <GuaranteedDaysToDelivery/>
156
+ <ScheduledDeliveryTime/>
157
+ <RatedPackage>
158
+ <TransportationCharges>
159
+ <CurrencyCode/>
160
+ <MonetaryValue/>
161
+ </TransportationCharges>
162
+ <ServiceOptionsCharges>
163
+ <CurrencyCode/>
164
+ <MonetaryValue/>
165
+ </ServiceOptionsCharges>
166
+ <TotalCharges>
167
+ <CurrencyCode/>
168
+ <MonetaryValue/>
169
+ </TotalCharges>
170
+ <Weight>8.0</Weight>
171
+ <BillingWeight>
172
+ <UnitOfMeasurement>
173
+ <Code/>
174
+ </UnitOfMeasurement>
175
+ <Weight/>
176
+ </BillingWeight>
177
+ </RatedPackage>
178
+ <NegotiatedRates>
179
+ <NetSummaryCharges>
180
+ <GrandTotal>
181
+ <CurrencyCode>GBP</CurrencyCode>
182
+ <MonetaryValue>226.89</MonetaryValue>
183
+ </GrandTotal>
184
+ </NetSummaryCharges>
185
+ </NegotiatedRates>
186
+ </RatedShipment>
187
+ </RatingServiceSelectionResponse>
@@ -0,0 +1,185 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <RatingServiceSelectionResponse>
3
+ <Response>
4
+ <ResponseStatusCode>1</ResponseStatusCode>
5
+ <ResponseStatusDescription>Success</ResponseStatusDescription>
6
+ </Response>
7
+ <RatedShipment>
8
+ <Service>
9
+ <Code>07</Code>
10
+ </Service>
11
+ <RatedShipmentWarning>
12
+ The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight.
13
+ </RatedShipmentWarning>
14
+ <RatedShipmentWarning>
15
+ Your invoice may vary from the displayed reference rates
16
+ </RatedShipmentWarning>
17
+ <BillingWeight>
18
+ <UnitOfMeasurement>
19
+ <Code>KGS</Code>
20
+ </UnitOfMeasurement>
21
+ <Weight>8.0</Weight>
22
+ </BillingWeight>
23
+ <TransportationCharges>
24
+ <CurrencyCode>GBP</CurrencyCode>
25
+ <MonetaryValue>171.99</MonetaryValue>
26
+ </TransportationCharges>
27
+ <ServiceOptionsCharges>
28
+ <CurrencyCode>GBP</CurrencyCode>
29
+ <MonetaryValue>0.00</MonetaryValue>
30
+ </ServiceOptionsCharges>
31
+ <TotalCharges>
32
+ <CurrencyCode>GBP</CurrencyCode>
33
+ <MonetaryValue>171.99</MonetaryValue>
34
+ </TotalCharges><GuaranteedDaysToDelivery/>
35
+ <ScheduledDeliveryTime/>
36
+ <RatedPackage>
37
+ <TransportationCharges>
38
+ <CurrencyCode/>
39
+ <MonetaryValue/>
40
+ </TransportationCharges>
41
+ <ServiceOptionsCharges>
42
+ <CurrencyCode/>
43
+ <MonetaryValue/>
44
+ </ServiceOptionsCharges>
45
+ <TotalCharges>
46
+ <CurrencyCode/>
47
+ <MonetaryValue/>
48
+ </TotalCharges>
49
+ <Weight>8.0</Weight>
50
+ <BillingWeight>
51
+ <UnitOfMeasurement>
52
+ <Code/>
53
+ </UnitOfMeasurement>
54
+ <Weight/>
55
+ </BillingWeight>
56
+ </RatedPackage>
57
+ <NegotiatedRates>
58
+ <NetSummaryCharges>
59
+ <GrandTotal>
60
+ <CurrencyCode>GBP</CurrencyCode>
61
+ <MonetaryValue>170.27</MonetaryValue>
62
+ </GrandTotal>
63
+ </NetSummaryCharges>
64
+ </NegotiatedRates>
65
+ </RatedShipment>
66
+ <RatedShipment>
67
+ <Service>
68
+ <Code>65</Code>
69
+ </Service>
70
+ <RatedShipmentWarning>
71
+ The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight.
72
+ </RatedShipmentWarning>
73
+ <RatedShipmentWarning>
74
+ Your invoice may vary from the displayed reference rates
75
+ </RatedShipmentWarning>
76
+ <BillingWeight>
77
+ <UnitOfMeasurement>
78
+ <Code>KGS</Code>
79
+ </UnitOfMeasurement>
80
+ <Weight>8.0</Weight>
81
+ </BillingWeight>
82
+ <TransportationCharges>
83
+ <CurrencyCode>GBP</CurrencyCode>
84
+ <MonetaryValue>162.38</MonetaryValue>
85
+ </TransportationCharges>
86
+ <ServiceOptionsCharges>
87
+ <CurrencyCode>GBP</CurrencyCode>
88
+ <MonetaryValue>0.00</MonetaryValue>
89
+ </ServiceOptionsCharges>
90
+ <TotalCharges>
91
+ <CurrencyCode>GBP</CurrencyCode>
92
+ <MonetaryValue>162.38</MonetaryValue>
93
+ </TotalCharges>
94
+ <GuaranteedDaysToDelivery/>
95
+ <ScheduledDeliveryTime/>
96
+ <RatedPackage>
97
+ <TransportationCharges>
98
+ <CurrencyCode/>
99
+ <MonetaryValue/>
100
+ </TransportationCharges>
101
+ <ServiceOptionsCharges>
102
+ <CurrencyCode/>
103
+ <MonetaryValue/>
104
+ </ServiceOptionsCharges>
105
+ <TotalCharges>
106
+ <CurrencyCode/>
107
+ <MonetaryValue/>
108
+ </TotalCharges>
109
+ <Weight>8.0</Weight>
110
+ <BillingWeight>
111
+ <UnitOfMeasurement>
112
+ <Code/>
113
+ </UnitOfMeasurement>
114
+ <Weight/>
115
+ </BillingWeight>
116
+ </RatedPackage>
117
+ <NegotiatedRates>
118
+ <NetSummaryCharges>
119
+ <GrandTotal>
120
+ <CurrencyCode>GBP</CurrencyCode>
121
+ <MonetaryValue>160.76</MonetaryValue>
122
+ </GrandTotal>
123
+ </NetSummaryCharges>
124
+ </NegotiatedRates>
125
+ </RatedShipment>
126
+ <RatedShipment>
127
+ <Service>
128
+ <Code>54</Code>
129
+ </Service>
130
+ <RatedShipmentWarning>
131
+ The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight.
132
+ </RatedShipmentWarning>
133
+ <RatedShipmentWarning>
134
+ Your invoice may vary from the displayed reference rates
135
+ </RatedShipmentWarning>
136
+ <BillingWeight>
137
+ <UnitOfMeasurement>
138
+ <Code>KGS</Code>
139
+ </UnitOfMeasurement>
140
+ <Weight>8.0</Weight>
141
+ </BillingWeight>
142
+ <TransportationCharges>
143
+ <CurrencyCode>GBP</CurrencyCode>
144
+ <MonetaryValue>229.18</MonetaryValue>
145
+ </TransportationCharges>
146
+ <ServiceOptionsCharges>
147
+ <CurrencyCode>GBP</CurrencyCode>
148
+ <MonetaryValue>0.00</MonetaryValue>
149
+ </ServiceOptionsCharges>
150
+ <TotalCharges>
151
+ <CurrencyCode>GBP</CurrencyCode>
152
+ <MonetaryValue>229.18</MonetaryValue>
153
+ </TotalCharges><GuaranteedDaysToDelivery/>
154
+ <ScheduledDeliveryTime/>
155
+ <RatedPackage>
156
+ <TransportationCharges>
157
+ <CurrencyCode/>
158
+ <MonetaryValue/>
159
+ </TransportationCharges>
160
+ <ServiceOptionsCharges>
161
+ <CurrencyCode/>
162
+ <MonetaryValue/>
163
+ </ServiceOptionsCharges>
164
+ <TotalCharges>
165
+ <CurrencyCode/>
166
+ <MonetaryValue/>
167
+ </TotalCharges>
168
+ <Weight>8.0</Weight>
169
+ <BillingWeight>
170
+ <UnitOfMeasurement>
171
+ <Code/>
172
+ </UnitOfMeasurement>
173
+ <Weight/>
174
+ </BillingWeight>
175
+ </RatedPackage>
176
+ <NegotiatedRates>
177
+ <NetSummaryCharges>
178
+ <GrandTotal>
179
+ <CurrencyCode>GBP</CurrencyCode>
180
+ <MonetaryValue>226.89</MonetaryValue>
181
+ </GrandTotal>
182
+ </NetSummaryCharges>
183
+ </NegotiatedRates>
184
+ </RatedShipment>
185
+ </RatingServiceSelectionResponse>