Method: Fedex::UpsInfo#getTransitTime

Defined in:
lib/ups/UpsInfo.rb

#getTransitTime(options) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ups/UpsInfo.rb', line 79

def getTransitTime(options)
  
  @url = options[:mode] == "production" ? PRODUCTION_URL : TEST_URL + '/TimeInTransit'
  #@url = options[:url] + '/TimeInTransit'
  # build our request xml
  pickup_date = calculate_pickup_date
  options[:pickup_date] = pickup_date.strftime('%Y%m%d')
  xml = @access_xml + generate_xml(build_transit_attributes(options))
  
  # attempt the request in a timeout
  delivery_dates = {}
  attempts = 0
  begin 
    Timeout.timeout(@timeout) do
      response = send_request(@url, xml)
      delivery_dates = response_to_map(response)
    end

  # We can only attempt to recover from Timeout errors, all other errors
  # should be raised back to the user
  rescue Timeout::Error => error
    if(attempts < @retry_count)
      attempts += 1
      retry

    else
      raise error
    end
  end

  delivery_dates
end