friendly_shipping 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.env.template +1 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +13 -4
  5. data/Gemfile +1 -0
  6. data/README.md +21 -2
  7. data/friendly_shipping.gemspec +1 -1
  8. data/lib/friendly_shipping/api_failure.rb +3 -0
  9. data/lib/friendly_shipping/api_result.rb +3 -0
  10. data/lib/friendly_shipping/carrier.rb +6 -0
  11. data/lib/friendly_shipping/http_client.rb +1 -0
  12. data/lib/friendly_shipping/item_options.rb +11 -0
  13. data/lib/friendly_shipping/label.rb +17 -9
  14. data/lib/friendly_shipping/package_options.rb +28 -0
  15. data/lib/friendly_shipping/rate.rb +9 -8
  16. data/lib/friendly_shipping/request.rb +4 -0
  17. data/lib/friendly_shipping/response.rb +3 -0
  18. data/lib/friendly_shipping/services/ship_engine.rb +10 -11
  19. data/lib/friendly_shipping/services/ship_engine/label_options.rb +34 -0
  20. data/lib/friendly_shipping/services/ship_engine/label_package_options.rb +28 -0
  21. data/lib/friendly_shipping/services/ship_engine/parse_label_response.rb +6 -1
  22. data/lib/friendly_shipping/services/ship_engine/parse_rate_estimate_response.rb +7 -7
  23. data/lib/friendly_shipping/services/ship_engine/rate_estimates_options.rb +25 -0
  24. data/lib/friendly_shipping/services/ship_engine/serialize_label_shipment.rb +15 -14
  25. data/lib/friendly_shipping/services/ship_engine/serialize_rate_estimate_request.rb +2 -2
  26. data/lib/friendly_shipping/services/ups.rb +47 -2
  27. data/lib/friendly_shipping/services/ups/label_billing_options.rb +41 -0
  28. data/lib/friendly_shipping/services/ups/label_item_options.rb +74 -0
  29. data/lib/friendly_shipping/services/ups/label_options.rb +165 -0
  30. data/lib/friendly_shipping/services/ups/label_package_options.rb +43 -0
  31. data/lib/friendly_shipping/services/ups/parse_money_element.rb +128 -0
  32. data/lib/friendly_shipping/services/ups/parse_rate_response.rb +8 -7
  33. data/lib/friendly_shipping/services/ups/parse_shipment_accept_response.rb +75 -0
  34. data/lib/friendly_shipping/services/ups/parse_shipment_confirm_response.rb +22 -0
  35. data/lib/friendly_shipping/services/ups/parse_xml_response.rb +2 -1
  36. data/lib/friendly_shipping/services/ups/serialize_address_snippet.rb +11 -6
  37. data/lib/friendly_shipping/services/ups/serialize_package_node.rb +21 -6
  38. data/lib/friendly_shipping/services/ups/serialize_shipment_accept_request.rb +27 -0
  39. data/lib/friendly_shipping/services/ups/serialize_shipment_address_snippet.rb +21 -0
  40. data/lib/friendly_shipping/services/ups/serialize_shipment_confirm_request.rb +282 -0
  41. data/lib/friendly_shipping/services/ups_freight.rb +76 -0
  42. data/lib/friendly_shipping/services/ups_freight/generate_commodity_information.rb +33 -0
  43. data/lib/friendly_shipping/services/ups_freight/generate_freight_rate_request_hash.rb +72 -0
  44. data/lib/friendly_shipping/services/ups_freight/generate_location_hash.rb +39 -0
  45. data/lib/friendly_shipping/services/ups_freight/generate_ups_security_hash.rb +23 -0
  46. data/lib/friendly_shipping/services/ups_freight/parse_freight_rate_response.rb +53 -0
  47. data/lib/friendly_shipping/services/ups_freight/parse_json_response.rb +38 -0
  48. data/lib/friendly_shipping/services/ups_freight/rates_item_options.rb +72 -0
  49. data/lib/friendly_shipping/services/ups_freight/rates_options.rb +54 -0
  50. data/lib/friendly_shipping/services/ups_freight/rates_package_options.rb +38 -0
  51. data/lib/friendly_shipping/services/ups_freight/shipping_methods.rb +25 -0
  52. data/lib/friendly_shipping/services/usps.rb +1 -1
  53. data/lib/friendly_shipping/services/usps/parse_xml_response.rb +1 -1
  54. data/lib/friendly_shipping/services/usps/serialize_rate_request.rb +0 -4
  55. data/lib/friendly_shipping/shipment_options.rb +23 -0
  56. data/lib/friendly_shipping/shipping_method.rb +7 -0
  57. data/lib/friendly_shipping/version.rb +1 -1
  58. metadata +33 -6
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'friendly_shipping/services/ups_freight/rates_item_options'
4
+
5
+ module FriendlyShipping
6
+ module Services
7
+ class UpsFreight
8
+ # Options for packages/pallets within a UPS Freight shipment
9
+ #
10
+ # @attribute [Symbol] handling _unit How this shipment is divided. Any of the keys in `HANDLING_UNIT_TYPES`
11
+ # @attribute [RatesItemOptions] item_options Options for each of the items on the pallet/in the carboy/etc.
12
+ class RatesPackageOptions < FriendlyShipping::PackageOptions
13
+ HANDLING_UNIT_TYPES = {
14
+ pallet: { code: "PLT", description: "Pallet", handling_unit_tag: 'One' },
15
+ skid: { code: "SKD", description: "Skid", handling_unit_tag: 'One' },
16
+ carboy: { code: "CBY", description: "Carboy", handling_unit_tag: 'One' },
17
+ totes: { code: "TOT", description: "Totes", handling_unit_tag: 'One' },
18
+ other: { code: "OTH", description: "Other", handling_unit_tag: 'Two' },
19
+ loose: { code: "LOO", description: "Loose", handling_unit_tag: 'Two' }
20
+ }.freeze
21
+
22
+ attr_reader :handling_unit_description,
23
+ :handling_unit_tag,
24
+ :handling_unit_code
25
+
26
+ def initialize(
27
+ handling_unit: :pallet,
28
+ **kwargs
29
+ )
30
+ @handling_unit_code = HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:code)
31
+ @handling_unit_description = HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:description)
32
+ @handling_unit_tag = "HandlingUnit#{HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:handling_unit_tag)}"
33
+ super kwargs.merge(item_options_class: RatesItemOptions)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class UpsFreight
6
+ ORIGIN_COUNTRIES = %w(
7
+ CA MX PR US
8
+ ).map { |country_code| Carmen::Country.coded(country_code) }.freeze
9
+
10
+ SHIPPING_METHODS = [
11
+ ['308', 'UPS Freight LTL'],
12
+ ['309', 'UPS Freight LTL - Guaranteed'],
13
+ ['334', 'UPS Freight LTL - Guaranteed A.M.'],
14
+ ['349', 'UPS Standard LTL']
15
+ ].freeze.map do |code, name|
16
+ FriendlyShipping::ShippingMethod.new(
17
+ name: name,
18
+ service_code: code,
19
+ origin_countries: ORIGIN_COUNTRIES,
20
+ multi_package: true
21
+ ).freeze
22
+ end
23
+ end
24
+ end
25
+ end
@@ -59,7 +59,7 @@ module FriendlyShipping
59
59
  # can be serialized into an error message using `to_s`.
