class Synchrolog::Logger::HTTPS

Public Class Methods

new(api_key, **args) click to toggle source
# File lib/synchrolog/logger/https.rb, line 7
def initialize(api_key, **args)
  @api_key = api_key
  @host = args[:host]
end

Public Instance Methods

body(message) click to toggle source
# File lib/synchrolog/logger/https.rb, line 22
def body(message)
  {
    event_type: 'log', 
    timestamp: message[:timestamp],
    anonymous_id: message[:anonymous_id],
    user_id: message[:user_id],
    source: 'backend',
    api_key: @api_key,
    log: message
  }
end
close() click to toggle source
# File lib/synchrolog/logger/https.rb, line 34
def close
  nil
end
write(message) click to toggle source
# File lib/synchrolog/logger/https.rb, line 12
def write(message)
  return unless message[:anonymous_id]
  json_headers = {'Authorization' => "Basic #{@api_key}", 'Content-Type' =>'application/json'}
  uri = URI.parse("#{@host}/v1/track-backend")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE      
  http.post(uri.path, body(message).to_json, json_headers)
end