Class: CloseYourIt::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/closeyourit/client.rb

Overview

Compone Transport + BackgroundWorker: applica ‘before_send` e dispatcha l’invio in modo fire-and-forget.

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
# File 'lib/closeyourit/client.rb', line 7

def initialize(configuration)
  @configuration = configuration
  @transport = Transport.new(configuration)
  @worker = BackgroundWorker.new(
    threads: configuration.async_threads,
    max_queue: configuration.background_worker_max_queue
  )
end

Instance Method Details

#capture_event(event) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/closeyourit/client.rb', line 16

def capture_event(event)
  payload = event.to_h
  payload = @configuration.before_send.call(payload) if @configuration.before_send
  return nil if payload.nil?

  path = event.ingest_path(@configuration.project_id)
  @worker.perform { @transport.send_event(payload, path: path) }
  payload
end

#shutdownObject



26
27
28
# File 'lib/closeyourit/client.rb', line 26

def shutdown
  @worker.shutdown
end