friendly_shipping 0.10.1 → 0.10.2

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/README.md +16 -16
  4. data/lib/friendly_shipping/services/rl/parse_rate_quote_response.rb +3 -3
  5. data/lib/friendly_shipping/services/ups_json/parse_money_hash.rb +1 -0
  6. data/lib/friendly_shipping/services/usps_international/parse_rate_response.rb +3 -3
  7. data/lib/friendly_shipping/services/{usps → usps_international}/parse_xml_response.rb +1 -1
  8. data/lib/friendly_shipping/services/usps_international/serialize_rate_request.rb +1 -1
  9. data/lib/friendly_shipping/services/usps_ship/parse_rate_estimates_response.rb +1 -1
  10. data/lib/friendly_shipping/version.rb +1 -1
  11. metadata +3 -51
  12. data/lib/friendly_shipping/services/ups/label.rb +0 -20
  13. data/lib/friendly_shipping/services/ups/label_billing_options.rb +0 -41
  14. data/lib/friendly_shipping/services/ups/label_item_options.rb +0 -75
  15. data/lib/friendly_shipping/services/ups/label_options.rb +0 -174
  16. data/lib/friendly_shipping/services/ups/label_package_options.rb +0 -49
  17. data/lib/friendly_shipping/services/ups/parse_address_classification_response.rb +0 -29
  18. data/lib/friendly_shipping/services/ups/parse_address_validation_response.rb +0 -53
  19. data/lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb +0 -33
  20. data/lib/friendly_shipping/services/ups/parse_modifier_element.rb +0 -29
  21. data/lib/friendly_shipping/services/ups/parse_money_element.rb +0 -128
  22. data/lib/friendly_shipping/services/ups/parse_rate_response.rb +0 -101
  23. data/lib/friendly_shipping/services/ups/parse_shipment_accept_response.rb +0 -77
  24. data/lib/friendly_shipping/services/ups/parse_shipment_confirm_response.rb +0 -24
  25. data/lib/friendly_shipping/services/ups/parse_time_in_transit_response.rb +0 -56
  26. data/lib/friendly_shipping/services/ups/parse_void_shipment_response.rb +0 -24
  27. data/lib/friendly_shipping/services/ups/parse_xml_response.rb +0 -50
  28. data/lib/friendly_shipping/services/ups/rate_estimate_options.rb +0 -111
  29. data/lib/friendly_shipping/services/ups/rate_estimate_package_options.rb +0 -22
  30. data/lib/friendly_shipping/services/ups/serialize_access_request.rb +0 -20
  31. data/lib/friendly_shipping/services/ups/serialize_address_snippet.rb +0 -60
  32. data/lib/friendly_shipping/services/ups/serialize_address_validation_request.rb +0 -40
  33. data/lib/friendly_shipping/services/ups/serialize_city_state_lookup_request.rb +0 -26
  34. data/lib/friendly_shipping/services/ups/serialize_package_node.rb +0 -75
  35. data/lib/friendly_shipping/services/ups/serialize_rating_service_selection_request.rb +0 -98
  36. data/lib/friendly_shipping/services/ups/serialize_shipment_accept_request.rb +0 -27
  37. data/lib/friendly_shipping/services/ups/serialize_shipment_address_snippet.rb +0 -21
  38. data/lib/friendly_shipping/services/ups/serialize_shipment_confirm_request.rb +0 -285
  39. data/lib/friendly_shipping/services/ups/serialize_time_in_transit_request.rb +0 -56
  40. data/lib/friendly_shipping/services/ups/serialize_void_shipment_request.rb +0 -21
  41. data/lib/friendly_shipping/services/ups/shipping_methods.rb +0 -111
  42. data/lib/friendly_shipping/services/ups/timing_options.rb +0 -33
  43. data/lib/friendly_shipping/services/ups.rb +0 -218
  44. data/lib/friendly_shipping/services/usps/choose_package_rate.rb +0 -40
  45. data/lib/friendly_shipping/services/usps/machinable_package.rb +0 -50
  46. data/lib/friendly_shipping/services/usps/parse_address_validation_response.rb +0 -43
  47. data/lib/friendly_shipping/services/usps/parse_city_state_lookup_response.rb +0 -41
  48. data/lib/friendly_shipping/services/usps/parse_package_rate.rb +0 -159
  49. data/lib/friendly_shipping/services/usps/parse_rate_response.rb +0 -86
  50. data/lib/friendly_shipping/services/usps/parse_time_in_transit_response.rb +0 -240
  51. data/lib/friendly_shipping/services/usps/rate_estimate_options.rb +0 -26
  52. data/lib/friendly_shipping/services/usps/rate_estimate_package_options.rb +0 -66
  53. data/lib/friendly_shipping/services/usps/serialize_address_validation_request.rb +0 -25
  54. data/lib/friendly_shipping/services/usps/serialize_city_state_lookup_request.rb +0 -20
  55. data/lib/friendly_shipping/services/usps/serialize_rate_request.rb +0 -83
  56. data/lib/friendly_shipping/services/usps/serialize_time_in_transit_request.rb +0 -22
  57. data/lib/friendly_shipping/services/usps/shipping_methods.rb +0 -66
  58. data/lib/friendly_shipping/services/usps/timing_options.rb +0 -19
  59. data/lib/friendly_shipping/services/usps.rb +0 -115
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0aa01bc03e05cfdd6fa53432ea9d4692e53f9e71580432d15d485a8ad6213bfc
4
- data.tar.gz: 4917749e1c8a5955eceb4459af1dfa212a833840cfcec022bd89423554fb94d3
3
+ metadata.gz: d1947b72c921f913cd7e75eaf62c82e9453caa017eedd05f3bef555d202d28a9
4
+ data.tar.gz: 757e4ae6beaf55c89ad726ecf1c7b0609603b033908c7975ba47c436d059f306
5
5
  SHA512:
