Class: FriendlyShipping::Services::ShipEngineLTL
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::ShipEngineLTL
- Includes:
- Dry::Monads::Result::Mixin
- Defined in:
- lib/friendly_shipping/services/ship_engine_ltl.rb,
lib/friendly_shipping/services/ship_engine_ltl/api_error.rb,
lib/friendly_shipping/services/ship_engine_ltl/item_options.rb,
lib/friendly_shipping/services/ship_engine_ltl/quote_options.rb,
lib/friendly_shipping/services/ship_engine_ltl/package_options.rb,
lib/friendly_shipping/services/ship_engine_ltl/shipment_options.rb,
lib/friendly_shipping/services/ship_engine_ltl/structure_options.rb,
lib/friendly_shipping/services/ship_engine_ltl/serialize_packages.rb,
lib/friendly_shipping/services/ship_engine_ltl/parse_quote_response.rb,
lib/friendly_shipping/services/ship_engine_ltl/serialize_structures.rb,
lib/friendly_shipping/services/ship_engine_ltl/parse_carrier_response.rb,
lib/friendly_shipping/services/ship_engine_ltl/serialize_quote_request.rb
Overview
API service class for ShipEngine LTL, a shipping API supporting Freight carriers.
Defined Under Namespace
Classes: ApiError, ItemOptions, PackageOptions, ParseCarrierResponse, ParseQuoteResponse, QuoteOptions, SerializePackages, SerializeQuoteRequest, SerializeStructures, ShipmentOptions, StructureOptions
Constant Summary collapse
- API_BASE =
The API base URL.
"https://api.shipengine.com/v-beta/ltl/"
- API_PATHS =
The API paths. Used when constructing endpoint URLs.
{ connections: "connections", carriers: "carriers", quotes: "quotes" }.freeze
Instance Method Summary collapse
-
#carriers(debug: false) ⇒ Success<ApiResult<Array<Carrier>>>, Failure<ApiResult<Array<String>>>
Get configured LTL carriers.
-
#connect_carrier(credentials, scac, debug: false) ⇒ Success<ApiResult<Hash>>, Failure<ApiResult<String>>
Connect an LTL carrier.
-
#initialize(token:, test: true, client: nil) ⇒ ShipEngineLTL
constructor
A new instance of ShipEngineLTL.
-
#request_quote(carrier_id, shipment, options, debug: false) ⇒ Success<ApiResult<Hash>>, Failure<ApiResult<String>>
Request an LTL price quote.
-
#update_carrier(credentials, scac, carrier_id, debug: false) ⇒ Success<ApiResult<Hash>>, Failure<ApiResult<String>>
Update an existing LTL carrier.
Constructor Details
#initialize(token:, test: true, client: nil) ⇒ ShipEngineLTL
Returns a new instance of ShipEngineLTL.
25 26 27 28 29 30 31 |
# File 'lib/friendly_shipping/services/ship_engine_ltl.rb', line 25 def initialize(token:, test: true, client: nil) @token = token @test = test error_handler = ApiErrorHandler.new(api_error_class: ShipEngineLTL::ApiError) @client = client || HttpClient.new(error_handler: error_handler) end |
Instance Method Details
#carriers(debug: false) ⇒ Success<ApiResult<Array<Carrier>>>, Failure<ApiResult<Array<String>>>
Get configured LTL carriers.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/friendly_shipping/services/ship_engine_ltl.rb', line 38 def carriers(debug: false) request = FriendlyShipping::Request.new( url: API_BASE + API_PATHS[:carriers], headers: request_headers, debug: debug ) client.get(request).bind do |response| ParseCarrierResponse.call(request: request, response: response) end end |
#connect_carrier(credentials, scac, debug: false) ⇒ Success<ApiResult<Hash>>, Failure<ApiResult<String>>
Connect an LTL carrier.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/friendly_shipping/services/ship_engine_ltl.rb', line 56 def connect_carrier(credentials, scac, debug: false) request = FriendlyShipping::Request.new( url: API_BASE + API_PATHS[:connections] + "/#{scac}", body: { credentials: credentials }.to_json, headers: request_headers, debug: debug ) client.post(request).bind do |response| Success( ApiResult.new( JSON.parse(response.body), original_request: request, original_response: response ) ) end end |
#request_quote(carrier_id, shipment, options, debug: false) ⇒ Success<ApiResult<Hash>>, Failure<ApiResult<String>>
Request an LTL price quote.
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/friendly_shipping/services/ship_engine_ltl.rb', line 107 def request_quote(carrier_id, shipment, , debug: false) request = FriendlyShipping::Request.new( url: API_BASE + API_PATHS[:quotes] + "/#{carrier_id}", http_method: "POST", body: SerializeQuoteRequest.call(shipment: shipment, options: ).to_json, headers: request_headers, debug: debug ) client.post(request).bind do |response| ParseQuoteResponse.call(request: request, response: response) end end |
#update_carrier(credentials, scac, carrier_id, debug: false) ⇒ Success<ApiResult<Hash>>, Failure<ApiResult<String>>
Update an existing LTL carrier.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/friendly_shipping/services/ship_engine_ltl.rb', line 82 def update_carrier(credentials, scac, carrier_id, debug: false) request = FriendlyShipping::Request.new( url: API_BASE + API_PATHS[:connections] + "/#{scac}/#{carrier_id}", body: { credentials: credentials }.to_json, headers: request_headers, debug: debug ) client.put(request).bind do |response| Success( ApiResult.new( JSON.parse(response.body), original_request: request, original_response: response ) ) end end |