Class: FriendlyShipping::Services::RL

Inherits:
Object
  • Object
show all
Includes:
Dry::Monads::Result::Mixin
Defined in:
lib/friendly_shipping/services/rl.rb,
lib/friendly_shipping/services/rl/api_error.rb,
lib/friendly_shipping/services/rl/bol_options.rb,
lib/friendly_shipping/services/rl/item_options.rb,
lib/friendly_shipping/services/rl/package_options.rb,
lib/friendly_shipping/services/rl/shipment_options.rb,
lib/friendly_shipping/services/rl/shipping_methods.rb,
lib/friendly_shipping/services/rl/shipment_document.rb,
lib/friendly_shipping/services/rl/structure_options.rb,
lib/friendly_shipping/services/rl/rate_quote_options.rb,
lib/friendly_shipping/services/rl/serialize_location.rb,
lib/friendly_shipping/services/rl/shipment_information.rb,
lib/friendly_shipping/services/rl/parse_invoice_response.rb,
lib/friendly_shipping/services/rl/bol_packages_serializer.rb,
lib/friendly_shipping/services/rl/parse_print_bol_response.rb,
lib/friendly_shipping/services/rl/bol_structures_serializer.rb,
lib/friendly_shipping/services/rl/parse_create_bol_response.rb,
lib/friendly_shipping/services/rl/parse_rate_quote_response.rb,
lib/friendly_shipping/services/rl/parse_transit_times_response.rb,
lib/friendly_shipping/services/rl/serialize_create_bol_request.rb,
lib/friendly_shipping/services/rl/serialize_rate_quote_request.rb,
lib/friendly_shipping/services/rl/rate_quote_packages_serializer.rb,
lib/friendly_shipping/services/rl/serialize_transit_times_request.rb,
lib/friendly_shipping/services/rl/rate_quote_structures_serializer.rb,
lib/friendly_shipping/services/rl/parse_print_shipping_labels_response.rb

Overview

API service class for R+L Carriers, a freight/LTL carrier.

See Also:

Defined Under Namespace

Classes: ApiError, BOLOptions, BOLPackagesSerializer, BOLStructuresSerializer, ItemOptions, PackageOptions, ParseCreateBOLResponse, ParseInvoiceResponse, ParsePrintBOLResponse, ParsePrintShippingLabelsResponse, ParseRateQuoteResponse, ParseTransitTimesResponse, RateQuoteOptions, RateQuotePackagesSerializer, RateQuoteStructuresSerializer, SerializeCreateBOLRequest, SerializeLocation, SerializeRateQuoteRequest, SerializeTransitTimesRequest, ShipmentDocument, ShipmentInformation, ShipmentOptions, StructureOptions

Constant Summary collapse

LIVE_API_BASE =

The API base URL for production.

"https://api.rlc.com/"
TEST_API_BASE =

The API base URL for testing.

"https://apisandbox.rlc.com/"
API_PATHS =

This carrier's API paths. Used when constructing endpoint URLs.

{
  bill_of_lading: "BillOfLading",
  documents: "DocumentRetrieval",
  print_bol: "BillOfLading/PrintBOL",
  print_shipping_labels: "BillOfLading/PrintShippingLabels",
  rate_quote: "RateQuote",
  transit_times: "TransitTimes"
}.freeze
ORIGIN_COUNTRIES =

Available origin countries for R+L shipments.

%w[
  AG BB CA DO GU GY JM PR VC TT US VG VI
].map { |country_code| Carmen::Country.coded(country_code) }.freeze
SHIPPING_METHODS =

Available R+L shipping methods.

[
  ["STD", "Standard Service"],
  ["GSDS", "Guaranteed Service"],
  ["GSAM", "Guaranteed AM Service"],
  ["GSHW", "Guaranteed Hourly Window Service"],
  ["EXPD", "Expedited Service"]
].freeze.map do |code, name|
  FriendlyShipping::ShippingMethod.new(
    name: name,
    service_code: code,
    origin_countries: ORIGIN_COUNTRIES,
    multi_package: true
  ).freeze
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, test: true, client: nil) ⇒ RL

Returns a new instance of RL.

Parameters:

  • api_key (String)

    the API key for this carrier

  • test (Boolean) (defaults to: true)

    whether to use test API endpoints

  • client (HttpClient) (defaults to: nil)

    the HTTP client to use for requests



40
41
42
43
44
45
46
# File 'lib/friendly_shipping/services/rl.rb', line 40

def initialize(api_key:, test: true, client: nil)
  @api_key = api_key
  @test = test

  error_handler = ApiErrorHandler.new(api_error_class: RL::ApiError)
  @client = client || HttpClient.new(error_handler: error_handler)
end

Instance Attribute Details

#api_keyString (readonly)

Returns the API key for this carrier.

Returns:

  • (String)

    the API key for this carrier



13
14
15
# File 'lib/friendly_shipping/services/rl.rb', line 13

def api_key
  @api_key
end

#clientHttpClient (readonly)

Returns the HTTP client to use for requests.

Returns:

  • (HttpClient)

    the HTTP client to use for requests



19
20
21
# File 'lib/friendly_shipping/services/rl.rb', line 19

def client
  @client
end

#testBoolean (readonly)

Returns whether to use test API endpoints.

Returns:

  • (Boolean)

    whether to use test API endpoints



16
17
18
# File 'lib/friendly_shipping/services/rl.rb', line 16

