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.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  3. data/.env.template +3 -0
  4. data/.env.test.local.template +6 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop-relaxed.yml +7 -23
  7. data/.rubocop.yml +17 -2
  8. data/.rubocop_todo.yml +21 -0
  9. data/.yardopts +6 -0
  10. data/CHANGELOG.md +71 -0
  11. data/Gemfile +17 -0
  12. data/README.md +1 -1
  13. data/friendly_shipping.gemspec +8 -17
  14. data/lib/friendly_shipping/access_token.rb +24 -0
  15. data/lib/friendly_shipping/api_error.rb +8 -4
  16. data/lib/friendly_shipping/api_error_handler.rb +11 -9
  17. data/lib/friendly_shipping/api_failure.rb +2 -7
  18. data/lib/friendly_shipping/api_result.rb +26 -4
  19. data/lib/friendly_shipping/carrier.rb +28 -8
  20. data/lib/friendly_shipping/http_client.rb +25 -8
  21. data/lib/friendly_shipping/inflections.rb +10 -0
  22. data/lib/friendly_shipping/item_options.rb +3 -0
  23. data/lib/friendly_shipping/label.rb +41 -22
  24. data/lib/friendly_shipping/package_options.rb +21 -2
  25. data/lib/friendly_shipping/rate.rb +50 -15
  26. data/lib/friendly_shipping/request.rb +23 -7
  27. data/lib/friendly_shipping/response.rb +21 -6
  28. data/lib/friendly_shipping/services/rl/api_error.rb +31 -0
  29. data/lib/friendly_shipping/services/rl/bol_options.rb +103 -0
  30. data/lib/friendly_shipping/services/rl/bol_packages_serializer.rb +32 -0
  31. data/lib/friendly_shipping/services/rl/bol_structures_serializer.rb +31 -0
  32. data/lib/friendly_shipping/services/rl/item_options.rb +36 -0
  33. data/lib/friendly_shipping/services/rl/package_options.rb +38 -0
  34. data/lib/friendly_shipping/services/rl/parse_create_bol_response.rb +43 -0
  35. data/lib/friendly_shipping/services/rl/parse_invoice_response.rb +47 -0
  36. data/lib/friendly_shipping/services/rl/parse_print_bol_response.rb +44 -0
  37. data/lib/friendly_shipping/services/rl/parse_print_shipping_labels_response.rb +44 -0
  38. data/lib/friendly_shipping/services/rl/parse_rate_quote_response.rb +93 -0
  39. data/lib/friendly_shipping/services/rl/parse_transit_times_response.rb +73 -0
  40. data/lib/friendly_shipping/services/rl/rate_quote_options.rb +82 -0
  41. data/lib/friendly_shipping/services/rl/rate_quote_packages_serializer.rb +54 -0
  42. data/lib/friendly_shipping/services/rl/rate_quote_structures_serializer.rb +53 -0
  43. data/lib/friendly_shipping/services/rl/serialize_create_bol_request.rb +86 -0
  44. data/lib/friendly_shipping/services/rl/serialize_location.rb +53 -0
  45. data/lib/friendly_shipping/services/rl/serialize_rate_quote_request.rb +69 -0
  46. data/lib/friendly_shipping/services/rl/serialize_transit_times_request.rb +38 -0
  47. data/lib/friendly_shipping/services/rl/shipment_document.rb +40 -0
  48. data/lib/friendly_shipping/services/rl/shipment_information.rb +41 -0
  49. data/lib/friendly_shipping/services/rl/shipment_options.rb +48 -0
  50. data/lib/friendly_shipping/services/rl/shipping_methods.rb +28 -0
  51. data/lib/friendly_shipping/services/rl/structure_options.rb +13 -0
  52. data/lib/friendly_shipping/services/rl.rb +187 -0
  53. data/lib/friendly_shipping/services/ship_engine/api_error.rb +31 -0
  54. data/lib/friendly_shipping/services/ship_engine/customs_items_serializer.rb +36 -0
  55. data/lib/friendly_shipping/services/ship_engine/label_customs_options.rb +10 -7
  56. data/lib/friendly_shipping/services/ship_engine/label_item_options.rb +10 -7
  57. data/lib/friendly_shipping/services/ship_engine/label_options.rb +30 -17
  58. data/lib/friendly_shipping/services/ship_engine/label_package_options.rb +18 -14
  59. data/lib/friendly_shipping/services/ship_engine/parse_address_validation_response.rb +75 -0
  60. data/lib/friendly_shipping/services/ship_engine/parse_carrier_response.rb +9 -2
  61. data/lib/friendly_shipping/services/ship_engine/parse_label_response.rb +4 -2
  62. data/lib/friendly_shipping/services/ship_engine/{parse_rate_estimate_response.rb → parse_rate_estimates_response.rb} +27 -9
  63. data/lib/friendly_shipping/services/ship_engine/parse_rates_response.rb +99 -0
  64. data/lib/friendly_shipping/services/ship_engine/parse_void_response.rb +5 -1
  65. data/lib/friendly_shipping/services/ship_engine/rate_estimates_options.rb +17 -6
  66. data/lib/friendly_shipping/services/ship_engine/rates_item_options.rb +26 -0
  67. data/lib/friendly_shipping/services/ship_engine/rates_options.rb +59 -0
  68. data/lib/friendly_shipping/services/ship_engine/rates_package_options.rb +18 -0
  69. data/lib/friendly_shipping/services/ship_engine/serialize_address_residential_indicator.rb +27 -0
  70. data/lib/friendly_shipping/services/ship_engine/serialize_address_validation_request.rb +31 -0
  71. data/lib/friendly_shipping/services/ship_engine/serialize_label_shipment.rb +22 -27
  72. data/lib/friendly_shipping/services/ship_engine/serialize_rate_estimate_request.rb +41 -16
  73. data/lib/friendly_shipping/services/ship_engine/serialize_rates_request.rb +126 -0
  74. data/lib/friendly_shipping/services/ship_engine.rb +89 -33
  75. data/lib/friendly_shipping/services/ship_engine_ltl/api_error.rb +12 -0
  76. data/lib/friendly_shipping/services/ship_engine_ltl/item_options.rb +24 -5
  77. data/lib/friendly_shipping/services/ship_engine_ltl/package_options.rb +39 -4
  78. data/lib/friendly_shipping/services/ship_engine_ltl/parse_carrier_response.rb +4 -2
  79. data/lib/friendly_shipping/services/ship_engine_ltl/parse_quote_response.rb +10 -2
  80. data/lib/friendly_shipping/services/ship_engine_ltl/quote_options.rb +29 -11
  81. data/lib/friendly_shipping/services/ship_engine_ltl/serialize_packages.rb +7 -2
  82. data/lib/friendly_shipping/services/ship_engine_ltl/serialize_quote_request.rb +50 -16
  83. data/lib/friendly_shipping/services/ship_engine_ltl/serialize_structures.rb +42 -0
  84. data/lib/friendly_shipping/services/ship_engine_ltl/shipment_options.rb +47 -0
  85. data/lib/friendly_shipping/services/ship_engine_ltl/structure_options.rb +17 -0
  86. data/lib/friendly_shipping/services/ship_engine_ltl.rb +47 -39
  87. data/lib/friendly_shipping/services/tforce_freight/access_token.rb +28 -0
  88. data/lib/friendly_shipping/services/tforce_freight/api_error.rb +40 -0
  89. data/lib/friendly_shipping/services/tforce_freight/bol_options.rb +180 -0
  90. data/lib/friendly_shipping/services/tforce_freight/document_options.rb +100 -0
  91. data/lib/friendly_shipping/services/tforce_freight/generate_commodity_information.rb +92 -0
  92. data/lib/friendly_shipping/services/tforce_freight/generate_create_bol_request_hash.rb +153 -0
  93. data/lib/friendly_shipping/services/tforce_freight/generate_document_options_hash.rb +36 -0
  94. data/lib/friendly_shipping/services/tforce_freight/generate_handling_units_hash.rb +51 -0
  95. data/lib/friendly_shipping/services/tforce_freight/generate_location_hash.rb +25 -0
  96. data/lib/friendly_shipping/services/tforce_freight/generate_pickup_request_hash.rb +111 -0
  97. data/lib/friendly_shipping/services/tforce_freight/generate_rates_request_hash.rb +63 -0
  98. data/lib/friendly_shipping/services/tforce_freight/generate_reference_hash.rb +28 -0
  99. data/lib/friendly_shipping/services/tforce_freight/item_options.rb +93 -0
  100. data/lib/friendly_shipping/services/tforce_freight/package_options.rb +119 -0
  101. data/lib/friendly_shipping/services/tforce_freight/parse_create_bol_response.rb +90 -0
  102. data/lib/friendly_shipping/services/tforce_freight/parse_pickup_response.rb +45 -0
  103. data/lib/friendly_shipping/services/tforce_freight/parse_rates_response.rb +50 -0
  104. data/lib/friendly_shipping/services/tforce_freight/parse_shipment_document.rb +29 -0
  105. data/lib/friendly_shipping/services/tforce_freight/pickup_options.rb +82 -0
  106. data/lib/friendly_shipping/services/tforce_freight/rates_item_options.rb +10 -0
  107. data/lib/friendly_shipping/services/tforce_freight/rates_options.rb +159 -0
  108. data/lib/friendly_shipping/services/tforce_freight/rates_package_options.rb +10 -0
  109. data/lib/friendly_shipping/services/tforce_freight/shipment_document.rb +38 -0
  110. data/lib/friendly_shipping/services/tforce_freight/shipment_information.rb +104 -0
  111. data/lib/friendly_shipping/services/tforce_freight/shipment_options.rb +47 -0
  112. data/lib/friendly_shipping/services/tforce_freight/shipping_methods.rb +25 -0
  113. data/lib/friendly_shipping/services/tforce_freight/structure_options.rb +44 -0
  114. data/lib/friendly_shipping/services/tforce_freight.rb +176 -0
  115. data/lib/friendly_shipping/services/ups/label_item_options.rb +0 -2
  116. data/lib/friendly_shipping/services/ups/label_options.rb +14 -5
  117. data/lib/friendly_shipping/services/ups/label_package_options.rb +1 -3
  118. data/lib/friendly_shipping/services/ups/parse_address_validation_response.rb +1 -1
  119. data/lib/friendly_shipping/services/ups/parse_modifier_element.rb +29 -0
  120. data/lib/friendly_shipping/services/ups/parse_rate_response.rb +11 -3
  121. data/lib/friendly_shipping/services/ups/parse_shipment_accept_response.rb +0 -3
  122. data/lib/friendly_shipping/services/ups/parse_shipment_confirm_response.rb +0 -2
  123. data/lib/friendly_shipping/services/ups/parse_time_in_transit_response.rb +1 -1
  124. data/lib/friendly_shipping/services/ups/parse_void_shipment_response.rb +0 -2
  125. data/lib/friendly_shipping/services/ups/parse_xml_response.rb +1 -1
  126. data/lib/friendly_shipping/services/ups/rate_estimate_options.rb +14 -3
  127. data/lib/friendly_shipping/services/ups/rate_estimate_package_options.rb +0 -2
  128. data/lib/friendly_shipping/services/ups/serialize_access_request.rb +0 -2
  129. data/lib/friendly_shipping/services/ups/serialize_rating_service_selection_request.rb +10 -5
  130. data/lib/friendly_shipping/services/ups/serialize_shipment_accept_request.rb +1 -1
  131. data/lib/friendly_shipping/services/ups/serialize_shipment_confirm_request.rb +2 -4
  132. data/lib/friendly_shipping/services/ups/shipping_methods.rb +1 -1
  133. data/lib/friendly_shipping/services/ups.rb +2 -24
  134. data/lib/friendly_shipping/services/ups_freight/api_error.rb +8 -7
  135. data/lib/friendly_shipping/services/ups_freight/generate_commodity_information.rb +65 -19
  136. data/lib/friendly_shipping/services/ups_freight/generate_freight_rate_request_hash.rb +2 -23
  137. data/lib/friendly_shipping/services/ups_freight/generate_freight_ship_request_hash.rb +1 -27
  138. data/lib/friendly_shipping/services/ups_freight/generate_handling_units_hash.rb +54 -0
  139. data/lib/friendly_shipping/services/ups_freight/label_options.rb +36 -10
  140. data/lib/friendly_shipping/services/ups_freight/label_structure_options.rb +13 -0
  141. data/lib/friendly_shipping/services/ups_freight/parse_freight_label_response.rb +2 -5
  142. data/lib/friendly_shipping/services/ups_freight/parse_freight_rate_response.rb +0 -4
  143. data/lib/friendly_shipping/services/ups_freight/parse_shipment_document.rb +1 -3
  144. data/lib/friendly_shipping/services/ups_freight/rates_item_options.rb +18 -9
  145. data/lib/friendly_shipping/services/ups_freight/rates_options.rb +30 -24
  146. data/lib/friendly_shipping/services/ups_freight/rates_package_options.rb +79 -10
  147. data/lib/friendly_shipping/services/ups_freight/rates_structure_options.rb +44 -0
  148. data/lib/friendly_shipping/services/ups_freight/shipment_information.rb +7 -3
  149. data/lib/friendly_shipping/services/ups_freight/shipment_options.rb +47 -0
  150. data/lib/friendly_shipping/services/ups_freight.rb +2 -20
  151. data/lib/friendly_shipping/services/ups_json/access_token.rb +20 -0
  152. data/lib/friendly_shipping/services/ups_json/api_error.rb +27 -0
  153. data/lib/friendly_shipping/services/ups_json/generate_address_classification_payload.rb +29 -0
  154. data/lib/friendly_shipping/services/ups_json/generate_address_hash.rb +30 -0
  155. data/lib/friendly_shipping/services/ups_json/generate_city_state_lookup_payload.rb +23 -0
  156. data/lib/friendly_shipping/services/ups_json/generate_labels_payload.rb +208 -0
  157. data/lib/friendly_shipping/services/ups_json/generate_package_hash.rb +76 -0
  158. data/lib/friendly_shipping/services/ups_json/generate_rates_payload.rb +84 -0
  159. data/lib/friendly_shipping/services/ups_json/generate_timings_payload.rb +44 -0
  160. data/lib/friendly_shipping/services/ups_json/label.rb +20 -0
  161. data/lib/friendly_shipping/services/ups_json/label_billing_options.rb +41 -0
  162. data/lib/friendly_shipping/services/ups_json/label_item_options.rb +75 -0
  163. data/lib/friendly_shipping/services/ups_json/label_options.rb +174 -0
  164. data/lib/friendly_shipping/services/ups_json/label_package_options.rb +49 -0
  165. data/lib/friendly_shipping/services/ups_json/parse_address_classification_response.rb +31 -0
  166. data/lib/friendly_shipping/services/ups_json/parse_city_state_lookup_response.rb +44 -0
  167. data/lib/friendly_shipping/services/ups_json/parse_json_response.rb +51 -0
  168. data/lib/friendly_shipping/services/ups_json/parse_labels_response.rb +71 -0
  169. data/lib/friendly_shipping/services/ups_json/parse_money_hash.rb +128 -0
  170. data/lib/friendly_shipping/services/ups_json/parse_rate_modifier_hash.rb +28 -0
  171. data/lib/friendly_shipping/services/ups_json/parse_rates_response.rb +107 -0
  172. data/lib/friendly_shipping/services/ups_json/parse_timings_response.rb +56 -0
  173. data/lib/friendly_shipping/services/ups_json/parse_void_response.rb +32 -0
  174. data/lib/friendly_shipping/services/ups_json/rates_item_options.rb +20 -0
  175. data/lib/friendly_shipping/services/ups_json/rates_options.rb +111 -0
  176. data/lib/friendly_shipping/services/ups_json/rates_package_options.rb +17 -0
  177. data/lib/friendly_shipping/services/ups_json/shipping_methods.rb +111 -0
  178. data/lib/friendly_shipping/services/ups_json/timings_options.rb +33 -0
  179. data/lib/friendly_shipping/services/ups_json.rb +216 -0
  180. data/lib/friendly_shipping/services/usps/choose_package_rate.rb +3 -3
  181. data/lib/friendly_shipping/services/usps/machinable_package.rb +1 -1
  182. data/lib/friendly_shipping/services/usps/parse_package_rate.rb +6 -6
  183. data/lib/friendly_shipping/services/usps/parse_rate_response.rb +0 -4
  184. data/lib/friendly_shipping/services/usps/parse_time_in_transit_response.rb +6 -9
  185. data/lib/friendly_shipping/services/usps/parse_xml_response.rb +1 -1
  186. data/lib/friendly_shipping/services/usps/rate_estimate_options.rb +1 -3
  187. data/lib/friendly_shipping/services/usps/rate_estimate_package_options.rb +6 -3
  188. data/lib/friendly_shipping/services/usps/serialize_rate_request.rb +2 -4
  189. data/lib/friendly_shipping/services/usps/shipping_methods.rb +4 -3
  190. data/lib/friendly_shipping/services/usps.rb +2 -13
  191. data/lib/friendly_shipping/services/usps_international/parse_package_rate.rb +3 -3
  192. data/lib/friendly_shipping/services/usps_international/parse_rate_response.rb +0 -3
  193. data/lib/friendly_shipping/services/usps_international/rate_estimate_options.rb +1 -3
  194. data/lib/friendly_shipping/services/usps_international/rate_estimate_package_options.rb +0 -2
  195. data/lib/friendly_shipping/services/usps_international/serialize_rate_request.rb +1 -3
  196. data/lib/friendly_shipping/services/usps_international.rb +2 -6
  197. data/lib/friendly_shipping/services/usps_ship/access_token.rb +22 -0
  198. data/lib/friendly_shipping/services/usps_ship/api_error.rb +27 -0
  199. data/lib/friendly_shipping/services/usps_ship/machinable_package.rb +55 -0
  200. data/lib/friendly_shipping/services/usps_ship/parse_rate_estimates_response.rb +80 -0
  201. data/lib/friendly_shipping/services/usps_ship/parse_timings_response.rb +82 -0
  202. data/lib/friendly_shipping/services/usps_ship/rate_estimate_options.rb +45 -0
  203. data/lib/friendly_shipping/services/usps_ship/rate_estimate_package_options.rb +122 -0
  204. data/lib/friendly_shipping/services/usps_ship/serialize_rate_estimates_request.rb +53 -0
  205. data/lib/friendly_shipping/services/usps_ship/shipping_methods.rb +38 -0
  206. data/lib/friendly_shipping/services/{ship_engine_ltl/bad_request.rb → usps_ship/timing_options.rb} +2 -2
  207. data/lib/friendly_shipping/services/usps_ship.rb +185 -0
  208. data/lib/friendly_shipping/shipment_options.rb +13 -1
  209. data/lib/friendly_shipping/shipping_method.rb +38 -11
  210. data/lib/friendly_shipping/structure_options.rb +38 -0
  211. data/lib/friendly_shipping/timing.rb +42 -7
  212. data/lib/friendly_shipping/version.rb +1 -1
  213. data/lib/friendly_shipping.rb +20 -15
  214. metadata +143 -174
  215. data/lib/friendly_shipping/services/ship_engine/bad_request.rb +0 -29
  216. data/lib/friendly_shipping/services/ship_engine/bad_request_handler.rb +0 -33
  217. data/lib/friendly_shipping/services/ship_engine_ltl/bad_request_handler.rb +0 -33
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
6
+ # Options for creating a pickup.
7
+ class PickupOptions < ShipmentOptions
8
+ # Maps friendly names to service options.
9
+ SERVICE_OPTIONS = {
10
+ inside: "INPU",
11
+ liftgate: "LIFO",
12
+ freezable: "PFFF",
13
+ residential: "RESP",
14
+ extreme_length: "EXLT",
15
+ trade_show: "TRPU"
16
+ }.freeze
17
+
18
+ # @return [Time] date/time of pickup
19
+ attr_reader :pickup_at
20
+
21
+ # @return [Range] time window for pickup
22
+ attr_reader :pickup_time_window
23
+
24
+ # @return [Array<String>] shipment pickup service options (see {SERVICE_OPTIONS})
25
+ attr_reader :service_options
26
+
27
+ # @return [String] instructions for pickup
28
+ attr_reader :pickup_instructions
29
+
30
+ # @return [String] instructions for handling
31
+ attr_reader :handling_instructions
32
+
33
+ # @return [String] instructions for delivery
34
+ attr_reader :delivery_instructions
35
+
36
+ # @param pickup_at [Time] date/time of pickup (defaults to now)
37
+ # @param pickup_time_window [Range] time window for pickup (defaults to start/end of today)
38
+ # @param service_options [Array<String>] shipment pickup service options (see {SERVICE_OPTIONS})
39
+ # @param pickup_instructions [String] instructions for pickup
40
+ # @param handling_instructions [String] instructions for handling
41
+ # @param delivery_instructions [String] instructions for delivery
42
+ # @param kwargs [Hash]
43
+ # @option kwargs [Array<PackageOptions>] :package_options the options for packages in this shipment
44
+ # @option kwargs [Class] :package_options_class the class to use for package options when none are provided
45
+ def initialize(
46
+ pickup_at: Time.now,
47
+ pickup_time_window: Time.now.beginning_of_day..Time.now.end_of_day,
48
+ service_options: [],
49
+ pickup_instructions: nil,
50
+ handling_instructions: nil,
51
+ delivery_instructions: nil,
52
+ **kwargs
53
+ )
54
+ @pickup_at = pickup_at
55
+ @pickup_time_window = pickup_time_window
56
+ @service_options = service_options
57
+ @pickup_instructions = pickup_instructions
58
+ @handling_instructions = handling_instructions
59
+ @delivery_instructions = delivery_instructions
60
+
61
+ validate_service_options!
62
+
63
+ super(**kwargs.reverse_merge(package_options_class: PackageOptions))
64
+ end
65
+
66
+ private
67
+
68
+ # Raises an exception if the service options passed into the initializer
69
+ # don't correspond to valid codes from {SERVICE_OPTIONS}.
70
+ #
71
+ # @raise [ArgumentError] invalid service options
72
+ # @return [nil]
73
+ def validate_service_options!
74
+ invalid_options = (service_options - SERVICE_OPTIONS.values)
75
+ return unless invalid_options.any?
76
+
77
+ raise ArgumentError, "Invalid service option(s): #{invalid_options.join(', ')}"
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
6
+ # @deprecated use {FriendlyShipping::Services::TForceFreight::ItemOptions} instead
7
+ RatesItemOptions = ItemOptions
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
6
+ # Options for getting rates for a shipment.
7
+ class RatesOptions < ShipmentOptions
8
+ # Maps friendly names to billing codes.
9
+ BILLING_CODES = {
10
+ prepaid: "10",
11
+ third_party: "30",
12
+ freight_collect: "40"
13
+ }.freeze
14
+
15
+ # Maps friendly names to type codes.
16
+ TYPE_CODES = {
17
+ l: "L", # LTL (Less Than Truckload) only
18
+ f: "F", # GFP (Ground w/Freight Pricing) only
19
+ b: "B" # Both (LTL and GFP)
20
+ }.freeze
21
+
22
+ # Maps friendly names to pickup options.
23
+ PICKUP_OPTIONS = {
24
+ inside: "INPU",
25
+ liftgate: "LIFO",
26
+ limited_access: "LAPU",
27
+ holiday: "WHPU",
28
+ weekend: "WHPU",
29
+ tradeshow: "TRPU",
30
+ residential: "RESP"
31
+ }.freeze
32
+
33
+ # Maps friendly names to delivery options.
34
+ DELIVERY_OPTIONS = {
35
+ inside: "INDE",
36
+ liftgate: "LIFD",
37
+ limited_access: "LADL",
38
+ holiday: "WHDL",
39
+ weekend: "WHDL",
40
+ call_consignee: "NTFN",
41
+ tradeshow: "TRDS",
42
+ residential: "RESD"
43
+ }.freeze
44
+
45
+ # @return [Physical::Location] the billing address
46
+ attr_reader :billing_address
47
+
48
+ # @return [ShippingMethod] the shipping method
49
+ attr_reader :shipping_method
50
+
51
+ # @return [Date] date of the pickup
52
+ attr_reader :pickup_date
53
+
54
+ # @return [Symbol] how the shipment is billed (see {BILLING_CODES})
55
+ attr_reader :billing_code
56
+
57
+ # @return [String] rating call type (see {TYPE_CODES})
58
+ attr_reader :type_code
59
+
60
+ # @return [Boolean] indicates that the rate request is density based
61
+ attr_reader :density_eligible
62
+
63
+ # @return [Boolean] indicates that the rate is accessorial
64
+ attr_reader :accessorial_rate
65
+
66
+ # @return [Boolean] requests transit timing information be included in the response
67
+ attr_reader :time_in_transit
68
+
69
+ # @return [Boolean] requests a quote number be included in the response
70
+ attr_reader :quote_number
71
+
72
+ # @return [Array<String>] shipment pick up service options (see {PICKUP_OPTIONS})
73
+ attr_reader :pickup_options
74
+
75
+ # @return [Array<String] shipment delivery service options (see {DELIVERY_OPTIONS})
76
+ attr_reader :delivery_options
77
+
78
+ # @return [String] customer context
79
+ attr_reader :customer_context
80
+
81
+ # @return [Callable] a callable that takes a shipment
82
+ attr_reader :commodity_information_generator
83
+
84
+ # @param billing_address [Physical::Location] the billing address
85
+ # @param shipping_method [ShippingMethod] the shipping method to use
86
+ # @param pickup_date [Date] date of the pickup (defaults to today)
87
+ # @param billing [Symbol] how the shipment is billed (see {BILLING_CODES})
88
+ # @param type [String] rating call type (defaults to L, see {TYPE_CODES})
89
+ # @param density_eligible [Boolean] indicates that the rate request is density based (defaults to `false`)
90
+ # @param accessorial_rate [Boolean] indicates that the rate is accessorial (defaults to `false`)
91
+ # @param time_in_transit [Boolean] requests transit timing information be included in the response (defaults to `true`)
92
+ # @param quote_number [Boolean] requests a quote number be included in the response (defaults to `false`)
93
+ # @param pickup_options [Array<String>] shipment pick up service options (see {PICKUP_OPTIONS})
94
+ # @param delivery_options [Array<String] shipment delivery service options (see {DELIVERY_OPTIONS})
95
+ # @param customer_context [String] a reference to match this request with an order or shipment (defaults to `nil`)
96
+ # @param commodity_information_generator [Callable] a callable that takes a shipment
97
+ # and an options object to create an `Array` of commodity fields as per the UPS docs
98
+ # @param kwargs [Hash]
99
+ # @option kwargs [Array<PackageOptions>] :package_options the options for packages in this shipment
100
+ # @option kwargs [Class] :package_options_class the class to use for package options when none are provided
101
+ def initialize(
102
+ billing_address:,
103
+ shipping_method:,
104
+ pickup_date: Date.today,
105
+ billing: :prepaid,
106
+ type: :l,
107
+ density_eligible: false,
108
+ accessorial_rate: false,
109
+ time_in_transit: true,
110
+ quote_number: false,
111
+ pickup_options: [],
112
+ delivery_options: [],
113
+ customer_context: nil,
114
+ commodity_information_generator: GenerateCommodityInformation,
115
+ **kwargs
116
+ )
117
+ @pickup_date = pickup_date
118
+ @billing_address = billing_address
119
+ @billing_code = BILLING_CODES.fetch(billing)
120
+ @shipping_method = shipping_method
121
+ @type_code = TYPE_CODES.fetch(type)
122
+ @density_eligible = density_eligible
123
+ @accessorial_rate = accessorial_rate
124
+ @time_in_transit = time_in_transit
125
+ @quote_number = quote_number
126
+ @pickup_options = pickup_options
127
+ @delivery_options = delivery_options
128
+ @customer_context = customer_context
129
+ @commodity_information_generator = commodity_information_generator
130
+
131
+ validate_pickup_options!
132
+ validate_delivery_options!
133
+
134
+ super(**kwargs.reverse_merge(package_options_class: PackageOptions))
135
+ end
136
+
137
+ private
138
+
139
+ # @raise [ArgumentError] invalid pickup options
140
+ # @return [nil]
141
+ def validate_pickup_options!
142
+ invalid_options = (pickup_options - PICKUP_OPTIONS.values)
143
+ return unless invalid_options.any?
144
+
145
+ raise ArgumentError, "Invalid pickup option(s): #{invalid_options.join(', ')}"
146
+ end
147
+
148
+ # @raise [ArgumentError] invalid delivery options
149
+ # @return [nil]
150
+ def validate_delivery_options!
151
+ invalid_options = (delivery_options - DELIVERY_OPTIONS.values)
152
+ return unless invalid_options.any?
153
+
154
+ raise ArgumentError, "Invalid delivery option(s): #{invalid_options.join(', ')}"
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
6
+ # @deprecated use {FriendlyShipping::Services::TForceFreight::PackageOptions} instead
7
+ RatesPackageOptions = PackageOptions
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
6
+ # A shipping document (BOL, label, etc.) returned by the API.
7
+ class ShipmentDocument
8
+ # @return [String] the type of document
9
+ attr_reader :document_type
10
+
11
+ # @return [String] the format of the document
12
+ attr_reader :document_format
13
+
14
+ # @return [String] the document's binary data
15
+ attr_reader :binary
16
+
17
+ # @return [String] the status of the document
18
+ attr_reader :status
19
+
20
+ # @param document_type [String] the type of document
21
+ # @param document_format [String] the format of the document
22
+ # @param binary [String] the document's binary data
23
+ # @param status [String] the status of the document (defaults to `nil`)
24
+ def initialize(
25
+ document_type:,
26
+ document_format:,
27
+ binary:,
28
+ status: nil
29
+ )
30
+ @document_type = document_type
31
+ @document_format = document_format
32
+ @binary = binary
33
+ @status = status
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
6
+ # Information for a specific shipment returned by the API.
7
+ class ShipmentInformation
8
+ # @return [String] the shipment's BOL ID number
9
+ attr_reader :bol_id
10
+
11
+ # @return [String] the shipment's PRO number
12
+ attr_reader :pro_number
13
+
14
+ # @return [String] the shipment's pickup confirmation number
15
+ attr_reader :pickup_confirmation_number
16
+
17
+ # @return [String] the origin service center
18
+ attr_reader :origin_service_center
19
+
20
+ # @return [Boolean] whether or not the email was sent
21
+ attr_reader :email_sent
22
+
23
+ # @return [Boolean] whether or not the origin is rural
24
+ attr_reader :origin_is_rural
25
+
26
+ # @return [Boolean] whether or not the destination is rural
27
+ attr_reader :destination_is_rural
28
+
29
+ # @return [Array<Hash>] the rates
30
+ attr_reader :rates
31
+
32
+ # @return [Money] the total charges for this shipment
33
+ attr_reader :total_charges
34
+
35
+ # @return [Measured::Weight] the billable weight for this shipment
36
+ attr_reader :billable_weight
37
+
38
+ # @return [Integer] the number of days in transit
39
+ attr_reader :days_in_transit
40
+
41
+ # @return [Array<ShipmentDocument>] the shipment's documents (BOL, labels, etc)
42
+ attr_reader :documents
43
+
44
+ # @return [ShippingMethod] the shipping method
45
+ attr_reader :shipping_method
46
+
47
+ # @return [Array<String>] any warnings
48
+ attr_reader :warnings
49
+
50
+ # @return [Hash] any additional data
51
+ attr_reader :data
52
+
53
+ # @param bol_id [String] the shipment's BOL ID number
54
+ # @param pro_number [String] the shipment's PRO number
55
+ # @param pickup_confirmation_number [String] the shipment's pickup confirmation number
56
+ # @param origin_service_center [String] the origin service center
57
+ # @param email_sent [Boolean] whether or not the email was sent
58
+ # @param origin_is_rural [Boolean] whether or not the origin is rural
59
+ # @param destination_is_rural [Boolean] whether or not the destination is rural
60
+ # @param rates [Array<Hash>] the rates
61
+ # @param total_charges [Money] the total charges for this shipment
62
+ # @param billable_weight [Measured::Weight] the billable weight for this shipment
63
+ # @param days_in_transit [Integer] the number of days in transit
64
+ # @param documents [Array<ShipmentDocument>] the shipment's documents (BOL, labels, etc)
65
+ # @param shipping_method [ShippingMethod] the shipping method
66
+ # @param warnings [Array<String>] any warnings
67
+ # @param data [Hash] any additional data
68
+ def initialize(
69
+ bol_id:,
70
+ pro_number: nil,
71
+ pickup_confirmation_number: nil,
72
+ origin_service_center: nil,
73
+ email_sent: nil,
74
+ origin_is_rural: nil,
75
+ destination_is_rural: nil,
76
+ rates: [],
77
+ total_charges: nil,
78
+ billable_weight: nil,
79
+ days_in_transit: nil,
80
+ documents: [],
81
+ shipping_method: nil,
82
+ warnings: nil,
83
+ data: {}
84
+ )
85
+ @bol_id = bol_id
86
+ @pro_number = pro_number
87
+ @pickup_confirmation_number = pickup_confirmation_number
88
+ @origin_service_center = origin_service_center
89
+ @email_sent = email_sent
90
+ @origin_is_rural = origin_is_rural
91
+ @destination_is_rural = destination_is_rural
92
+ @rates = rates
93
+ @total_charges = total_charges
94
+ @billable_weight = billable_weight
95
+ @days_in_transit = days_in_transit
96
+ @documents = documents
97
+ @shipping_method = shipping_method
98
+ @warnings = warnings
99
+ @data = data
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
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: RatesPackageOptions))
20
+ end
21
+
22
+ # @param structure [#id]
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,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
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', 'TForce Freight LTL'],
12
+ ['309', 'TForce Freight LTL - Guaranteed'],
13
+ ['334', 'TForce Freight LTL - Guaranteed A.M.'],
14
+ ['349', 'TForce 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
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FriendlyShipping
4
+ module Services
5
+ class TForceFreight
6
+ # Options for structures/pallets within a TForce Freight shipment.
7
+ class StructureOptions < FriendlyShipping::StructureOptions
8
+ # Maps friendly names to handling unit types.
9
+ HANDLING_UNIT_TYPES = {
10
+ pallet: { code: "PLT", description: "Pallet", handling_unit_tag: 'One' },
11
+ skid: { code: "SKD", description: "Skid", handling_unit_tag: 'One' },
12
+ carboy: { code: "CBY", description: "Carboy", handling_unit_tag: 'One' },
13
+ totes: { code: "TOT", description: "Totes", handling_unit_tag: 'One' },
14
+ other: { code: "OTH", description: "Other", handling_unit_tag: 'Two' },
15
+ loose: { code: "LOO", description: "Loose", handling_unit_tag: 'Two' }
16
+ }.freeze
17
+
18
+ # @return [String]
19
+ attr_reader :handling_unit_description
20
+
21
+ # @return [String]
22
+ attr_reader :handling_unit_tag
23
+
24
+ # @return [String]
25
+ attr_reader :handling_unit_code
26
+
27
+ # @param handling_unit [Symbol] how this shipment is divided (see {HANDLING_UNIT_TYPES})
28
+ # @param kwargs [Hash]
29
+ # @options kwargs [Object] :structure_id unique identifier for this set of options
30
+ # @options kwargs [Array<PackageOptions>] :package_options the options for packages in this structure
31
+ # @options kwargs [Class] :package_options_class the class to use for package options when none are provided
32
+ def initialize(
33
+ handling_unit: :pallet,
34
+ **kwargs
35
+ )
36
+ @handling_unit_code = HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:code)
37
+ @handling_unit_description = HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:description)
38
+ @handling_unit_tag = "handlingUnit#{HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:handling_unit_tag)}"
39
+ super(**kwargs.reverse_merge(package_options_class: RatesPackageOptions))
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end