60
60
  def rate_estimates(shipment, shipping_method: nil, debug: false)
61
61
  rate_request_xml = SerializeRateRequest.call(shipment: shipment, login: login, shipping_method: shipping_method)
62
- request = build_request(api: :rates_request, xml: rate_request_xml, debug: debug)
62
+ request = build_request(api: :rates, xml: rate_request_xml, debug: debug)
63
63
 
64
64
  client.post(request).bind do |response|
65
65
  ParseRateResponse.call(response: response, request: request, shipment: shipment)
@@ -9,7 +9,7 @@ module FriendlyShipping
9
9
 
10
10
  class << self
11
11
  def call(response_body, expected_root_tag)
12
- xml = Nokogiri.XML(response_body)
12
+ xml = Nokogiri.XML(response_body, &:strict)
13
13
 
14
14
  if xml.root.nil? || ![expected_root_tag, 'Error'].include?(xml.root.name)
15
15
  Failure('Invalid document')
@@ -74,10 +74,6 @@ module FriendlyShipping
74
74
  ounces == 16 ? 15.999 : [ounces, 1].max
75
75
  end
76
76
 
77
- def strip_zip(zip)
78
- zip.to_s.scan(/\d{5}/).first || zip
79
- end
80
-
81
77
  def girth(package)
