class FriendlyShipping::Services::UpsFreight

Constants

CARRIER
LIVE_URL
ORIGIN_COUNTRIES
RESOURCES
SHIPPING_METHODS
TEST_URL

Attributes

client[R]
key[R]
login[R]
password[R]
test[R]

Public Class Methods

new(key:, login:, password:, test: true, client: HttpClient.new(error_handler: RestfulApiErrorHandler)) click to toggle source
# File lib/friendly_shipping/services/ups_freight.rb, line 45
def initialize(key:, login:, password:, test: true, client: HttpClient.new(error_handler: RestfulApiErrorHandler))
  @key = key
  @login = login
  @password = password
  @test = test
  @client = client
end

Public Instance Methods

carriers() click to toggle source
# File lib/friendly_shipping/services/ups_freight.rb, line 53
def carriers
  Success([CARRIER])
end
labels(shipment, options:, debug: false) click to toggle source

Get labels for a shipment @param [Physical::Shipment] shipment The shipment we want to get rates for @param [FriendlyShipping::Services::UpsFreight::LabelOptions] options Options for shipping this shipment. @return [Result<ApiResult<ShipmentInformation>] The information that you need for shipping this shipment.

# File lib/friendly_shipping/services/ups_freight.rb, line 75
def labels(shipment, options:, debug: false)
  freight_ship_request_hash = GenerateFreightShipRequestHash.call(shipment: shipment, options: options)
  request = build_request(:labels, freight_ship_request_hash, debug)

  client.post(request).fmap do |response|
    ParseFreightLabelResponse.call(response: response, request: request)
  end
end
rate_estimates(shipment, options:, debug: false) click to toggle source

Get rates for a shipment @param [Physical::Shipment] shipment The shipment we want to get rates for @param [FriendlyShipping::Services::UpsFreight::RatesOptions] options Options for obtaining rates for this shipment. @return [Result<ApiResult<Array<Rate>>>] The rates returned from UPS encoded in a

`FriendlyShipping::ApiResult` object.
# File lib/friendly_shipping/services/ups_freight.rb, line 62
def rate_estimates(shipment, options:, debug: false)
  freight_rate_request_hash = GenerateFreightRateRequestHash.call(shipment: shipment, options: options)
  request = build_request(:rates, freight_rate_request_hash, debug)

  client.post(request).fmap do |response|
    ParseFreightRateResponse.call(response: response, request: request)
  end
end

Private Instance Methods

base_url() click to toggle source
# File lib/friendly_shipping/services/ups_freight.rb, line 102
def base_url
  test ? TEST_URL : LIVE_URL
end
build_request(action, payload, debug) click to toggle source
# File lib/friendly_shipping/services/ups_freight.rb, line 86
def build_request(action, payload, debug)
  url = base_url + RESOURCES[action]
  FriendlyShipping::Request.new(
    url: url,
    body: payload.to_json,
    headers: {
      Content_Type: 'application/json',
      Accept: 'application/json',
      Username: login,
      Password: password,
      AccessLicenseNumber: key
    },
    debug: debug
  )
end