lib/friendly_shipping/services/ups.rb in friendly_shipping-0.4.6 vs lib/friendly_shipping/services/ups.rb in friendly_shipping-0.4.7
- old
+ new
@@ -6,20 +6,23 @@
require 'friendly_shipping/services/ups/serialize_city_state_lookup_request'
require 'friendly_shipping/services/ups/serialize_address_validation_request'
require 'friendly_shipping/services/ups/serialize_rating_service_selection_request'
require 'friendly_shipping/services/ups/serialize_shipment_accept_request'
require 'friendly_shipping/services/ups/serialize_shipment_confirm_request'
+require 'friendly_shipping/services/ups/serialize_time_in_transit_request'
require 'friendly_shipping/services/ups/serialize_void_shipment_request'
require 'friendly_shipping/services/ups/parse_address_validation_response'
require 'friendly_shipping/services/ups/parse_address_classification_response'
require 'friendly_shipping/services/ups/parse_city_state_lookup_response'
require 'friendly_shipping/services/ups/parse_rate_response'
require 'friendly_shipping/services/ups/parse_shipment_confirm_response'
require 'friendly_shipping/services/ups/parse_shipment_accept_response'
+require 'friendly_shipping/services/ups/parse_time_in_transit_response'
require 'friendly_shipping/services/ups/parse_void_shipment_response'
require 'friendly_shipping/services/ups/shipping_methods'
require 'friendly_shipping/services/ups/label_options'
+require 'friendly_shipping/services/ups/timing_options'
module FriendlyShipping
module Services
class Ups
include Dry::Monads::Result::Mixin
@@ -40,10 +43,11 @@
address_validation: '/ups.app/xml/XAV',
city_state_lookup: '/ups.app/xml/AV',
rates: '/ups.app/xml/Rate',
ship_confirm: '/ups.app/xml/ShipConfirm',
ship_accept: '/ups.app/xml/ShipAccept',
+ timings: '/ups.app/xml/TimeInTransit',
void: '/ups.app/xml/Void',
}.freeze
def initialize(key:, login:, password:, test: true, client: HttpClient.new)
@key = key
@@ -56,11 +60,11 @@
def carriers
Success([CARRIER])
end
# Get rates for a shipment
- # @param [Physical::Shipment] location The shipment we want to get rates for
+ # @param [Physical::Shipment] shipment The shipment we want to get rates for
# @return [Result<ApiResult<Array<Rate>>>] The rates returned from UPS encoded in a
# `FriendlyShipping::ApiResult` object.
def rate_estimates(shipment, debug: false)
rate_request_xml = SerializeRatingServiceSelectionRequest.call(shipment: shipment)
url = base_url + RESOURCES[:rates]
@@ -70,9 +74,30 @@
debug: debug
)
client.post(request).bind do |response|
ParseRateResponse.call(response: response, request: request, shipment: shipment)
+ end
+ end
+
+ # Get timing information for a shipment
+ # @param [Physical::Shipment] shipment The shipment we want to estimate timings for
+ # @param [FriendlyShipping::Services::Ups::TimingOptions] Options for this call
+ def timings(shipment, options:, debug: false)
+ time_in_transit_request_xml = SerializeTimeInTransitRequest.call(
+ shipment: shipment,
+ options: options
+ )
+ time_in_transit_url = base_url + RESOURCES[:timings]
+
+ request = FriendlyShipping::Request.new(
+ url: time_in_transit_url,
+ body: access_request_xml + time_in_transit_request_xml,
+ debug: debug
+ )
+
+ client.post(request).bind do |response|
+ ParseTimeInTransitResponse.call(response: response, request: request)
end
end
def labels(shipment, options:, debug: false)
## Method body starts