friendly_shipping 0.8.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/.env.template +3 -0
- data/.env.test.local.template +6 -0
- data/.gitignore +1 -0
- data/.rubocop-relaxed.yml +7 -23
- data/.rubocop.yml +17 -2
- data/.rubocop_todo.yml +21 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +71 -0
- data/Gemfile +17 -0
- data/README.md +1 -1
- data/friendly_shipping.gemspec +8 -17
- data/lib/friendly_shipping/access_token.rb +24 -0
- data/lib/friendly_shipping/api_error.rb +8 -4
- data/lib/friendly_shipping/api_error_handler.rb +11 -9
- data/lib/friendly_shipping/api_failure.rb +2 -7
- data/lib/friendly_shipping/api_result.rb +26 -4
- data/lib/friendly_shipping/carrier.rb +28 -8
- data/lib/friendly_shipping/http_client.rb +25 -8
- data/lib/friendly_shipping/inflections.rb +10 -0
- data/lib/friendly_shipping/item_options.rb +3 -0
- data/lib/friendly_shipping/label.rb +41 -22
- data/lib/friendly_shipping/package_options.rb +21 -2
- data/lib/friendly_shipping/rate.rb +50 -15
- data/lib/friendly_shipping/request.rb +23 -7
- data/lib/friendly_shipping/response.rb +21 -6
- data/lib/friendly_shipping/services/rl/api_error.rb +31 -0
- data/lib/friendly_shipping/services/rl/bol_options.rb +103 -0
- data/lib/friendly_shipping/services/rl/bol_packages_serializer.rb +32 -0
- data/lib/friendly_shipping/services/rl/bol_structures_serializer.rb +31 -0
- data/lib/friendly_shipping/services/rl/item_options.rb +36 -0
- data/lib/friendly_shipping/services/rl/package_options.rb +38 -0
- data/lib/friendly_shipping/services/rl/parse_create_bol_response.rb +43 -0
- data/lib/friendly_shipping/services/rl/parse_invoice_response.rb +47 -0
- data/lib/friendly_shipping/services/rl/parse_print_bol_response.rb +44 -0
- data/lib/friendly_shipping/services/rl/parse_print_shipping_labels_response.rb +44 -0
- data/lib/friendly_shipping/services/rl/parse_rate_quote_response.rb +93 -0
- data/lib/friendly_shipping/services/rl/parse_transit_times_response.rb +73 -0
- data/lib/friendly_shipping/services/rl/rate_quote_options.rb +82 -0
- data/lib/friendly_shipping/services/rl/rate_quote_packages_serializer.rb +54 -0
- data/lib/friendly_shipping/services/rl/rate_quote_structures_serializer.rb +53 -0
- data/lib/friendly_shipping/services/rl/serialize_create_bol_request.rb +86 -0
- data/lib/friendly_shipping/services/rl/serialize_location.rb +53 -0
- data/lib/friendly_shipping/services/rl/serialize_rate_quote_request.rb +69 -0
- data/lib/friendly_shipping/services/rl/serialize_transit_times_request.rb +38 -0
- data/lib/friendly_shipping/services/rl/shipment_document.rb +40 -0
- data/lib/friendly_shipping/services/rl/shipment_information.rb +41 -0
- data/lib/friendly_shipping/services/rl/shipment_options.rb +48 -0
- data/lib/friendly_shipping/services/rl/shipping_methods.rb +28 -0
- data/lib/friendly_shipping/services/rl/structure_options.rb +13 -0
- data/lib/friendly_shipping/services/rl.rb +187 -0
- data/lib/friendly_shipping/services/ship_engine/api_error.rb +31 -0
- data/lib/friendly_shipping/services/ship_engine/customs_items_serializer.rb +36 -0
- data/lib/friendly_shipping/services/ship_engine/label_customs_options.rb +10 -7
- data/lib/friendly_shipping/services/ship_engine/label_item_options.rb +10 -7
- data/lib/friendly_shipping/services/ship_engine/label_options.rb +30 -17
- data/lib/friendly_shipping/services/ship_engine/label_package_options.rb +18 -14
- data/lib/friendly_shipping/services/ship_engine/parse_address_validation_response.rb +75 -0
- data/lib/friendly_shipping/services/ship_engine/parse_carrier_response.rb +9 -2
- data/lib/friendly_shipping/services/ship_engine/parse_label_response.rb +4 -2
- data/lib/friendly_shipping/services/ship_engine/{parse_rate_estimate_response.rb → parse_rate_estimates_response.rb} +27 -9
- data/lib/friendly_shipping/services/ship_engine/parse_rates_response.rb +99 -0
- data/lib/friendly_shipping/services/ship_engine/parse_void_response.rb +5 -1
- data/lib/friendly_shipping/services/ship_engine/rate_estimates_options.rb +17 -6
- data/lib/friendly_shipping/services/ship_engine/rates_item_options.rb +26 -0
- data/lib/friendly_shipping/services/ship_engine/rates_options.rb +59 -0
- data/lib/friendly_shipping/services/ship_engine/rates_package_options.rb +18 -0
- data/lib/friendly_shipping/services/ship_engine/serialize_address_residential_indicator.rb +27 -0
- data/lib/friendly_shipping/services/ship_engine/serialize_address_validation_request.rb +31 -0
- data/lib/friendly_shipping/services/ship_engine/serialize_label_shipment.rb +22 -27
- data/lib/friendly_shipping/services/ship_engine/serialize_rate_estimate_request.rb +41 -16
- data/lib/friendly_shipping/services/ship_engine/serialize_rates_request.rb +126 -0
- data/lib/friendly_shipping/services/ship_engine.rb +89 -33
- data/lib/friendly_shipping/services/ship_engine_ltl/api_error.rb +12 -0
- data/lib/friendly_shipping/services/ship_engine_ltl/item_options.rb +24 -5
- data/lib/friendly_shipping/services/ship_engine_ltl/package_options.rb +39 -4
- data/lib/friendly_shipping/services/ship_engine_ltl/parse_carrier_response.rb +4 -2
- data/lib/friendly_shipping/services/ship_engine_ltl/parse_quote_response.rb +10 -2
- data/lib/friendly_shipping/services/ship_engine_ltl/quote_options.rb +29 -11
- data/lib/friendly_shipping/services/ship_engine_ltl/serialize_packages.rb +7 -2
- data/lib/friendly_shipping/services/ship_engine_ltl/serialize_quote_request.rb +50 -16
- data/lib/friendly_shipping/services/ship_engine_ltl/serialize_structures.rb +42 -0
- data/lib/friendly_shipping/services/ship_engine_ltl/shipment_options.rb +47 -0
- data/lib/friendly_shipping/services/ship_engine_ltl/structure_options.rb +17 -0
- data/lib/friendly_shipping/services/ship_engine_ltl.rb +47 -39
- data/lib/friendly_shipping/services/tforce_freight/access_token.rb +28 -0
- data/lib/friendly_shipping/services/tforce_freight/api_error.rb +40 -0
- data/lib/friendly_shipping/services/tforce_freight/bol_options.rb +180 -0
- data/lib/friendly_shipping/services/tforce_freight/document_options.rb +100 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_commodity_information.rb +92 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_create_bol_request_hash.rb +153 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_document_options_hash.rb +36 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_handling_units_hash.rb +51 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_location_hash.rb +25 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_pickup_request_hash.rb +111 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_rates_request_hash.rb +63 -0
- data/lib/friendly_shipping/services/tforce_freight/generate_reference_hash.rb +28 -0
- data/lib/friendly_shipping/services/tforce_freight/item_options.rb +93 -0
- data/lib/friendly_shipping/services/tforce_freight/package_options.rb +119 -0
- data/lib/friendly_shipping/services/tforce_freight/parse_create_bol_response.rb +90 -0
- data/lib/friendly_shipping/services/tforce_freight/parse_pickup_response.rb +45 -0
- data/lib/friendly_shipping/services/tforce_freight/parse_rates_response.rb +50 -0
- data/lib/friendly_shipping/services/tforce_freight/parse_shipment_document.rb +29 -0
- data/lib/friendly_shipping/services/tforce_freight/pickup_options.rb +82 -0
- data/lib/friendly_shipping/services/tforce_freight/rates_item_options.rb +10 -0
- data/lib/friendly_shipping/services/tforce_freight/rates_options.rb +159 -0
- data/lib/friendly_shipping/services/tforce_freight/rates_package_options.rb +10 -0
- data/lib/friendly_shipping/services/tforce_freight/shipment_document.rb +38 -0
- data/lib/friendly_shipping/services/tforce_freight/shipment_information.rb +104 -0
- data/lib/friendly_shipping/services/tforce_freight/shipment_options.rb +47 -0
- data/lib/friendly_shipping/services/tforce_freight/shipping_methods.rb +25 -0
- data/lib/friendly_shipping/services/tforce_freight/structure_options.rb +44 -0
- data/lib/friendly_shipping/services/tforce_freight.rb +176 -0
- data/lib/friendly_shipping/services/ups/label_item_options.rb +0 -2
- data/lib/friendly_shipping/services/ups/label_options.rb +14 -5
- data/lib/friendly_shipping/services/ups/label_package_options.rb +1 -3
- data/lib/friendly_shipping/services/ups/parse_address_validation_response.rb +1 -1
- data/lib/friendly_shipping/services/ups/parse_modifier_element.rb +29 -0
- data/lib/friendly_shipping/services/ups/parse_rate_response.rb +11 -3
- data/lib/friendly_shipping/services/ups/parse_shipment_accept_response.rb +0 -3
- data/lib/friendly_shipping/services/ups/parse_shipment_confirm_response.rb +0 -2
- data/lib/friendly_shipping/services/ups/parse_time_in_transit_response.rb +1 -1
- data/lib/friendly_shipping/services/ups/parse_void_shipment_response.rb +0 -2
- data/lib/friendly_shipping/services/ups/parse_xml_response.rb +1 -1
- data/lib/friendly_shipping/services/ups/rate_estimate_options.rb +14 -3
- data/lib/friendly_shipping/services/ups/rate_estimate_package_options.rb +0 -2
- data/lib/friendly_shipping/services/ups/serialize_access_request.rb +0 -2
- data/lib/friendly_shipping/services/ups/serialize_rating_service_selection_request.rb +10 -5
- data/lib/friendly_shipping/services/ups/serialize_shipment_accept_request.rb +1 -1
- data/lib/friendly_shipping/services/ups/serialize_shipment_confirm_request.rb +2 -4
- data/lib/friendly_shipping/services/ups/shipping_methods.rb +1 -1
- data/lib/friendly_shipping/services/ups.rb +2 -24
- data/lib/friendly_shipping/services/ups_freight/api_error.rb +8 -7
- data/lib/friendly_shipping/services/ups_freight/generate_commodity_information.rb +65 -19
- data/lib/friendly_shipping/services/ups_freight/generate_freight_rate_request_hash.rb +2 -23
- data/lib/friendly_shipping/services/ups_freight/generate_freight_ship_request_hash.rb +1 -27
- data/lib/friendly_shipping/services/ups_freight/generate_handling_units_hash.rb +54 -0
- data/lib/friendly_shipping/services/ups_freight/label_options.rb +36 -10
- data/lib/friendly_shipping/services/ups_freight/label_structure_options.rb +13 -0
- data/lib/friendly_shipping/services/ups_freight/parse_freight_label_response.rb +2 -5
- data/lib/friendly_shipping/services/ups_freight/parse_freight_rate_response.rb +0 -4
- data/lib/friendly_shipping/services/ups_freight/parse_shipment_document.rb +1 -3
- data/lib/friendly_shipping/services/ups_freight/rates_item_options.rb +18 -9
- data/lib/friendly_shipping/services/ups_freight/rates_options.rb +30 -24
- data/lib/friendly_shipping/services/ups_freight/rates_package_options.rb +79 -10
- data/lib/friendly_shipping/services/ups_freight/rates_structure_options.rb +44 -0
- data/lib/friendly_shipping/services/ups_freight/shipment_information.rb +7 -3
- data/lib/friendly_shipping/services/ups_freight/shipment_options.rb +47 -0
- data/lib/friendly_shipping/services/ups_freight.rb +2 -20
- data/lib/friendly_shipping/services/ups_json/access_token.rb +20 -0
- data/lib/friendly_shipping/services/ups_json/api_error.rb +27 -0
- data/lib/friendly_shipping/services/ups_json/generate_address_classification_payload.rb +29 -0
- data/lib/friendly_shipping/services/ups_json/generate_address_hash.rb +30 -0
- data/lib/friendly_shipping/services/ups_json/generate_city_state_lookup_payload.rb +23 -0
- data/lib/friendly_shipping/services/ups_json/generate_labels_payload.rb +208 -0
- data/lib/friendly_shipping/services/ups_json/generate_package_hash.rb +76 -0
- data/lib/friendly_shipping/services/ups_json/generate_rates_payload.rb +84 -0
- data/lib/friendly_shipping/services/ups_json/generate_timings_payload.rb +44 -0
- data/lib/friendly_shipping/services/ups_json/label.rb +20 -0
- data/lib/friendly_shipping/services/ups_json/label_billing_options.rb +41 -0
- data/lib/friendly_shipping/services/ups_json/label_item_options.rb +75 -0
- data/lib/friendly_shipping/services/ups_json/label_options.rb +174 -0
- data/lib/friendly_shipping/services/ups_json/label_package_options.rb +49 -0
- data/lib/friendly_shipping/services/ups_json/parse_address_classification_response.rb +31 -0
- data/lib/friendly_shipping/services/ups_json/parse_city_state_lookup_response.rb +44 -0
- data/lib/friendly_shipping/services/ups_json/parse_json_response.rb +51 -0
- data/lib/friendly_shipping/services/ups_json/parse_labels_response.rb +71 -0
- data/lib/friendly_shipping/services/ups_json/parse_money_hash.rb +128 -0
- data/lib/friendly_shipping/services/ups_json/parse_rate_modifier_hash.rb +28 -0
- data/lib/friendly_shipping/services/ups_json/parse_rates_response.rb +107 -0
- data/lib/friendly_shipping/services/ups_json/parse_timings_response.rb +56 -0
- data/lib/friendly_shipping/services/ups_json/parse_void_response.rb +32 -0
- data/lib/friendly_shipping/services/ups_json/rates_item_options.rb +20 -0
- data/lib/friendly_shipping/services/ups_json/rates_options.rb +111 -0
- data/lib/friendly_shipping/services/ups_json/rates_package_options.rb +17 -0
- data/lib/friendly_shipping/services/ups_json/shipping_methods.rb +111 -0
- data/lib/friendly_shipping/services/ups_json/timings_options.rb +33 -0
- data/lib/friendly_shipping/services/ups_json.rb +216 -0
- data/lib/friendly_shipping/services/usps/choose_package_rate.rb +3 -3
- data/lib/friendly_shipping/services/usps/machinable_package.rb +1 -1
- data/lib/friendly_shipping/services/usps/parse_package_rate.rb +6 -6
- data/lib/friendly_shipping/services/usps/parse_rate_response.rb +0 -4
- data/lib/friendly_shipping/services/usps/parse_time_in_transit_response.rb +6 -9
- data/lib/friendly_shipping/services/usps/parse_xml_response.rb +1 -1
- data/lib/friendly_shipping/services/usps/rate_estimate_options.rb +1 -3
- data/lib/friendly_shipping/services/usps/rate_estimate_package_options.rb +6 -3
- data/lib/friendly_shipping/services/usps/serialize_rate_request.rb +2 -4
- data/lib/friendly_shipping/services/usps/shipping_methods.rb +4 -3
- data/lib/friendly_shipping/services/usps.rb +2 -13
- data/lib/friendly_shipping/services/usps_international/parse_package_rate.rb +3 -3
- data/lib/friendly_shipping/services/usps_international/parse_rate_response.rb +0 -3
- data/lib/friendly_shipping/services/usps_international/rate_estimate_options.rb +1 -3
- data/lib/friendly_shipping/services/usps_international/rate_estimate_package_options.rb +0 -2
- data/lib/friendly_shipping/services/usps_international/serialize_rate_request.rb +1 -3
- data/lib/friendly_shipping/services/usps_international.rb +2 -6
- data/lib/friendly_shipping/services/usps_ship/access_token.rb +22 -0
- data/lib/friendly_shipping/services/usps_ship/api_error.rb +27 -0
- data/lib/friendly_shipping/services/usps_ship/machinable_package.rb +55 -0
- data/lib/friendly_shipping/services/usps_ship/parse_rate_estimates_response.rb +80 -0
- data/lib/friendly_shipping/services/usps_ship/parse_timings_response.rb +82 -0
- data/lib/friendly_shipping/services/usps_ship/rate_estimate_options.rb +45 -0
- data/lib/friendly_shipping/services/usps_ship/rate_estimate_package_options.rb +122 -0
- data/lib/friendly_shipping/services/usps_ship/serialize_rate_estimates_request.rb +53 -0
- data/lib/friendly_shipping/services/usps_ship/shipping_methods.rb +38 -0
- data/lib/friendly_shipping/services/{ship_engine_ltl/bad_request.rb → usps_ship/timing_options.rb} +2 -2
- data/lib/friendly_shipping/services/usps_ship.rb +185 -0
- data/lib/friendly_shipping/shipment_options.rb +13 -1
- data/lib/friendly_shipping/shipping_method.rb +38 -11
- data/lib/friendly_shipping/structure_options.rb +38 -0
- data/lib/friendly_shipping/timing.rb +42 -7
- data/lib/friendly_shipping/version.rb +1 -1
- data/lib/friendly_shipping.rb +20 -15
- metadata +143 -174
- data/lib/friendly_shipping/services/ship_engine/bad_request.rb +0 -29
- data/lib/friendly_shipping/services/ship_engine/bad_request_handler.rb +0 -33
- data/lib/friendly_shipping/services/ship_engine_ltl/bad_request_handler.rb +0 -33
@@ -1,32 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'friendly_shipping/shipment_options'
|
4
|
-
|
5
3
|
module FriendlyShipping
|
6
4
|
module Services
|
7
5
|
class ShipEngineLTL
|
6
|
+
# Options for rate quote requests.
|
8
7
|
class QuoteOptions < ShipmentOptions
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
# @return [String] the service code to use when getting rates
|
9
|
+
attr_reader :service_code
|
10
|
+
|
11
|
+
# @return [Time] the pickup date
|
12
|
+
attr_reader :pickup_date
|
13
|
+
|
14
|
+
# @return [Array<String>] the accessorial service codes
|
15
|
+
attr_reader :accessorial_service_codes
|
16
|
+
|
17
|
+
# @return [Class] the class to use for serializing structures
|
18
|
+
attr_reader :structures_serializer_class
|
19
|
+
|
20
|
+
# @return [Class] the class to use for serializing packages
|
21
|
+
# @deprecated Use {#structures_serializer_class} instead.
|
22
|
+
attr_reader :packages_serializer_class
|
13
23
|
|
14
|
-
# @param [String]
|
15
|
-
# @param [Time]
|
16
|
-
# @param [Array<String>]
|
17
|
-
# @param [Class]
|
24
|
+
# @param service_code [String] the service code to use when getting rates
|
25
|
+
# @param pickup_date [Time] the pickup date
|
26
|
+
# @param accessorial_service_codes [Array<String>] the accessorial service codes (if any)
|
27
|
+
# @param packages_serializer_class [Class] the class to use for serializing packages (DEPRECATED: use `structures_serializer_class` instead)
|
28
|
+
# @param structures_serializer_class [Class] the class to use for serializing structures
|
29
|
+
# @param kwargs [Hash]
|
30
|
+
# @option kwargs [Array<PackageOptions>] :package_options the options for packages in this shipment (DEPRECATED: use `structure_options` instead)
|
31
|
+
# @option kwargs [Class] :package_options_class the class to use for package options when none are provided (DEPRECATED: use `structure_options_class` instead)
|
32
|
+
# @option kwargs [Array<StructureOptions>] :structure_options the options for structures in this shipment
|
33
|
+
# @option kwargs [Class] :structure_options_class the class to use for structure options when none are provided
|
18
34
|
def initialize(
|
19
35
|
service_code: nil,
|
20
36
|
pickup_date: nil,
|
21
37
|
accessorial_service_codes: [],
|
38
|
+
structures_serializer_class: SerializeStructures,
|
22
39
|
packages_serializer_class: SerializePackages,
|
23
40
|
**kwargs
|
24
41
|
)
|
25
42
|
@service_code = service_code
|
26
43
|
@pickup_date = pickup_date
|
27
44
|
@accessorial_service_codes = accessorial_service_codes
|
45
|
+
@structures_serializer_class = structures_serializer_class
|
28
46
|
@packages_serializer_class = packages_serializer_class
|
29
|
-
super(**kwargs
|
47
|
+
super(**kwargs)
|
30
48
|
end
|
31
49
|
end
|
32
50
|
end
|
@@ -3,11 +3,16 @@
|
|
3
3
|
module FriendlyShipping
|
4
4
|
module Services
|
5
5
|
class ShipEngineLTL
|
6
|
+
# Serializes packages for the rate quote API request.
|
7
|
+
# @deprecated Use {SerializeStructures} instead.
|
6
8
|
class SerializePackages
|
7
9
|
class << self
|
8
|
-
# @param [Array<Physical::Package>]
|
9
|
-
# @param [
|
10
|
+
# @param packages [Array<Physical::Package>]
|
11
|
+
# @param options [QuoteOptions]
|
12
|
+
# @return [Array<Hash>]
|
10
13
|
def call(packages:, options:)
|
14
|
+
warn "[DEPRECATION] `SerializePackages` is deprecated. Please use `SerializeStructures` instead."
|
15
|
+
|
11
16
|
packages.flat_map do |package|
|
12
17
|
package_options = options.options_for_package(package)
|
13
18
|
package.items.map do |item|
|
@@ -3,36 +3,52 @@
|
|
3
3
|
module FriendlyShipping
|
4
4
|
module Services
|
5
5
|
class ShipEngineLTL
|
6
|
+
# Serializes a shipment and options for the rate quote API request.
|
6
7
|
class SerializeQuoteRequest
|
7
8
|
class << self
|
8
|
-
# @param [Physical::Shipment] shipment
|
9
|
-
# @param [
|
9
|
+
# @param shipment [Physical::Shipment] the shipment to serialize
|
10
|
+
# @param options [QuoteOptions] the options to serialize
|
11
|
+
# @return [Hash] the serialized request
|
10
12
|
def call(shipment:, options:)
|
11
13
|
{
|
12
14
|
shipment: {
|
13
15
|
service_code: options.service_code,
|
14
16
|
pickup_date: options.pickup_date.strftime('%Y-%m-%d'),
|
15
|
-
packages:
|
17
|
+
packages: serialize_packages(shipment, options),
|
16
18
|
options: serialize_options(options),
|
17
19
|
ship_from: serialize_ship_address(shipment.origin),
|
18
20
|
ship_to: serialize_ship_address(shipment.destination),
|
19
21
|
bill_to: serialize_bill_address(shipment.origin),
|
20
22
|
requested_by: serialize_requested_by(shipment.origin),
|
21
23
|
}.compact,
|
22
|
-
shipment_measurements: serialize_shipment_measurements(shipment
|
24
|
+
shipment_measurements: serialize_shipment_measurements(shipment, options)
|
23
25
|
}
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
27
29
|
|
28
|
-
# @param [
|
30
|
+
# @param shipment [Physical::Shipment]
|
31
|
+
# @param options [QuoteOptions]
|
32
|
+
# @return [Hash]
|
33
|
+
def serialize_packages(shipment, options)
|
34
|
+
if options.packages_serializer_class
|
35
|
+
warn "[DEPRECATION] `packages_serializer_class` is deprecated. Please use `structures_serializer_class` instead."
|
36
|
+
options.packages_serializer_class.call(packages: shipment.packages, options: options)
|
37
|
+
else
|
38
|
+
options.structures_serializer_class.call(structures: shipment.structures, options: options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param options [QuoteOptions]
|
43
|
+
# @return [Array<Hash>]
|
29
44
|
def serialize_options(options)
|
30
45
|
options.accessorial_service_codes.map do |code|
|
31
46
|
{ code: code }
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
35
|
-
# @param [Physical::Location]
|
50
|
+
# @param location [Physical::Location]
|
51
|
+
# @return [Hash]
|
36
52
|
def serialize_ship_address(location)
|
37
53
|
{
|
38
54
|
account: location.properties.with_indifferent_access['account_number'],
|
@@ -41,7 +57,8 @@ module FriendlyShipping
|
|
41
57
|
}.compact
|
42
58
|
end
|
43
59
|
|
44
|
-
# @param [Physical::Location]
|
60
|
+
# @param location [Physical::Location]
|
61
|
+
# @return [Hash]
|
45
62
|
def serialize_bill_address(location)
|
46
63
|
{
|
47
64
|
type: "shipper",
|
@@ -52,7 +69,8 @@ module FriendlyShipping
|
|
52
69
|
}.compact
|
53
70
|
end
|
54
71
|
|
55
|
-
# @param [Physical::Location]
|
72
|
+
# @param location [Physical::Location]
|
73
|
+
# @return [Hash]
|
56
74
|
def serialize_address(location)
|
57
75
|
{
|
58
76
|
company_name: location.company_name,
|
@@ -64,7 +82,8 @@ module FriendlyShipping
|
|
64
82
|
}.compact
|
65
83
|
end
|
66
84
|
|
67
|
-
# @param [Physical::Location]
|
85
|
+
# @param location [Physical::Location]
|
86
|
+
# @return [Hash]
|
68
87
|
def serialize_contact(location)
|
69
88
|
{
|
70
89
|
name: location.name,
|
@@ -73,7 +92,8 @@ module FriendlyShipping
|
|
73
92
|
}.compact
|
74
93
|
end
|
75
94
|
|
76
|
-
# @param [Physical::Location]
|
95
|
+
# @param location [Physical::Location]
|
96
|
+
# @return [Hash]
|
77
97
|
def serialize_requested_by(location)
|
78
98
|
{
|
79
99
|
company_name: location.company_name,
|
@@ -81,23 +101,37 @@ module FriendlyShipping
|
|
81
101
|
}.compact
|
82
102
|
end
|
83
103
|
|
84
|
-
# @param [
|
85
|
-
|
104
|
+
# @param shipment [Physical::Shipment]
|
105
|
+
# @param options [QuoteOptions]
|
106
|
+
# @return [Hash]
|
107
|
+
def serialize_shipment_measurements(shipment, options)
|
108
|
+
if options.packages_serializer_class
|
109
|
+
warn "[DEPRECATION] `packages_serializer_class` is deprecated. Please use `structures_serializer_class` instead."
|
110
|
+
total_length = shipment.packages.sum(&:length)
|
111
|
+
max_width = shipment.packages.map(&:width).max
|
112
|
+
max_height = shipment.packages.map(&:height).max
|
113
|
+
total_weight = shipment.packages.sum(&:weight)
|
114
|
+
else
|
115
|
+
total_length = shipment.structures.sum(&:length)
|
116
|
+
max_width = shipment.structures.map(&:width).max
|
117
|
+
max_height = shipment.structures.map(&:height).max
|
118
|
+
total_weight = shipment.structures.sum(&:weight)
|
119
|
+
end
|
86
120
|
{
|
87
121
|
total_linear_length: {
|
88
|
-
value:
|
122
|
+
value: total_length.convert_to(:inches).value.ceil,
|
89
123
|
unit: "inches"
|
90
124
|
},
|
91
125
|
total_width: {
|
92
|
-
value:
|
126
|
+
value: max_width.convert_to(:inches).value.ceil,
|
93
127
|
unit: "inches"
|
94
128
|
},
|
95
129
|
total_height: {
|
96
|
-
value:
|
130
|
+
value: max_height.convert_to(:inches).value.ceil,
|
97
131
|
unit: "inches"
|
98
132
|
},
|
99
133
|
total_weight: {
|
100
|
-
value:
|
134
|
+
value: total_weight.convert_to(:pounds).value.ceil,
|
101
135
|
unit: "pounds"
|
102
136
|
}
|
103
137
|
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FriendlyShipping
|
4
|
+
module Services
|
5
|
+
class ShipEngineLTL
|
6
|
+
class SerializeStructures
|
7
|
+
class << self
|
8
|
+
# @param structures [Array<Physical::Structure>]
|
9
|
+
# @param options [FriendlyShipping::Services::ShipEngineLTL::QuoteOptions]
|
10
|
+
# @return [Array<Hash>]
|
11
|
+
def call(structures:, options:)
|
12
|
+
structures.flat_map do |structure|
|
13
|
+
structure_options = options.options_for_structure(structure)
|
14
|
+
structure.packages.map do |package|
|
15
|
+
package_options = structure_options.options_for_package(package)
|
16
|
+
{
|
17
|
+
code: package_options.packaging_code,
|
18
|
+
freight_class: package_options.freight_class,
|
19
|
+
nmfc_code: package_options.nmfc_code,
|
20
|
+
description: package.description || "Commodities",
|
21
|
+
dimensions: {
|
22
|
+
width: package.width.convert_to(:inches).value.ceil,
|
23
|
+
height: package.height.convert_to(:inches).value.ceil,
|
24
|
+
length: package.length.convert_to(:inches).value.ceil,
|
25
|
+
unit: "inches"
|
26
|
+
},
|
27
|
+
weight: {
|
28
|
+
value: package.weight.convert_to(:pounds).value.ceil,
|
29
|
+
unit: "pounds"
|
30
|
+
},
|
31
|
+
quantity: 1, # we don't support this yet
|
32
|
+
stackable: package_options.stackable,
|
33
|
+
hazardous_materials: package_options.hazardous_materials
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FriendlyShipping
|
4
|
+
module Services
|
5
|
+
class ShipEngineLTL
|
6
|
+
class ShipmentOptions < FriendlyShipping::ShipmentOptions
|
7
|
+
# @param structure_options [Array<StructureOptions>]
|
8
|
+
# @param structure_options_class [Class]
|
9
|
+
# @param kwargs [Hash]
|
10
|
+
# @option kwargs [Array<PackageOptions>] :package_options
|
11
|
+
# @option kwargs [Class] :package_options_class
|
12
|
+
def initialize(
|
13
|
+
structure_options: Set.new,
|
14
|
+
structure_options_class: StructureOptions,
|
15
|
+
**kwargs
|
16
|
+
)
|
17
|
+
@structure_options = structure_options
|
18
|
+
@structure_options_class = structure_options_class
|
19
|
+
super(**kwargs.reverse_merge(package_options_class: PackageOptions))
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param [#id] structure
|
23
|
+
# @return [StructureOptions]
|
24
|
+
def options_for_structure(structure)
|
25
|
+
structure_options.detect do |structure_option|
|
26
|
+
structure_option.structure_id == structure.id
|
27
|
+
end || structure_options_class.new(structure_id: nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# @return [Array<StructureOptions>]
|
33
|
+
attr_reader :structure_options
|
34
|
+
|
35
|
+
# @return [Class]
|
36
|
+
attr_reader :structure_options_class
|
37
|
+
|
38
|
+
# @return [Array<PackageOptions>]
|
39
|
+
# @deprecated Use {#structure_options} instead.
|
40
|
+
def package_options
|
41
|
+
warn "[DEPRECATION] `package_options` is deprecated. Please use `structure_options` instead."
|
42
|
+
@package_options
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FriendlyShipping
|
4
|
+
module Services
|
5
|
+
class ShipEngineLTL
|
6
|
+
class StructureOptions < FriendlyShipping::StructureOptions
|
7
|
+
# @param kwargs [Hash]
|
8
|
+
# @option kwargs [String] :structure_id
|
9
|
+
# @option kwargs [Array<PackageOptions>] :package_options
|
10
|
+
# @option kwargs [Class] :package_options_class
|
11
|
+
def initialize(**kwargs)
|
12
|
+
super(**kwargs.reverse_merge(package_options_class: PackageOptions))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,43 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require 'friendly_shipping/http_client'
|
5
|
-
require 'friendly_shipping/services/ship_engine_ltl/bad_request_handler'
|
6
|
-
require 'friendly_shipping/services/ship_engine_ltl/parse_carrier_response'
|
7
|
-
require 'friendly_shipping/services/ship_engine_ltl/parse_quote_response'
|
8
|
-
require 'friendly_shipping/services/ship_engine_ltl/serialize_packages'
|
9
|
-
require 'friendly_shipping/services/ship_engine_ltl/serialize_quote_request'
|
10
|
-
require 'friendly_shipping/services/ship_engine_ltl/quote_options'
|
11
|
-
require 'friendly_shipping/services/ship_engine_ltl/package_options'
|
12
|
-
require 'friendly_shipping/services/ship_engine_ltl/item_options'
|
3
|
+
require "json"
|
13
4
|
|
14
5
|
module FriendlyShipping
|
15
6
|
module Services
|
7
|
+
# API service class for ShipEngine LTL, a shipping API supporting Freight carriers.
|
8
|
+
# @see https://www.shipengine.com/docs/ltl/ ShipEngine LTL API docs
|
16
9
|
class ShipEngineLTL
|
17
10
|
include Dry::Monads::Result::Mixin
|
18
11
|
|
12
|
+
# The API base URL.
|
19
13
|
API_BASE = "https://api.shipengine.com/v-beta/ltl/"
|
14
|
+
|
15
|
+
# The API paths. Used when constructing endpoint URLs.
|
20
16
|
API_PATHS = {
|
21
17
|
connections: "connections",
|
22
18
|
carriers: "carriers",
|
23
19
|
quotes: "quotes"
|
24
20
|
}.freeze
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
error_handler: FriendlyShipping::Services::ShipEngineLTL::BadRequestHandler
|
31
|
-
)
|
32
|
-
)
|
22
|
+
# @param token [String] the API token
|
23
|
+
# @param test [Boolean] whether to use test API endpoints
|
24
|
+
# @param client [HttpClient] optional custom HTTP client to use for requests
|
25
|
+
def initialize(token:, test: true, client: nil)
|
33
26
|
@token = token
|
34
27
|
@test = test
|
35
|
-
|
28
|
+
|
29
|
+
error_handler = ApiErrorHandler.new(api_error_class: ShipEngineLTL::ApiError)
|
30
|
+
@client = client || HttpClient.new(error_handler: error_handler)
|
36
31
|
end
|
37
32
|
|
38
|
-
# Get configured LTL carriers
|
33
|
+
# Get configured LTL carriers.
|
39
34
|
#
|
40
|
-
# @
|
35
|
+
# @param debug [Boolean] whether to attach debugging information to the response
|
36
|
+
# @return [Success<ApiResult<Array<Carrier>>>, Failure<ApiResult<Array<String>>>] On success,
|
37
|
+
# LTL carriers configured in your account. On failure, a list of error messages.
|
41
38
|
def carriers(debug: false)
|
42
39
|
request = FriendlyShipping::Request.new(
|
43
40
|
url: API_BASE + API_PATHS[:carriers],
|
@@ -49,12 +46,13 @@ module FriendlyShipping
|
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
52
|
-
# Connect an LTL carrier
|
53
|
-
#
|
54
|
-
# @param [Hash] credentials The carrier's connection information
|
55
|
-
# @param [String] scac Standard Carrier Alpha Code
|
49
|
+
# Connect an LTL carrier.
|
56
50
|
#
|
57
|
-
# @
|
51
|
+
# @param credentials [Hash] the carrier's connection information
|
52
|
+
# @param scac [String] Standard Carrier Alpha Code
|
53
|
+
# @see https://nmfta.org/scac/ SCAC
|
54
|
+
# @param debug [Boolean] whether to attach debugging information to the response
|
55
|
+
# @return [Success<ApiResult<Hash>>, Failure<ApiResult<String>>] the carrier or error message
|
58
56
|
def connect_carrier(credentials, scac, debug: false)
|
59
57
|
request = FriendlyShipping::Request.new(
|
60
58
|
url: API_BASE + API_PATHS[:connections] + "/#{scac}",
|
@@ -73,13 +71,14 @@ module FriendlyShipping
|
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
76
|
-
# Update an existing LTL carrier
|
74
|
+
# Update an existing LTL carrier.
|
77
75
|
#
|
78
|
-
# @param [Hash]
|
79
|
-
# @param [String]
|
80
|
-
# @
|
81
|
-
#
|
82
|
-
# @
|
76
|
+
# @param credentials [Hash] the carrier's connection information
|
77
|
+
# @param scac [String] Standard Carrier Alpha Code
|
78
|
+
# @see https://nmfta.org/scac/ SCAC
|
79
|
+
# @param carrier_id [String] the ID for the carrier you want to update
|
80
|
+
# @param debug [Boolean] whether to attach debugging information to the response
|
81
|
+
# @return [Success<ApiResult<Hash>>, Failure<ApiResult<String>>] the carrier or error message
|
83
82
|
def update_carrier(credentials, scac, carrier_id, debug: false)
|
84
83
|
request = FriendlyShipping::Request.new(
|
85
84
|
url: API_BASE + API_PATHS[:connections] + "/#{scac}/#{carrier_id}",
|
@@ -98,13 +97,13 @@ module FriendlyShipping
|
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
|
-
# Request an LTL price quote
|
102
|
-
#
|
103
|
-
# @param [String] carrier_id The carrier ID from ShipEngine that you want to quote against
|
104
|
-
# @param [Physical::Shipment] shipment The shipment to quote
|
105
|
-
# @param [FriendlyShipping::Services::ShipEngineLTL::QuoteOptions] options The options for the quote
|
100
|
+
# Request an LTL price quote.
|
106
101
|
#
|
107
|
-
# @
|
102
|
+
# @param carrier_id [String] the carrier ID
|
103
|
+
# @param shipment [Physical::Shipment] the shipment to quote
|
104
|
+
# @param options [QuoteOptions] the options for the quote
|
105
|
+
# @param debug [Boolean] whether to attach debugging information to the response
|
106
|
+
# @return [Success<ApiResult<Hash>>, Failure<ApiResult<String>>] the quote or error message
|
108
107
|
def request_quote(carrier_id, shipment, options, debug: false)
|
109
108
|
request = FriendlyShipping::Request.new(
|
110
109
|
url: API_BASE + API_PATHS[:quotes] + "/#{carrier_id}",
|
@@ -120,12 +119,21 @@ module FriendlyShipping
|
|
120
119
|
|
121
120
|
private
|
122
121
|
|
123
|
-
|
122
|
+
# @return [String] the API token
|
123
|
+
attr_reader :token
|
124
|
+
|
125
|
+
# @return [Boolean] whether to use test API endpoints
|
126
|
+
attr_reader :test
|
127
|
+
|
128
|
+
# @return [HttpClient] the HTTP client to use for requests
|
129
|
+
attr_reader :client
|
124
130
|
|
131
|
+
# Returns the content type and API key as a headers hash.
|
132
|
+
# @return [Hash]
|
125
133
|
def request_headers
|
126
134
|
{
|
127
135
|
content_type: :json,
|
128
|
-
|
136
|
+
'api-key': token
|
129
137
|
}
|
130
138
|
end
|
131
139
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jwt'
|
4
|
+
|
5
|
+
module FriendlyShipping
|
6
|
+
module Services
|
7
|
+
class TForceFreight
|
8
|
+
# Represents an access token returned by TForce Freight. The access token can be
|
9
|
+
# used to make API requests. Once it expires, a new token must be created.
|
10
|
+
class AccessToken < FriendlyShipping::AccessToken
|
11
|
+
# @return [String] the token's type
|
12
|
+
attr_reader :token_type
|
13
|
+
|
14
|
+
# @return [Integer] the token's extended expiration
|
15
|
+
attr_reader :ext_expires_in
|
16
|
+
|
17
|
+
# @param token_type [String] the token's type (typically "Bearer")
|
18
|
+
# @param ext_expires_in [Integer] the token's extended expiration (only applicable during a service outage)
|
19
|
+
# @see https://github.com/AzureAD/azure-activedirectory-library-for-android/issues/675 Service Outage Resiliency Support
|
20
|
+
def initialize(token_type:, ext_expires_in:, **other_kwargs)
|
21
|
+
@token_type = token_type
|
22
|
+
@ext_expires_in = ext_expires_in
|
23
|
+
super(**other_kwargs)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FriendlyShipping
|
4
|
+
module Services
|
5
|
+
class TForceFreight
|
6
|
+
# Raised when an API error is returned.
|
7
|
+
class ApiError < FriendlyShipping::ApiError
|
8
|
+
# @param cause [RestClient::Exception]
|
9
|
+
def initialize(cause)
|
10
|
+
super(cause, parse_message(cause))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# @param error [RestClient::Exception]
|
16
|
+
# @return [String]
|
17
|
+
def parse_message(error)
|
18
|
+
return error.message unless error.response
|
19
|
+
|
20
|
+
parsed_json = JSON.parse(error.response.body)
|
21
|
+
if parsed_json['summary'].present?
|
22
|
+
status = parsed_json.dig("summary", "responseStatus", "code")
|
23
|
+
message = parsed_json.dig("summary", "responseStatus", "message").presence ||
|
24
|
+
parsed_json.dig("summary", "responseStatus", "description")
|
25
|
+
elsif parsed_json['responseStatus'].present?
|
26
|
+
status = parsed_json.dig("responseStatus", "code")
|
27
|
+
message = parsed_json.dig("responseStatus", "description")
|
28
|
+
else
|
29
|
+
status = parsed_json['statusCode']
|
30
|
+
message = parsed_json['message'].presence ||
|
31
|
+
parsed_json['description']
|
32
|
+
end
|
33
|
+
[status, message].compact.join(": ")
|
34
|
+
rescue JSON::ParserError, KeyError => _e
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|