6
- metadata.gz: 3ad0ecca24a8fe1ce5017f5b17b16d1332fc80d89ab7ed1ea025bcb6a25ab59dcb175e4abbac6d676ff8224c437fc67fa18b1d29aeb9b120c32308d54551b9c9
7
- data.tar.gz: 8d662295fece385bf10bd2bcbb50ffcd18b1819b2c44e93625dfb42023af4fe4d0445ce84dd6110e49ca1c2c9152f83ff86c6aa7301399dd3d7b9479ff284944
6
+ metadata.gz: b0091e092439cb74e7d1f34d6342dedbcf15e8d6e451bea5782eda11129df3c94dcb224bb6a319ba859545f090899f0c51f8beb16dbd0de0a91078d57be5521d
7
+ data.tar.gz: 40d1c62b73125f662061e22c7100d9fa9aa0ec061b18b13066bc3f171e4b60c499ab57aecb77e1a79dc693849ba50fc3391e843bc7626dee6b5563f35039450c
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ group :development do
11
11
  gem "bundler", ">= 2.1.4", "< 3"
12
12
  gem "dotenv", "~> 3.0"
13
13
  gem "factory_bot", "~> 6.2"
14
+ gem "observer", "~> 0.1.2"
14
15
  gem "pry", "~> 0.12"
15
16
  gem "rack"
16
17
  gem "rake", ">= 12.3.3"
data/README.md CHANGED
@@ -22,8 +22,8 @@ Or install it yourself as:
22
22
 
23
23
  The entry point for using FriendlyShipping are the `service` objects that each represent an API provider. Currently, there are three services:
24
24
 
25
- 1. `FriendlyShipping::Services::Ups`
26
- 2. `FriendlyShipping::Services::Usps`
25
+ 1. `FriendlyShipping::Services::UpsJson`
26
+ 2. `FriendlyShipping::Services::USPSShip`
27
27
  3. `FriendlyShipping::Services::ShipEngine`
28
28
  4. `FriendlyShipping::Services::UpsFreight`
29
29
 
@@ -54,13 +54,11 @@ The following methods are supported:
54
54
 
55
55
  #### UPS (United Parcel Service)
56
56
 
57
- The service class for UPS is `FriendlyShipping::Services::Ups`. Initialize like so:
57
+ The service class for UPS is `FriendlyShipping::Services::UpsJson`. Initialize like so:
58
58
 
59
59
  ```rb
60
- service = FriendlyShipping::Services::Ups.new(
61
- key: ENV['UPS_API_KEY'],
62
- login: ENV['UPS_API_LOGIN'],
63
- password: ENV['UPS_API_PASSWORD'],
60
+ service = FriendlyShipping::Services::UpsJson.new(
61
+ access_token: ENV['UPS_ACCESS_TOKEN'],
64
62
  test: true
65
63
  )
66
64
  ```
