2020-01-13 17:05:53 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-26 10:19:43 +01:00
|
|
|
# Fab-manager central hub (remote host)
|
2020-01-13 17:05:53 +01:00
|
|
|
class FabHub
|
|
|
|
def self.version_check_payload
|
2020-05-13 15:02:03 +02:00
|
|
|
uuid = Setting.get('uuid')
|
2020-06-02 18:29:24 +02:00
|
|
|
origin = Setting.get('origin') || "#{Rails.application.secrets.default_protocol}://#{Rails.application.secrets.default_host}"
|
2020-01-13 17:05:53 +01:00
|
|
|
{
|
2020-04-07 17:53:19 +02:00
|
|
|
uuid: uuid,
|
|
|
|
origin: origin,
|
2020-01-13 17:05:53 +01:00
|
|
|
version: Version.current,
|
|
|
|
lang: I18n.default_locale.to_s
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.fab_manager_version_check
|
|
|
|
get('/api/versions/check', version_check_payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get(rel_url, payload)
|
|
|
|
require 'uri'
|
|
|
|
require 'net/http'
|
|
|
|
require 'json'
|
|
|
|
|
|
|
|
uri = URI.join(hub_base_url, rel_url)
|
|
|
|
uri.query = URI.encode_www_form(payload)
|
|
|
|
|
2020-01-14 14:33:00 +01:00
|
|
|
res = Net::HTTP.get_response(uri)
|
2020-01-13 17:05:53 +01:00
|
|
|
JSON.parse(res.body) if res.is_a?(Net::HTTPSuccess)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.hub_base_url
|
|
|
|
if Rails.env.production?
|
2020-01-14 14:33:00 +01:00
|
|
|
ENV['HUB_BASE_URL'] || 'https://hub.fab-manager.com'
|
2020-01-13 17:05:53 +01:00
|
|
|
else
|
2020-01-14 14:33:00 +01:00
|
|
|
ENV['HUB_BASE_URL'] || 'http://localhost:3000'
|
2020-01-13 17:05:53 +01:00
|
|
|
end
|
|
|
|
end
|
2020-01-14 14:33:00 +01:00
|
|
|
end
|