Class: Workarea::PingHomeBase

Inherits:
Object
  • Object
show all
Defined in:
lib/workarea/ping_home_base.rb

Defined Under Namespace

Classes: Request

Constant Summary collapse

URL =
'https://homebase.weblinc.com'
SHARED_SECRET =
'e20750f19f5acfe314050da46e6aa77e'

Class Method Summary collapse

Class Method Details

.auth_tokenObject



30
31
32
# File 'lib/workarea/ping_home_base.rb', line 30

def auth_token
  Digest::SHA256.hexdigest(Workarea.config.site_name + SHARED_SECRET)
end

.pingObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/workarea/ping_home_base.rb', line 7

def ping
  begin
    request = Net::HTTP::Post.new('/ping')
    request['X-WeblincClientName'] = Workarea.config.site_name
    request['X-WeblincAuthToken'] = auth_token
    request.content_type = 'application/json'
    request.body = Request.new.to_json

    uri = URI(URL)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http.start { |h| h.request(request) }

  rescue Exception => e
    Rails.logger.error '-------------------------------------'
    Rails.logger.error "There was an error contacting #{URL}!"
    Rails.logger.error e.class
    Rails.logger.error e.message
    Rails.logger.error '-------------------------------------'
  end
end