def test
  @test
end

Instance Method Details

#create_bill_of_lading(shipment, options:, debug: false) ⇒ Success<ApiResult<ShipmentInformation>>, Failure<ApiResult>

Create an LTL Bill of Lading (BOL) and schedule a pickup with R+L Carriers.

Parameters:

  • shipment (Physical::Shipment)

    the shipment for the BOL

  • options (BOLOptions)

    the options for the BOL

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/friendly_shipping/services/rl.rb', line 53

def create_bill_of_lading(shipment, options:, debug: false)
  request = FriendlyShipping::Request.new(
    url: api_base + API_PATHS[:bill_of_lading],
    http_method: "POST",
    body: SerializeCreateBOLRequest.call(shipment: shipment, options: options).to_json,
    headers: request_headers,
    debug: debug
  )
  client.post(request).bind do |response|
    ParseCreateBOLResponse.call(request: request, response: response)
  end
end

#get_invoice(pro_number, debug: false) ⇒ Result<ApiResult<ShipmentDocument>>

Retrieve an existing binary Invoice

Parameters:

  • pro_number (String)

    The PRO number for the Invoice

Returns:



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/friendly_shipping/services/rl.rb', line 157

def get_invoice(pro_number, debug: false)
  request = FriendlyShipping::Request.new(
    url: api_base + API_PATHS[:documents] + "?ProNumber=#{pro_number}&DocumentTypes=Invoice&MediaType=PDF",
    http_method: "GET",
    headers: request_headers,
    debug: debug
  )
  client.get(request).bind do |response|
    ParseInvoiceResponse.call(request: request, response: response)
  end
end

Retrieve an existing binary LTL Bill of Lading (BOL) document for printing. The BOL is appended to the ShipmentInformation object's documents array.

Parameters:

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/friendly_shipping/services/rl.rb', line 71

def print_bill_of_lading(shipment_info, debug: false)
  request = FriendlyShipping::Request.new(
    url: api_base + API_PATHS[:print_bol] + "?ProNumber=#{shipment_info.pro_number}",
    http_method: "GET",
    headers: request_headers,
    debug: debug
  )
  client.get(request).bind do |response|
    ParsePrintBOLResponse.call(request: request, response: response).bind do |api_result|
      shipment_info.documents << api_result.data
      Success(api_result)
    end
  end
end

Retrieve binary LTL shipping label documents for printing. The label documents are appended to the ShipmentInformation object's documents array.

Parameters:

  • shipment_info (ShipmentInformation)

    the shipment for the labels

  • style (Integer) (defaults to: 1)

    the R+L Carriers shipping label style (between 1 and 13)

  • start_position (Integer) (defaults to: 1)

    the R+L Carriers start position for the first label (between 1 and 10)

  • num_labels (Integer) (defaults to: 4)

    number of labels to print (between 1 and 100)

Returns:

See Also:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/friendly_shipping/services/rl.rb', line 95

def print_shipping_labels(shipment_info, style: 1, start_position: 1, num_labels: 4, debug: false)
  request = FriendlyShipping::Request.new(
    url: api_base + API_PATHS[:print_shipping_labels] +
      "?ProNumber=#{shipment_info.pro_number}&" \
      "Style=#{style}&" \
      "StartPosition=#{start_position}&" \
      "NumberOfLabels=#{num_labels}",
    http_method: "GET",
    headers: request_headers,
    debug: debug
  )
  client.get(request).bind do |response|
    ParsePrintShippingLabelsResponse.call(request: request, response: response).bind do |api_result|
      shipment_info.documents << api_result.data
      Success(api_result)
    end
  end
end

#rate_quote(shipment, options:, debug: false) ⇒ Result<ApiResult<Array<Rate>>>

Request an LTL shipping rate quote from R+L Carriers.

Parameters:

  • shipment (Physical::Shipment)

    the shipment to quote

  • options (RateQuoteOptions)

    the options for the quote

Returns:

  • (Result<ApiResult<Array<Rate>>>)

    the rate quote from R+L Carriers



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/friendly_shipping/services/rl.rb', line 120

def rate_quote(shipment, options:, debug: false)
  request = FriendlyShipping::Request.new(
    url: LIVE_API_BASE + API_PATHS[:rate_quote],
    http_method: "POST",
    body: SerializeRateQuoteRequest.call(shipment: shipment, options: options).to_json,
    headers: request_headers,
    debug: debug
  )
  client.post(request).bind do |response|
    ParseRateQuoteResponse.call(request: request, response: response)
  end
end

#transit_times(shipment, options:, debug: false) ⇒ Result<ApiResult<Array<Timing>>>

Request an LTL shipment transit timing from R+L Carriers.

Parameters:

  • shipment (Physical::Shipment)

    the shipment we're timing

  • options (RateQuoteOptions)

    the options for the timing

Returns:

  • (Result<ApiResult<Array<Timing>>>)

    the transit timing from R+L Carriers



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/friendly_shipping/services/rl.rb', line 139

def transit_times(shipment, options:, debug: false)
  request = FriendlyShipping::Request.new(
    url: LIVE_API_BASE + API_PATHS[:transit_times],
    http_method: "POST",
    body: SerializeTransitTimesRequest.call(shipment: shipment, options: options).to_json,
    headers: request_headers,
    debug: debug
  )
  client.post(request).bind do |response|
    ParseTransitTimesResponse.call(request: request, response: response)
  end
end