lib/shippinglogic/fedex/rate.rb in binarylogic-shippinglogic-1.0.0 vs lib/shippinglogic/fedex/rate.rb in binarylogic-shippinglogic-1.0.1

- old
+ new

@@ -85,11 +85,11 @@ # # to show accessor methods # rates.first.name # # => "First Overnight" class Rate < Service # Each rate result is an object of this class - class Rate; attr_accessor :name, :type, :saturday, :deadline, :rate, :currency; end + class Service; attr_accessor :name, :type, :saturday, :deadline, :rate, :currency; end VERSION = {:major => 6, :intermediate => 0, :minor => 0} # shipper options attribute :shipper_streets, :string @@ -108,11 +108,11 @@ attribute :recipient_residential, :boolean, :default => false # packaging options attribute :packaging_type, :string, :default => "YOUR_PACKAGING" attribute :package_count, :integer, :default => 1 - attribute :package_weight, :integer + attribute :package_weight, :float attribute :package_weight_units, :string, :default => "LB" attribute :package_length, :integer attribute :package_width, :integer attribute :package_height, :integer attribute :package_dimension_units, :string, :default => "IN" @@ -168,29 +168,32 @@ end end end def parse_response(response) + return [] if !response[:rate_reply_details] + response[:rate_reply_details].collect do |details| shipment_detail = details[:rated_shipment_details].is_a?(Array) ? details[:rated_shipment_details].first : details[:rated_shipment_details] cost = shipment_detail[:shipment_rate_detail][:total_net_charge] deadline = details[:delivery_timestamp] && Time.parse(details[:delivery_timestamp]) - next if delivery_deadline && !meets_deadline?(delivery_deadline) - - rate = Rate.new - rate.name = details[:service_type].titleize - rate.type = details[:service_type] - rate.saturday = details[:applied_options] == "SATURDAY_DELIVERY" - rate.deadline = details[:delivery_timestamp] && Time.parse(details[:delivery_timestamp]) - rate.rate = BigDecimal.new(cost[:amount]) - rate.currency = cost[:currency] - rate - end + if meets_deadline?(deadline) + service = Service.new + service.name = details[:service_type].titleize + service.type = details[:service_type] + service.saturday = details[:applied_options] == "SATURDAY_DELIVERY" + service.deadline = details[:delivery_timestamp] && Time.parse(details[:delivery_timestamp]) + service.rate = BigDecimal.new(cost[:amount]) + service.currency = cost[:currency] + service + end + end.compact end - def meets_deadline?(delivery_deadline) - !deadline || deadline > delivery_deadline + def meets_deadline?(deadline) + return true if !delivery_deadline + deadline && deadline <= delivery_deadline end end end end \ No newline at end of file