class ActiveShipping::VALKEN
Public Instance Methods
filter_rates(rates)
click to toggle source
# File lib/active_shipping/carriers/valken.rb, line 51 def filter_rates(rates) filtered_rates = [] # find and sort all delivery dates and pick 1st three all_delivery_dates = rates.map { |rate| rate.delivery_date } # sorting the uniq delivery dates and reversing those delivery dates. uniq_delivery_dates = all_delivery_dates.compact.sort.uniq[0..2] # For each delivery dates, find cheapest rates and create shipping option and push uniq_delivery_dates.each_with_index do |date, index| selected_rates = rates.select {|rate| rate.delivery_date.present? && rate.delivery_date == date} cheap_rate = selected_rates.sort_by(&:price).first filtered_rates.push(cheap_rate) end if filtered_rates[-1].present? filtered_rates[-1].service_name = "Valken Express 3-Day" filtered_rates[-1].description = "3 Business Days" end if filtered_rates[-2].present? filtered_rates[-2].service_name = "Valken Express 2-Day" filtered_rates[-2].description = "2 Business Days" end if filtered_rates[-3].present? filtered_rates[-3].service_name = "Valken Overnight" filtered_rates[-3].description = "Overnight" end return filtered_rates end
find_rates(origin, destination, packages, options = {})
click to toggle source
Calls superclass method
# File lib/active_shipping/carriers/valken.rb, line 6 def find_rates(origin, destination, packages, options = {}) if options[:ground] || (::Workarea.config.default_shipping) return get_workarea_services(origin, destination, packages, options) end super end
get_workarea_services(*args)
click to toggle source
# File lib/active_shipping/carriers/valken.rb, line 47 def get_workarea_services(*args) ::Workarea::Shipping::RateLookup.new(*args).response end
parse_rate_response(origin, destination, packages, response, options = {})
click to toggle source
# File lib/active_shipping/carriers/valken.rb, line 13 def parse_rate_response(origin, destination, packages, response, options = {}) xml = build_document(response, 'RatingServiceSelectionResponse') success = response_success?(xml) message = response_message(xml) filtered_rates = [] if success rate_estimates = xml.root.css('> RatedShipment').map do |rated_shipment| service_code = rated_shipment.at('Service/Code').text days_to_delivery = rated_shipment.at('GuaranteedDaysToDelivery').text.to_i days_to_delivery = nil if days_to_delivery == 0 warning_messages = rate_warning_messages(rated_shipment) RateEstimate.new(origin, destination, @@name, service_name_for(origin, service_code), total_price: rated_shipment.at('TotalCharges/MonetaryValue').text.to_f, insurance_price: rated_shipment.at('ServiceOptionsCharges/MonetaryValue').text.to_f, currency: rated_shipment.at('TotalCharges/CurrencyCode').text, service_code: service_code, packages: packages, delivery_range: [timestamp_from_business_day(days_to_delivery)], negotiated_rate: rated_shipment.at('NegotiatedRates/NetSummaryCharges/GrandTotal/MonetaryValue').try(:text).to_f, messages: warning_messages ) end filtered_rates = filter_rates(rate_estimates) end workarea_rates = get_workarea_services(origin, destination, packages, options).rates if message.include?("Failure: Maximum number of packages exceeded") RateResponse.new(true, "Only workarea shipping service", {}, rates: workarea_rates, xml: "", request: "") else RateResponse.new(success, message, Hash.from_xml(response).values.first, rates:(filtered_rates + workarea_rates).flatten, xml: response, request: last_request) end end
weight_convertion(packages)
click to toggle source
# File lib/active_shipping/carriers/valken.rb, line 83 def weight_convertion(packages) full_weight = 0 packages.each do |item_package| new_weight = item_package.weight.convert_to(:lb) full_weight += new_weight.value end full_weight end