Module: Workarea::LatestVersion

Defined in:
lib/workarea/latest_version.rb

Class Method Summary collapse

Class Method Details

.getObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/workarea/latest_version.rb', line 3

def self.get
  Rails.cache.fetch('workarea/version/latest', expires_in: 3.days) do
    request = Net::HTTP::Get.new('/api/v1/gems/workarea.json')
    request.content_type = 'application/json'

    uri = URI('https://rubygems.org')
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    response = http.start { |h| h.request(request) }

    JSON.parse(response.body)['version']
  end
rescue Exception => e
  Rails.logger.error '-------------------------------------'
  Rails.logger.error "There was an error contacting rubygems.org!"
  Rails.logger.error e.class
  Rails.logger.error e.message
  Rails.logger.error '-------------------------------------'
end