Class: FriendlyShipping::Services::UpsFreight
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::UpsFreight
- Defined in:
- lib/friendly_shipping/services/ups_freight.rb,
lib/friendly_shipping/services/ups_freight/api_error.rb,
lib/friendly_shipping/services/ups_freight/label_options.rb,
lib/friendly_shipping/services/ups_freight/rates_options.rb,
lib/friendly_shipping/services/ups_freight/shipping_methods.rb,
lib/friendly_shipping/services/ups_freight/shipment_document.rb,
lib/friendly_shipping/services/ups_freight/label_item_options.rb,
lib/friendly_shipping/services/ups_freight/rates_item_options.rb,
lib/friendly_shipping/services/ups_freight/label_email_options.rb,
lib/friendly_shipping/services/ups_freight/label_pickup_options.rb,
lib/friendly_shipping/services/ups_freight/shipment_information.rb,
lib/friendly_shipping/services/ups_freight/label_package_options.rb,
lib/friendly_shipping/services/ups_freight/rates_package_options.rb,
lib/friendly_shipping/services/ups_freight/generate_location_hash.rb,
lib/friendly_shipping/services/ups_freight/label_delivery_options.rb,
lib/friendly_shipping/services/ups_freight/label_document_options.rb,
lib/friendly_shipping/services/ups_freight/pickup_request_options.rb,
lib/friendly_shipping/services/ups_freight/generate_reference_hash.rb,
lib/friendly_shipping/services/ups_freight/parse_shipment_document.rb,
lib/friendly_shipping/services/ups_freight/generate_email_options_hash.rb,
lib/friendly_shipping/services/ups_freight/parse_freight_rate_response.rb,
lib/friendly_shipping/services/ups_freight/generate_pickup_options_hash.rb,
lib/friendly_shipping/services/ups_freight/generate_pickup_request_hash.rb,
lib/friendly_shipping/services/ups_freight/parse_freight_label_response.rb,
lib/friendly_shipping/services/ups_freight/generate_commodity_information.rb,
lib/friendly_shipping/services/ups_freight/generate_delivery_options_hash.rb,
lib/friendly_shipping/services/ups_freight/generate_document_options_hash.rb,
lib/friendly_shipping/services/ups_freight/generate_freight_rate_request_hash.rb,
lib/friendly_shipping/services/ups_freight/generate_freight_ship_request_hash.rb
Defined Under Namespace
Classes: ApiError, GenerateCommodityInformation, GenerateDeliveryOptionsHash, GenerateDocumentOptionsHash, GenerateEmailOptionsHash, GenerateFreightRateRequestHash, GenerateFreightShipRequestHash, GenerateLocationHash, GeneratePickupOptionsHash, GeneratePickupRequestHash, GenerateReferenceHash, LabelDeliveryOptions, LabelDocumentOptions, LabelEmailOptions, LabelItemOptions, LabelOptions, LabelPackageOptions, LabelPickupOptions, ParseFreightLabelResponse, ParseFreightRateResponse, ParseShipmentDocument, PickupRequestOptions, RatesItemOptions, RatesOptions, RatesPackageOptions, ShipmentDocument, ShipmentInformation
Constant Summary collapse
- CARRIER =
FriendlyShipping::Carrier.new( id: 'ups_freight', name: 'United Parcel Service LTL', code: 'ups-freight', shipping_methods: SHIPPING_METHODS )
- TEST_URL =
'https://wwwcie.ups.com'
- LIVE_URL =
'https://onlinetools.ups.com'
- RESOURCES =
{ rates: '/ship/v1801/freight/rating/ground', labels: '/ship/v1607/freight/shipments/Ground' }.freeze
- ORIGIN_COUNTRIES =
%w( CA MX PR US ).map { |country_code| Carmen::Country.coded(country_code) }.freeze
- SHIPPING_METHODS =
[ ['308', 'UPS Freight LTL'], ['309', 'UPS Freight LTL - Guaranteed'], ['334', 'UPS Freight LTL - Guaranteed A.M.'], ['349', 'UPS Standard LTL'] ].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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Instance Method Summary collapse
- #carriers ⇒ Object
-
#initialize(key:, login:, password:, test: true, client: nil) ⇒ UpsFreight
constructor
A new instance of UpsFreight.
-
#labels(shipment, options:, debug: false) ⇒ Result<ApiResult<ShipmentInformation>] The information that you need for shipping this shipment.
Get labels for a shipment.
-
#rate_estimates(shipment, options:, debug: false) ⇒ Result<ApiResult<Array<Rate>>>
Get rates for a shipment.
Constructor Details
#initialize(key:, login:, password:, test: true, client: nil) ⇒ UpsFreight
Returns a new instance of UpsFreight.
45 46 47 48 49 50 51 52 53 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 45 def initialize(key:, login:, password:, test: true, client: nil) @key = key @login = login @password = password @test = test error_handler = ApiErrorHandler.new(api_error_class: UpsFreight::ApiError) @client = client || HttpClient.new(error_handler: error_handler) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
28 29 30 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 28 def client @client end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
28 29 30 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 28 def key @key end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
28 29 30 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 28 def login @login end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
28 29 30 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 28 def password @password end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
28 29 30 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 28 def test @test end |
Instance Method Details
#carriers ⇒ Object
55 56 57 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 55 def carriers Success([CARRIER]) end |
#labels(shipment, options:, debug: false) ⇒ Result<ApiResult<ShipmentInformation>] The information that you need for shipping this shipment.
Get labels for a shipment
77 78 79 80 81 82 83 84 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 77 def labels(shipment, options:, debug: false) freight_ship_request_hash = GenerateFreightShipRequestHash.call(shipment: shipment, 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) ⇒ Result<ApiResult<Array<Rate>>>
Get rates for a shipment
64 65 66 67 68 69 70 71 |
# File 'lib/friendly_shipping/services/ups_freight.rb', line 64 def rate_estimates(shipment, options:, debug: false) freight_rate_request_hash = GenerateFreightRateRequestHash.call(shipment: shipment, options: ) request = build_request(:rates, freight_rate_request_hash, debug) client.post(request).fmap do |response| ParseFreightRateResponse.call(response: response, request: request) end end |