def attempt(tries, &blk)
      if tries
        raise ArgumentError unless tries > 0
      else
        tries ||= @attempts
      end

      attempt = 1

      while true
        begin
          return yield blk
        rescue Errno::ECONNREFUSED, HTTPClient::TimeoutError,
               CorruptResult => e
          raise e if attempt == tries
          sleep 2 ** attempt
          attempt += 1
        end
      end
    end
def attempt(tries, &blk)
      if tries
        raise ArgumentError unless tries > 0
      else
        tries ||= @attempts
      end

      attempt = 1

      while true
        begin
          return yield blk
        rescue Errno::ECONNREFUSED, HTTPClient::TimeoutError,
               CorruptResult => e
          raise e if attempt == tries
          sleep 2 ** attempt
          attempt += 1
        end
      end
    end
Executes a block. If there is a connection- or corruption-related exception
 the block will be reexecuted up to the `tries' argument. It will sleep
 for an exponentially-increasing number of seconds between retries.