@@ -68,19 +66,21 @@ service = FriendlyShipping::Services::Ups.new(
68
66
  The following methods are supported:
69
67
 
70
68
  - `#carriers` - List all configured carriers (always returns UPS)
71
- - `#rate_estimates(physical_shipment)` - Get rate estimates for a shipment
72
- - `#labels(physical_shipment, options: options)` - Get labels for a shipment
69
+ - `#create_access_token(client_id:, client_secret:, merchant_id:)` - Create a new API access token
70
+ - `#rates(physical_shipment, options:)` - Get rate estimates for a shipment
71
+ - `#timings(physical_shipment, options:)` - Get transit timings for a shipment
72
+ - `#labels(physical_shipment, options:)` - Get labels for a shipment
73
73
  - `#address_classification(physical_location)` - Determine whether an address is commercial or residential.
74
- - `#address_validation(physical_location)` - Perform a detailed address validation and determine whether an address is commercial or residential.
75
74
  - `#city_state_lookup(physical_location)` - Lookup City and State for a given ZIP code.
75
+ - `#void(label)` - Void a previously created label.
76
76
 
77
77
  #### USPS (United States Postal Service)
78
78
 
79
- The service class for USPS is `FriendlyShipping::Services::Usps`. Initialize like so:
79
+ The service class for USPS is `FriendlyShipping::Services::USPSShip`. Initialize like so:
80
80
 
81
81
  ```rb
82
- service = FriendlyShipping::Services::Usps.new(
83
- login: ENV['USPS_API_LOGIN'],
82
+ service = FriendlyShipping::Services::USPSShip.new(
83
+ access_token: ENV['USPS_ACCESS_TOKEN'],
84
84
  test: true
85
85
  )
86
86
  ```
@@ -88,9 +88,9 @@ service = FriendlyShipping::Services::Usps.new(
88
88
  The following methods are supported:
89
89
 
90
90
  - `#carriers` - List all configured carriers (always returns USPS)
91
- - `#rate_estimates(physical_shipment)` - Get rate estimates for a shipment
92
- - `#address_validation(physical_location)` - Perform a detailed address validation and determine whether an address is commercial or residential.
93
- - `#city_state_lookup(physical_location)` - Lookup City and State for a given ZIP code.
91
+ - `#create_access_token(client_id:, client_secret:)` - Create a new API access token
92
+ - `#rate_estimates(physical_shipment, options:)` - Get rate estimates for a shipment
93
+ - `#timings(physical_location, options:)` - Get transit timings for a shipment
94
94
 
95
95
  #### UPS Freight
96
96
 
@@ -34,10 +34,10 @@ module FriendlyShipping
34
34
  end
35
35
  end
36
36
 
37
- private
38
-
39
37
  # The currency to use when parsing the rate quotes.
40
- CURRENCY = Money::Currency.new('USD').freeze
38
+ CURRENCY = Money::Currency.new('USD')
39
+
40
+ private
41
41
 
42
42
  # Builds {Rate} instances from the parsed JSON.
43
43
  #
@@ -105,6 +105,7 @@ module FriendlyShipping
105
105
  "470" => "COMMITTED DELIVERY WINDOW",
106
106
  "480" => "SECURITY SURCHARGE",
107
107
  "492" => "CUSTOMER TRANSACTION FEE",
108
+ "495" => "EXTENDED AREA SURCHARGE",
108
109
  "500" => "SHIPMENT COD",
109
110
  "510" => "LIFT GATE FOR PICKUP",
110
111
  "511" => "LIFT GATE FOR DELIVERY",
@@ -16,7 +16,7 @@ module FriendlyShipping
16
16
  # @return [Result<ApiResult<Array<FriendlyShipping::Rate>>>] When successfully parsing, an array of rates in a Success Monad.
17
17
  def call(request:, response:, shipment:, options:)
18
18
  # Filter out error responses and directly return a failure
19
- parsing_result = FriendlyShipping::Services::Usps::ParseXMLResponse.call(
19
+ parsing_result = ParseXMLResponse.call(
20
20
  request: request,
21
21
  response: response,
22
22
  expected_root_tag: 'IntlRateV2Response'
@@ -51,11 +51,11 @@ module FriendlyShipping
51
51
  end
52
52
  end
53
53
 
54
- private
55
-
56
54
  PACKAGE_NODE_XPATH = '//Package'
57
55
  SERVICE_NODE_NAME = 'Service'
58
56
 
57
+ private
58
+
59
59
  # Iterate over all packages and parse the rates for each package
60
60
  #
61
61
  # @param [Nokogiri::XML::Node] xml The XML document containing packages and rates
@@ -2,7 +2,7 @@
2
2
 
3
3
  module FriendlyShipping
4
4
  module Services
5
- class Usps
5
+ class UspsInternational
6
6
  class ParseXMLResponse
7
7
  extend Dry::Monads::Result::Mixin
8
8
  ERROR_TAG = 'Error'
@@ -50,7 +50,7 @@ module FriendlyShipping
50
50
  private
51
51
 
52
52
  def machinable(package)
53
- FriendlyShipping::Services::Usps::MachinablePackage.new(package).machinable? ? 'true' : 'false'
53
+ FriendlyShipping::Services::USPSShip::MachinablePackage.new(package).machinable? ? 'true' : 'false'
54
54
  end
55
55
 
56
56
  def ounces_for(package)
@@ -35,7 +35,7 @@ module FriendlyShipping
35
35
 
36
36
  success(rates, request, response)
37
37
  rescue JSON::ParserError, KeyError => e
38
- failure(e.message, request, response)
38
+ failure(e, request, response)
39
39
  end
40
40
 
41
41
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FriendlyShipping
4
- VERSION = "0.10.1"
4
+ VERSION = "0.10.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_shipping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-01-03 00:00:00.000000000 Z
12
+ date: 2025-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-monads
@@ -230,38 +230,6 @@ files:
230
230
  - lib/friendly_shipping/services/tforce_freight/shipment_options.rb
231
231
  - lib/friendly_shipping/services/tforce_freight/shipping_methods.rb
232
232
  - lib/friendly_shipping/services/tforce_freight/structure_options.rb
233
- - lib/friendly_shipping/services/ups.rb
234
- - lib/friendly_shipping/services/ups/label.rb
235
- - lib/friendly_shipping/services/ups/label_billing_options.rb
236
- - lib/friendly_shipping/services/ups/label_item_options.rb
237
- - lib/friendly_shipping/services/ups/label_options.rb
238
- - lib/friendly_shipping/services/ups/label_package_options.rb
239
- - lib/friendly_shipping/services/ups/parse_address_classification_response.rb
240
- - lib/friendly_shipping/services/ups/parse_address_validation_response.rb
241
- - lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
242
- - lib/friendly_shipping/services/ups/parse_modifier_element.rb
243
- - lib/friendly_shipping/services/ups/parse_money_element.rb
244
- - lib/friendly_shipping/services/ups/parse_rate_response.rb
245
- - lib/friendly_shipping/services/ups/parse_shipment_accept_response.rb
246
- - lib/friendly_shipping/services/ups/parse_shipment_confirm_response.rb
247
- - lib/friendly_shipping/services/ups/parse_time_in_transit_response.rb
248
- - lib/friendly_shipping/services/ups/parse_void_shipment_response.rb
249
- - lib/friendly_shipping/services/ups/parse_xml_response.rb
250
- - lib/friendly_shipping/services/ups/rate_estimate_options.rb
251
- - lib/friendly_shipping/services/ups/rate_estimate_package_options.rb
252
- - lib/friendly_shipping/services/ups/serialize_access_request.rb
253
- - lib/friendly_shipping/services/ups/serialize_address_snippet.rb
254
- - lib/friendly_shipping/services/ups/serialize_address_validation_request.rb
255
- - lib/friendly_shipping/services/ups/serialize_city_state_lookup_request.rb
256
- - lib/friendly_shipping/services/ups/serialize_package_node.rb
257
- - lib/friendly_shipping/services/ups/serialize_rating_service_selection_request.rb
258
- - lib/friendly_shipping/services/ups/serialize_shipment_accept_request.rb
259
- - lib/friendly_shipping/services/ups/serialize_shipment_address_snippet.rb
260
- - lib/friendly_shipping/services/ups/serialize_shipment_confirm_request.rb
261
- - lib/friendly_shipping/services/ups/serialize_time_in_transit_request.rb
262
- - lib/friendly_shipping/services/ups/serialize_void_shipment_request.rb
263
- - lib/friendly_shipping/services/ups/shipping_methods.rb
264
- - lib/friendly_shipping/services/ups/timing_options.rb
265
233
  - lib/friendly_shipping/services/ups_freight.rb
266
234
  - lib/friendly_shipping/services/ups_freight/api_error.rb
267
235
  - lib/friendly_shipping/services/ups_freight/generate_commodity_information.rb
@@ -324,26 +292,10 @@ files:
324
292
  - lib/friendly_shipping/services/ups_json/rates_package_options.rb
325
293
  - lib/friendly_shipping/services/ups_json/shipping_methods.rb
326
294
  - lib/friendly_shipping/services/ups_json/timings_options.rb
327
- - lib/friendly_shipping/services/usps.rb
328
- - lib/friendly_shipping/services/usps/choose_package_rate.rb
329
- - lib/friendly_shipping/services/usps/machinable_package.rb
330
- - lib/friendly_shipping/services/usps/parse_address_validation_response.rb
331
- - lib/friendly_shipping/services/usps/parse_city_state_lookup_response.rb
332
- - lib/friendly_shipping/services/usps/parse_package_rate.rb
333
- - lib/friendly_shipping/services/usps/parse_rate_response.rb
334
- - lib/friendly_shipping/services/usps/parse_time_in_transit_response.rb
335
- - lib/friendly_shipping/services/usps/parse_xml_response.rb
336
- - lib/friendly_shipping/services/usps/rate_estimate_options.rb
337
- - lib/friendly_shipping/services/usps/rate_estimate_package_options.rb
338
- - lib/friendly_shipping/services/usps/serialize_address_validation_request.rb
339
- - lib/friendly_shipping/services/usps/serialize_city_state_lookup_request.rb
340
- - lib/friendly_shipping/services/usps/serialize_rate_request.rb
341
- - lib/friendly_shipping/services/usps/serialize_time_in_transit_request.rb
342
- - lib/friendly_shipping/services/usps/shipping_methods.rb
343
- - lib/friendly_shipping/services/usps/timing_options.rb
344
295
  - lib/friendly_shipping/services/usps_international.rb
345
296
  - lib/friendly_shipping/services/usps_international/parse_package_rate.rb
346
297
  - lib/friendly_shipping/services/usps_international/parse_rate_response.rb
298
+ - lib/friendly_shipping/services/usps_international/parse_xml_response.rb
347
299
  - lib/friendly_shipping/services/usps_international/rate_estimate_options.rb
348
300
  - lib/friendly_shipping/services/usps_international/rate_estimate_package_options.rb
349
301
  - lib/friendly_shipping/services/usps_international/serialize_rate_request.rb
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FriendlyShipping
4
- module Services
5
- class Ups
6
- class Label < FriendlyShipping::Label
7
- attr_reader :usps_tracking_number
8
-
9
- # @param [String] usps_tracking_number The label's usps tracking number. Limited to SUREPOST
10
- def initialize(
11
- usps_tracking_number: nil,
12
- **params
13
- )
14
- @usps_tracking_number = usps_tracking_number
15
- super(**params)
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FriendlyShipping
4
- module Services
5
- class Ups
6
- # Represents billing-related options for obtaining shipment labels.
7
- # @option bill_third_party [Boolean] When truthy, bill an account other than the shipper's.
8
- # Specified by billing_(account, zip and country)
9
- # @option bill_to_consignee [Boolean] If billing a third party, bill the consignee instead of the 3rd party shipper
10
- # @option prepay [Boolean] If truthy the shipper will be bill immediately. Otherwise the shipper is billed
11
- # when the label is used. Default: false
12
- class LabelBillingOptions
13
- attr_reader :bill_third_party,
14
- :bill_to_consignee,
15
- :prepay,
16
- :billing_account,
17
- :billing_zip,
18
- :billing_country,
19
- :currency
20
-
21
- def initialize(
22
- bill_third_party: false,
23
- bill_to_consignee: false,
24
- prepay: false,
25
- billing_account: nil,
26
- billing_zip: nil,
27
- billing_country: nil,
28
- currency: nil
29
- )
30
- @bill_third_party = bill_third_party
31
- @bill_to_consignee = bill_to_consignee
32
- @prepay = prepay
33
- @billing_account = billing_account
34
- @billing_zip = billing_zip
35
- @billing_country = billing_country
36
- @currency = currency
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FriendlyShipping
4
- module Services
5
- class Ups
6
- class LabelItemOptions < FriendlyShipping::ItemOptions
7
- PRODUCT_UNIT_OF_MEASURE_CODES = {
8
- barrel: 'BA',
9
- bundle: 'BE',
10
- bag: 'BG',
11
- bunch: 'BH',
12
- box: 'BOX',
13
- bolt: 'BT',
14
- butt: 'BU',
15
- canister: 'CI',
16
- centimeter: 'CM',
17
- container: 'CON',
18
- crate: 'CR',
19
- case: 'CS',
20
- carton: 'CT',
21
- cylinder: 'CY',
22
- dozen: 'DOZ',
23
- each: 'EA',
24
- envelope: 'EN',
25
- feet: 'FT',
26
- kilogram: 'KG',
27
- kilograms: 'KGS',
28
- pound: 'LB',
29
- pounds: 'LBS',
30
- liter: 'L',
31
- meter: 'M',
32
- number: 'NMB',
33
- packet: 'PA',
34
- pallet: 'PAL',
35
- piece: 'PC',
36
- pieces: 'PCS',
37
- proof_liters: 'PF',
38
- package: 'PKG',
39
- pair: 'PR',
40
- pairs: 'PRS',
41
- roll: 'RL',
42
- set: 'SET',
43
- square_meters: 'SME',
44
- square_yards: 'SYD',
45
- tube: 'TU',
46
- yard: 'YD',
47
- other: 'OTH'
48
- }.freeze
49
-
50
- attr_reader :commodity_code,
51
- :country_of_origin
52
-
53
- def initialize(
54
- commodity_code: nil,
55
- country_of_origin: nil,
56
- product_unit_of_measure: :number,
57
- **kwargs
58
- )
59
- @commodity_code = commodity_code
60
- @country_of_origin = country_of_origin
61
- @product_unit_of_measure = product_unit_of_measure
62
- super(**kwargs)
63
- end
64
-
65
- def product_unit_of_measure_code
66
- PRODUCT_UNIT_OF_MEASURE_CODES[product_unit_of_measure]
67
- end
68
-
69
- private
70
-
71
- attr_reader :product_unit_of_measure
72
- end
73
- end
74
- end
75
- end
@@ -1,174 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FriendlyShipping
4
- module Services
5
- # Option container for a generating UPS labels for a shipment
6
- #
7
- # Required:
8
- #
9
- # @param shipping_method [FriendlyShipping::ShippingMethod] The shipping method to use. We only need the
10
- # service_code to be set.
11
- # @param shipper_number [String] account number for the shipper
12
- #
13
- # Optional:
14
- #
15
- # @param shipper [Physical::Location] The company sending the shipment. Defaults to the shipment's origin.
16
- # @param sub_version [String] The UPS API sub-version to use for requests. Default: 1707
17
- # @param customer_context [String ] Optional element to identify transactions between client and server
18
- # @param validate_address [Boolean] Validate the city field with ZIP code and state. If false, only ZIP code
19
- # and state are validated. Default: true
20
- # @param negotiated_rates [Boolean] if truthy negotiated rates will be requested from ups. Only valid if
21
- # shipper account has negotiated rates. Default: false
22
- # @option sold_to [Physical::Location] The person or company who imports and pays any duties due on the
23
- # current shipment. Default: The shipment's destination
24
- # @option saturday_delivery [Boolean] should we request Saturday delivery?. Default: false
25
- # @option label_format [String] GIF, EPL, ZPL, STARPL and SPL
26
- # @option label_size [Array<Integer>] Dimensions of the label. Default: [4, 6]
27
- # @option delivery_confirmation [Symbol] Can be set to any key from SHIPMENT_DELIVERY_CONFIRMATION_CODES.
28
- # Only possible for international shipments that are not between the US and Puerto Rico.
29
- # @option carbon_neutral [Boolean] Ship with UPS' carbon neutral program
30
- # @option return_service_code [Symbol] If present, marks this a return label. The kind
31
- # of return label is specified by the symbol, one of the keys in RETURN_SERVICE_CODES. Default: nil
32
- #
33
- # Shipment options for international shipping:
34
- #
35
- # @option paperless_invoice [Boolean] set to truthy if using paperless invoice to ship internationally. Default false
36
- # @option terms_of_shipment [Symbol] used with paperless invoice to specify who pays duties and taxes.
37
- # See TERMS_OF_SHIPMENT constant for possible options.
38
- # @option reason_for_export [String] A reason to export the current shipment. Possible values: 'SALE', 'GIFT', 'SAMPLE',
39
- # 'RETURN', 'REPAIR', 'INTERCOMPANYDATA', Any other reason. Default: 'SALE'.
40
- # @option invoice_date [Date] The invoice date for the shipment
41
- # @param declaration_statement [String ] Optional element to add customs declaration text
42
- #
43
- class Ups
44
- class LabelOptions < FriendlyShipping::ShipmentOptions
45
- SHIPMENT_DELIVERY_CONFIRMATION_CODES = {
46
- delivery_confirmation_signature_required: 1,
47
- delivery_confirmation_adult_signature_required: 2
48
- }.freeze
49
-
50
- TERMS_OF_SHIPMENT_CODES = {
51
- cost_and_freight: 'CFR',
52
- cost_insurance_and_freight: 'CIF',
53
- carriage_and_insurance_paid: 'CIP',
54
- carriage_paid_to: 'CPT',
55
- delivered_at_frontier: 'DAF',
56
- delivery_duty_paid: 'DDP',
57
- delivery_duty_unpaid: 'DDU',
58
- delivered_ex_quay: 'DEQ',
59
- delivered_ex_ship: 'DES',
60
- ex_works: 'EXW',
61
- free_alongside_ship: 'FAS',
62
- free_carrier: 'FCA',
63
- free_on_board: 'FOB'
64
- }.freeze
65
-
66
- RETURN_SERVICE_CODES = {
67
- ups_print_and_mail: 2, # UPS Print and Mail (PNM)
68
- ups_return_1_attempt: 3, # UPS Return Service 1-Attempt
69
- ups_return_3_attempt: 5, # UPS Return Service 3-Attempt (RS3)
70
- ups_electronic_return_label: 8, # UPS Electronic Return Label (ERL)
71
- ups_print_return_label: 9, # UPS Print Return Label (PRL)
72
- ups_exchange_print_return: 10, # UPS Exchange Print Return Label
73
- ups_pack_collect_1_attemt_box_1: 11, # UPS Pack & Collect Service 1-Attempt Box 1
74
- ups_pack_collect_1_attemt_box_2: 12, # UPS Pack & Collect Service 1-Attempt Box 2
75
- ups_pack_collect_1_attemt_box_3: 13, # UPS Pack & Collect Service 1-Attempt Box 3
76
- ups_pack_collect_1_attemt_box_4: 14, # UPS Pack & Collect Service 1-Attempt Box 4
77
- ups_pack_collect_1_attemt_box_5: 15, # UPS Pack & Collect Service 1-Attempt Box 5
78
- ups_pack_collect_3_attemt_box_1: 16, # UPS Pack & Collect Service 1-Attempt Box 1
79
- ups_pack_collect_3_attemt_box_2: 17, # UPS Pack & Collect Service 1-Attempt Box 2
80
- ups_pack_collect_3_attemt_box_3: 18, # UPS Pack & Collect Service 1-Attempt Box 3
81
- ups_pack_collect_3_attemt_box_4: 19, # UPS Pack & Collect Service 1-Attempt Box 4
82
- ups_pack_collect_3_attemt_box_5: 20 # UPS Pack & Collect Service 1-Attempt Box 5
83
- }.freeze
84
-
85
- SUB_VERSIONS = %w[1601 1607 1701 1707 1801 1807 2108 2205].freeze
86
-
87
- attr_reader :shipping_method,
88
- :shipper_number,
89
- :shipper,
90
- :sub_version,
91
- :customer_context,
92
- :validate_address,
93
- :negotiated_rates,
94
- :billing_options,
95
- :sold_to,
96
- :saturday_delivery,
97
- :label_format,
98
- :label_size,
99
- :carbon_neutral,
100
- :paperless_invoice,
101
- :reason_for_export,
102
- :invoice_date,
103
- :declaration_statement
104
-
105
- def initialize(
106
- shipping_method:,
107
- shipper_number:,
108
- shipper: nil,
109
- sub_version: '1707',
110
- customer_context: nil,
111
- validate_address: true,
112
- negotiated_rates: false,
113
- billing_options: LabelBillingOptions.new,
114
- sold_to: nil,
115
- saturday_delivery: false,
116
- label_format: 'GIF',
117
- label_size: [4, 6],
118
- delivery_confirmation: nil,
119
- carbon_neutral: true,
120
- return_service: nil,
121
- paperless_invoice: false,
122
- terms_of_shipment: nil,
123
- reason_for_export: 'SALE',
124
- invoice_date: nil,
125
- package_options_class: LabelPackageOptions,
126
- declaration_statement: nil,
127
- **kwargs
128
- )
129
- raise ArgumentError, "Invalid sub-version: #{sub_version}" unless sub_version.in?(SUB_VERSIONS)
130
-
131
- @shipping_method = shipping_method
132
- @shipper_number = shipper_number
133
- @shipper = shipper
134
- @sub_version = sub_version
135
- @customer_context = customer_context
136
- @validate_address = validate_address
137
- @negotiated_rates = negotiated_rates
138
- @billing_options = billing_options
139
- @sold_to = sold_to
140
- @saturday_delivery = saturday_delivery
141
- @label_format = label_format
142
- @label_size = label_size
143
- @delivery_confirmation = delivery_confirmation
144
- @carbon_neutral = carbon_neutral
145
- @return_service = return_service
146
- @paperless_invoice = paperless_invoice
147
- @terms_of_shipment = terms_of_shipment
148
- @reason_for_export = reason_for_export
149
- @invoice_date = invoice_date
150
- @declaration_statement = declaration_statement
151
- super(**kwargs.reverse_merge(package_options_class: package_options_class))
152
- end
153
-
154
- def delivery_confirmation_code
155
- SHIPMENT_DELIVERY_CONFIRMATION_CODES[delivery_confirmation]
156
- end
157
-
158
- def terms_of_shipment_code
159
- TERMS_OF_SHIPMENT_CODES[terms_of_shipment]
160
- end
161
-
162
- def return_service_code
163
- RETURN_SERVICE_CODES[return_service]
164
- end
165
-
166
- private
167
-
168
- attr_reader :terms_of_shipment,
169
- :return_service,
170
- :delivery_confirmation
171
- end
172
- end
173
- end
174
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FriendlyShipping
4
- module Services
5
- class Ups
6
- # Package properties relevant for generating a UPS shipping label
7
- #
8
- # @option reference_numbers [Hash] a Hash where keys are _reference number codes_ and
9
- # values are _reference number values_. Example: `{ reference_numbers: { xn: 'my_reference_1 }`
10
- # @option delivery_confirmation [Symbol] Can be set to any key from PACKAGE_DELIVERY_CONFIRMATION_CODES.
11
- # Only possible for domestic shipments or shipments between the US and Puerto Rico.
12
- # @option shipper_release [Boolean] Indicates that the package may be released by driver without a signature from
13
- # the consignee. Default: false
14
- # @option declared_value [Boolean] When true, declared value (calculated as the sum of all items in the shipment)
15
- # will be included in the request. Default: false
16
- class LabelPackageOptions < FriendlyShipping::PackageOptions
17
- PACKAGE_DELIVERY_CONFIRMATION_CODES = {
18
- delivery_confirmation: 1,
19
- delivery_confirmation_signature_required: 2,
20
- delivery_confirmation_adult_signature_required: 3
21
- }.freeze
22
-
23
- attr_reader :reference_numbers, :shipper_release, :declared_value
24
-
25
- def initialize(
26
- reference_numbers: {},
27
- delivery_confirmation: nil,
28
- shipper_release: false,
29
- declared_value: false,
30
- **kwargs
31
- )
32
- @reference_numbers = reference_numbers
33
- @delivery_confirmation = delivery_confirmation
34
- @shipper_release = shipper_release
35
- @declared_value = declared_value
36
- super(**kwargs.reverse_merge(item_options_class: LabelItemOptions))
37
- end
38
-
39
- def delivery_confirmation_code
40
- PACKAGE_DELIVERY_CONFIRMATION_CODES[delivery_confirmation]
41
- end
42
-
43
- private
44
-
45
- attr_reader :delivery_confirmation
46
- end
47
- end
48
- end
49
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FriendlyShipping
4
- module Services
5
- class Ups
6
- class ParseAddressClassificationResponse
7
- extend Dry::Monads::Result::Mixin
8
-
9
- def self.call(request:, response:)
10
- parsing_result = ParseXMLResponse.call(
11
- request: request,
12
- response: response,
13
- expected_root_tag: 'AddressValidationResponse'
14
- )
15
- parsing_result.bind do |xml|
16
- address_type = xml.at('AddressClassification/Description')&.text&.downcase
17
- Success(
18
- FriendlyShipping::ApiResult.new(
19
- address_type,
20
- original_request: request,
21
- original_response: response
22
- )
23
- )
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end