Skip to content

Commit

Permalink
Calculates UPS delivery date for rate estimates
Browse files Browse the repository at this point in the history
Closes Shopify#38
  • Loading branch information
Dennis O'Connor committed Jan 18, 2012
1 parent 5fa2892 commit 43082ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/active_shipping/shipping/carriers/ups.rb
Expand Up @@ -275,12 +275,16 @@ def parse_rate_response(origin, destination, packages, response, options={})

xml.elements.each('/*/RatedShipment') do |rated_shipment|
service_code = rated_shipment.get_text('Service/Code').to_s
days_to_delivery = rated_shipment.get_text('GuaranteedDaysToDelivery').to_s.to_i
delivery_date = days_to_delivery >= 1 ? days_to_delivery.days.from_now.strftime("%Y-%m-%d") : nil

rate_estimates << RateEstimate.new(origin, destination, @@name,
service_name_for(origin, service_code),
:total_price => rated_shipment.get_text('TotalCharges/MonetaryValue').to_s.to_f,
:currency => rated_shipment.get_text('TotalCharges/CurrencyCode').to_s,
:service_code => service_code,
:packages => packages)
:packages => packages,
:delivery_range => [delivery_date])
end
end
RateResponse.new(success, message, Hash.from_xml(response).values.first, :rates => rate_estimates, :xml => response, :request => last_request)
Expand Down
6 changes: 6 additions & 0 deletions test/unit/carriers/ups_test.rb
Expand Up @@ -71,6 +71,12 @@ def test_response_parsing
"UPS Next Day Air Early A.M.",
"UPS Next Day Air"], response.rates.map(&:service_name)
assert_equal [992, 2191, 3007, 5509, 9401, 6124], response.rates.map(&:price)

date_test = [nil, 3, 2, 1, 1, 1].map do |days|
DateTime.strptime(days.days.from_now.strftime("%Y-%m-%d"), "%Y-%m-%d") if days
end

assert_equal date_test, response.rates.map(&:delivery_date)
end

def test_maximum_weight
Expand Down

0 comments on commit 43082ce

Please sign in to comment.