0.0
The project is in a healthy, maintained state
Freight carrier API and website abstraction library for transportation management systems (TMS)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13.2.1
~> 3.6.0
~> 1.0.7
~> 0.9.28
~> 3.5.1
~> 3.12

Runtime

~> 0.13.0
>= 2.6.0, < 2.7.2
~> 0.10
>= 2.0, < 3.1.1
~> 0.4.3
~> 0.0.2
>= 7.0, < 7.4
>= 4.2, < 8.0.1
>= 4.2, < 7.2.3
>= 3.3.1, < 3.5.0
>= 1.6, < 1.17
>= 2.0, < 2.16
~> 1.2023, >= 1.2023.3
 Project Readme

FreightKit

This library interfaces with the web services of various shipping carriers. The goal is to abstract the features that are most frequently used into a pleasant and consistent Ruby API.

FreightKit supports:

  • Downloading scanned documents
  • Finding shipping rates
  • Tracking shipments

On a technical level it supports:

  • Abstracted accessorials
  • Abstracted tracking events
  • Cubic feet and density calculations
  • Freight class calculations (and manual overriding)

Definitions

Carrier: Has unique web services pertaining to whatever real-world services they provide.

Platform: Provides web-accessible services for many carriers at once.

Note: Carriers may extend Platforms and override them when their behavior differs from the Platform.

Plug-in System

FreightKit relies on plug-ins (gems) to define how it connects to individual Carriers and Platforms.

Installation

Using bundler, add to the Gemfile:

gem 'freight_kit'

Or standalone:

$ gem install freight_kit

Note: Plug-ins are required to connect to Carriers and Platforms (see above).

Standard Usage

Start off by initializing the Carrier provided by a Carrier plug-in:

require 'freight_kit'

# Typically just one `Credential` is required
credentials = [
  FreightKit::Credential.new(
    type: :api,
    account: 'account_number',
    username: 'username',
    password: 'password',
    tariff: FreightKit::Tariff.new # optional
  ),
  FreightKit::Credential.new(
    type: :oauth2,
    access_token: 'token',
    expires_at: DateTime.current + 1.day, # DateTime
    scope: 'scope'
  ),
  FreightKit::Credential.new(
    type: :website,
    username: 'username',
    password: 'password'
  ),
  FreightKit::Credential.new(
    type: :selenoid,
    base_url: URI.parse('http://domain:4444'),
    browser: :chrome
  )
]

carrier = FreightKit::SCAC.new(credentials)

Documents

carrier.bol(tracking_number) # BOL generated by carrier
carrier.scanned_bol(tracking_number) # BOL scanned by carrier

carrier.pod(tracking_number)

Tracking

tracking = carrier.find_tracking_info(tracking_number)

tracking.delivered?
tracking.status

tracking.shipment_events.each do |event|
  puts "#{event.name} at #{event.location.city}, #{event.location.state} on #{event.time}. #{event.message}"
end

Quoting

packages = [
  FreightKit::Package.new(
    371 * 16, # 371 lbs
    {
      length: 40, # inches
      width: 48,
      height: 47
    },
    units: :imperial
  ),
  FreightKit::Package.new(
    371 * 16, # 371 lbs
    {
      length: 40, # inches
      width: 48,
      height: 47
    },
    freight_class: 125, # override calculated freight class
    units: :imperial
  )
]

origin = FreightKit::Location.new(
  country: 'US',
  state: 'CA',
  city: 'Los Angeles',
  zip: '90001'
)

destination = FreightKit::Location.new(
  country: 'US',
  state: 'IL',
  city: 'Chicago',
  zip: '60007'
)

accessorials = %i[
  appointment_delivery
  liftgate_delivery
  residential_delivery
]

response = carrier.find_rates(origin, destination, packages, accessorials: accessorials)
rates = response.rates
rates = response.rates.sort_by(&:price).collect { |rate| [rate.service_name, rate.price] }