def check_version
last_check.clear if last_check['version'] != Travis::VERSION
seconds_since = Time.now.to_i - last_check['at'].to_i
return if skip_version_check?
return if seconds_since < MINUTE
case seconds_since
when MINUTE .. HOUR then timeout = 0.5
when HOUR .. DAY then timeout = 1.0
when DAY .. WEEK then timeout = 2.0
else timeout = 10.0
end
Timeout.timeout(timeout) do
response = Faraday.get('https://rubygems.org/api/v1/gems/travis.json', {}, 'If-None-Match' => last_check['etag'].to_s)
last_check['etag'] = response.headers['etag']
last_check['version'] = JSON.parse(response.body)['version'] if response.status == 200
end
last_check['at'] = Time.now.to_i
unless Tools::System.recent_version? Travis::VERSION, last_check['version']
warn "Outdated CLI version, run `gem install travis`."
end
rescue Timeout::Error, Faraday::Error::ClientError => error
debug "#{error.class}: #{error.message}"
end