def call_xavier_api(original, target)

      # Check if there is any cached XML for the specified date
      if defined?(Rails)
        parsed_response = Rails.cache.read("xaviermedia_#{stringified_exchange_date}")
      end

      unless parsed_response # Unless there is a cached XML response, ask for it
        retries = 10
        not_found_retries=10
        xml_response = nil
        begin
          # Returns the raw response or
          # raises OpenURI::HTTPError when no data available
          Timeout::timeout(1) { xml_response = make_call(@exchange_date) || nil }
        rescue Timeout::Error
          retries -= 1
          retries > 0 ? sleep(0.42) && retry : raise
        rescue OpenURI::HTTPError # Try to fetch one day and 2 days earlier
          not_found_retries -= 1
          if not_found_retries >= 0
            @exchange_date = (Time.parse(@exchange_date.to_s) - 86400).send(:to_date)
            retry
          else
            raise NotFoundError.new("404 Not Found")
          end
        rescue SocketError
          raise NotFoundError.new("Socket Error")
        end

        return nil unless xml_response && parsed_response = Crack::XML.parse(xml_response)["xavierresponse"]["exchange_rates"]["fx"]

        # Cache successful XML response for later reuse
        if defined?(Rails)
          Rails.cache.write("xaviermedia_#{stringified_exchange_date}", parsed_response)
        end
      end

      calculate_rate(parsed_response, original, target)
    end
def call_xavier_api(original, target)

      # Check if there is any cached XML for the specified date
      if defined?(Rails)
        parsed_response = Rails.cache.read("xaviermedia_#{stringified_exchange_date}")
      end

      unless parsed_response # Unless there is a cached XML response, ask for it
        retries = 10
        not_found_retries=10
        xml_response = nil
        begin
          # Returns the raw response or
          # raises OpenURI::HTTPError when no data available
          Timeout::timeout(1) { xml_response = make_call(@exchange_date) || nil }
        rescue Timeout::Error
          retries -= 1
          retries > 0 ? sleep(0.42) && retry : raise
        rescue OpenURI::HTTPError # Try to fetch one day and 2 days earlier
          not_found_retries -= 1
          if not_found_retries >= 0
            @exchange_date = (Time.parse(@exchange_date.to_s) - 86400).send(:to_date)
            retry
          else
            raise NotFoundError.new("404 Not Found")
          end
        rescue SocketError
          raise NotFoundError.new("Socket Error")
        end

        return nil unless xml_response && parsed_response = Crack::XML.parse(xml_response)["xavierresponse"]["exchange_rates"]["fx"]

        # Cache successful XML response for later reuse
        if defined?(Rails)
          Rails.cache.write("xaviermedia_#{stringified_exchange_date}", parsed_response)
        end
      end

      calculate_rate(parsed_response, original, target)
    end
Calls Xavier API to perform the exchange with a specific date.
 This method is called when using :at method, like this:

   30.eur.at(1.year.ago).to_usd