82
78
  width, length = package.dimensions.sort.first(2)
83
79
  (width.scale(2) + length.scale(2)).convert_to(:inches).value.to_f
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ class ShipmentOptions
5
+ def initialize(
6
+ package_options: Set.new,
7
+ package_options_class: PackageOptions
8
+ )
9
+ @package_options = package_options
10
+ @package_options_class = package_options_class
11
+ end
12
+
13
+ def options_for_package(package)
14
+ package_options.detect do |package_option|
15
+ package_option.package_id == package.id
16
+ end || package_options_class.new(package_id: nil)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :package_options, :package_options_class
22
+ end
23
+ end
@@ -4,6 +4,13 @@ module FriendlyShipping
4
4
  class ShippingMethod
5
5
  attr_reader :name, :service_code, :carrier, :origin_countries
6
6
 
7
+ # @param [String] name The shipping method's name
8
+ # @param [String] service_code The shipping method's service code
9
+ # @param [Boolean] domestic Whether this is a domestic shipping method
10
+ # @param [Boolean] international Whether this is an international shipping method
11
+ # @param [Boolean] multi_package Whether this is a multi-package shipping method
12
+ # @param [FriendlyShipping::Carrier] carrier This shipping method's carrier
13
+ # @param [Array] origin_countries Countries this shipping method ships from
7
14
  def initialize(
8
15
  name: nil,
9
16
  service_code: nil,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FriendlyShipping
4
- VERSION = "0.3.4"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_shipping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: data_uri
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: physical
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0.4'
75
+ version: 0.4.4
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0.4'
82
+ version: 0.4.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rest-client
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -164,24 +164,36 @@ files:
164
164
  - lib/friendly_shipping/api_result.rb
165
165
  - lib/friendly_shipping/carrier.rb
166
166
  - lib/friendly_shipping/http_client.rb
167
+ - lib/friendly_shipping/item_options.rb
167
168
  - lib/friendly_shipping/label.rb
169
+ - lib/friendly_shipping/package_options.rb
168
170
  - lib/friendly_shipping/rate.rb
169
171
  - lib/friendly_shipping/request.rb
170
172
  - lib/friendly_shipping/response.rb
171
173
  - lib/friendly_shipping/services/ship_engine.rb
172
174
  - lib/friendly_shipping/services/ship_engine/bad_request.rb
173
175
  - lib/friendly_shipping/services/ship_engine/bad_request_handler.rb
176
+ - lib/friendly_shipping/services/ship_engine/label_options.rb
177
+ - lib/friendly_shipping/services/ship_engine/label_package_options.rb
174
178
  - lib/friendly_shipping/services/ship_engine/parse_carrier_response.rb
175
179
  - lib/friendly_shipping/services/ship_engine/parse_label_response.rb
176
180
  - lib/friendly_shipping/services/ship_engine/parse_rate_estimate_response.rb
177
181
  - lib/friendly_shipping/services/ship_engine/parse_void_response.rb
182
+ - lib/friendly_shipping/services/ship_engine/rate_estimates_options.rb
178
183
  - lib/friendly_shipping/services/ship_engine/serialize_label_shipment.rb
179
184
  - lib/friendly_shipping/services/ship_engine/serialize_rate_estimate_request.rb
180
185
  - lib/friendly_shipping/services/ups.rb
186
+ - lib/friendly_shipping/services/ups/label_billing_options.rb
187
+ - lib/friendly_shipping/services/ups/label_item_options.rb
188
+ - lib/friendly_shipping/services/ups/label_options.rb
189
+ - lib/friendly_shipping/services/ups/label_package_options.rb
181
190
  - lib/friendly_shipping/services/ups/parse_address_classification_response.rb
182
191
  - lib/friendly_shipping/services/ups/parse_address_validation_response.rb
183
192
  - lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
193
+ - lib/friendly_shipping/services/ups/parse_money_element.rb
184
194
  - lib/friendly_shipping/services/ups/parse_rate_response.rb
195
+ - lib/friendly_shipping/services/ups/parse_shipment_accept_response.rb
196
+ - lib/friendly_shipping/services/ups/parse_shipment_confirm_response.rb
185
197
  - lib/friendly_shipping/services/ups/parse_xml_response.rb
186
198
  - lib/friendly_shipping/services/ups/serialize_access_request.rb
187
199
  - lib/friendly_shipping/services/ups/serialize_address_snippet.rb
@@ -189,7 +201,21 @@ files:
189
201
  - lib/friendly_shipping/services/ups/serialize_city_state_lookup_request.rb
190
202
  - lib/friendly_shipping/services/ups/serialize_package_node.rb
191
203
  - lib/friendly_shipping/services/ups/serialize_rating_service_selection_request.rb
204
+ - lib/friendly_shipping/services/ups/serialize_shipment_accept_request.rb
205
+ - lib/friendly_shipping/services/ups/serialize_shipment_address_snippet.rb
206
+ - lib/friendly_shipping/services/ups/serialize_shipment_confirm_request.rb
192
207
  - lib/friendly_shipping/services/ups/shipping_methods.rb
208
+ - lib/friendly_shipping/services/ups_freight.rb
209
+ - lib/friendly_shipping/services/ups_freight/generate_commodity_information.rb
210
+ - lib/friendly_shipping/services/ups_freight/generate_freight_rate_request_hash.rb
211
+ - lib/friendly_shipping/services/ups_freight/generate_location_hash.rb
212
+ - lib/friendly_shipping/services/ups_freight/generate_ups_security_hash.rb
213
+ - lib/friendly_shipping/services/ups_freight/parse_freight_rate_response.rb
214
+ - lib/friendly_shipping/services/ups_freight/parse_json_response.rb
215
+ - lib/friendly_shipping/services/ups_freight/rates_item_options.rb
216
+ - lib/friendly_shipping/services/ups_freight/rates_options.rb
217
+ - lib/friendly_shipping/services/ups_freight/rates_package_options.rb
218
+ - lib/friendly_shipping/services/ups_freight/shipping_methods.rb
193
219
  - lib/friendly_shipping/services/usps.rb
194
220
  - lib/friendly_shipping/services/usps/choose_package_rate.rb
195
221
  - lib/friendly_shipping/services/usps/machinable_package.rb
@@ -202,6 +228,7 @@ files:
202
228
  - lib/friendly_shipping/services/usps/serialize_city_state_lookup_request.rb
203
229
  - lib/friendly_shipping/services/usps/serialize_rate_request.rb
204
230
  - lib/friendly_shipping/services/usps/shipping_methods.rb
231
+ - lib/friendly_shipping/shipment_options.rb
205
232
  - lib/friendly_shipping/shipping_method.rb
206
233
  - lib/friendly_shipping/version.rb
207
234
  homepage: https://github.com/friendly_cart/friendly_shipping