Class: Synchrolog::Logger::HTTP
- Inherits:
-
Object
- Object
- Synchrolog::Logger::HTTP
- Defined in:
- lib/synchrolog/logger/http.rb
Instance Method Summary collapse
- #body(message) ⇒ Object
- #close ⇒ Object
-
#initialize(api_key, **args) ⇒ HTTP
constructor
A new instance of HTTP.
- #write(message) ⇒ Object
Constructor Details
#initialize(api_key, **args) ⇒ HTTP
Returns a new instance of HTTP.
7 8 9 10 |
# File 'lib/synchrolog/logger/http.rb', line 7 def initialize(api_key, **args) @api_key = api_key @host = args[:host] end |
Instance Method Details
#body(message) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/synchrolog/logger/http.rb', line 20 def body() { event_type: 'log', timestamp: [:timestamp], anonymous_id: [:anonymous_id], user_id: [:user_id], source: 'backend', api_key: @api_key, log: } end |
#close ⇒ Object
32 33 34 |
# File 'lib/synchrolog/logger/http.rb', line 32 def close nil end |
#write(message) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/synchrolog/logger/http.rb', line 12 def write() return unless [: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.post(uri.path, body().to_json, json_headers) end |