23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/friendly_shipping/services/ups_json/parse_timings_response.rb', line 23
def build_timings(timings_result, shipment)
service_timings = Array.wrap(timings_result.dig('emsResponse', 'services'))
service_timings.map do |timing|
service_description = timing['serviceLevelDescription']
shipping_method = SHIPPING_METHODS.detect do |potential_shipping_method|
service_description == potential_shipping_method.name &&
potential_shipping_method.origin_countries.map(&:code).include?(shipment.origin.country.code)
end
delivery_date = timing['deliveryDate']
delivery_time = timing['deliveryTime']
delivery = Time.parse("#{delivery_date} #{delivery_time}")
pickup_date = timing['pickupDate']
pickup_time = timing['pickupTime']
pickup = Time.parse("#{pickup_date} #{pickup_time}")
guaranteed = timing['guaranteeIndicator'] == '1'
business_transit_days = timing['businessTransitDays']
FriendlyShipping::Timing.new(
shipping_method: shipping_method,
pickup: pickup,
delivery: delivery,
guaranteed: guaranteed,
data: {
business_transit_days: business_transit_days
}
)
end
end
|