Class: LogNexis::Client
- Inherits:
-
Object
- Object
- LogNexis::Client
- Defined in:
- lib/lognexis/client.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://lognexis-node.onrender.com".freeze
Instance Method Summary collapse
- #capture(log_data) ⇒ Object
-
#initialize(api_key, base_url = DEFAULT_BASE_URL) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key, base_url = DEFAULT_BASE_URL) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 |
# File 'lib/lognexis/client.rb', line 10 def initialize(api_key, base_url = DEFAULT_BASE_URL) @api_key = api_key @base_url = base_url.sub(/\/$/, '') @endpoint = URI("#{@base_url}/api/logs/#{@api_key}") end |
Instance Method Details
#capture(log_data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lognexis/client.rb', line 16 def capture(log_data) # Fire and forget in a background thread to prevent blocking Thread.new do begin request = Net::HTTP::Post.new(@endpoint, 'Content-Type' => 'application/json') request.body = log_data.to_json Net::HTTP.start(@endpoint.hostname, @endpoint.port, use_ssl: @endpoint.scheme == 'https', open_timeout: 5, read_timeout: 5) do |http| http.request(request) end rescue => e # Silently fail, do not crash the user's application end end end |