Class: Synchrolog::Logger::HTTPS

Inherits:
Object
  • Object
show all
Defined in:
lib/synchrolog/logger/https.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, **args) ⇒ HTTPS

Returns a new instance of HTTPS.



7
8
9
10
# File 'lib/synchrolog/logger/https.rb', line 7

def initialize(api_key, **args)
  @api_key = api_key
  @host = args[:host]
end

Instance Method Details

#body(message) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# 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

#closeObject



34
35
36
# File 'lib/synchrolog/logger/https.rb', line 34

def close
  nil
end

#write(message) ⇒ Object



12
13
14
15
16
17
18
19
20
# 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