Sha256: 2615e2da43f13d817238606c09d2eb794fac83526ca5cf44013fb77823551fde
Contents?: true
Size: 1.21 KB
Versions: 2
Compression:
Stored size: 1.21 KB
Contents
# The time a 3rd-party shipping provider takes to respond to a request varies greatly. # This class simulates these unpredictable delays in shipping rate retrieval so that # load-testing tools run into situations that more accurately reflect the real world. module ActiveMerchant module Shipping class BenchmarkCarrier < Carrier cattr_reader :name @@name = "Benchmark Carrier" def find_rates(origin, destination, packages, options = {}) origin = Location.from(origin) destination = Location.from(destination) packages = Array(packages) delay_time = generate_simulated_lag bogus_estimate = RateEstimate.new( origin, destination, @@name, "Free Benchmark Shipping", :total_price => 0, :currency => 'USD', :packages => packages, :delivery_range => [Time.now.utc.strftime("%Y-%d-%m"), Time.now.utc.strftime("%Y-%d-%m")] ) RateResponse.new(true, "Success (delayed #{delay_time} seconds)", {:rate => 'free'}, :rates => [bogus_estimate], :xml => "<rate>free</rate>") end private def generate_simulated_lag(max_delay = 30) sleep Random.rand * max_delay end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_shipping-0.12.6 | lib/active_shipping/shipping/carriers/benchmark_carrier.rb |
active_shipping-0.12.5 | lib/active_shipping/shipping/carriers/benchmark_carrier.rb |