Method: Segment::Analytics::Client#initialize

Defined in:
lib/segment/analytics/client.rb

#initialize(attrs = {}) ⇒ Client

public: Creates a new client

attrs - Hash

:write_key         - String of your project's write_key
:max_queue_size - Fixnum of the max calls to remain queued (optional)
:on_error       - Proc which handles error calls from the API


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/segment/analytics/client.rb', line 18

def initialize attrs = {}
  symbolize_keys! attrs

  @queue = Queue.new
  @write_key = attrs[:write_key]
  @max_queue_size = attrs[:max_queue_size] || Defaults::Queue::MAX_SIZE
  @options = attrs
  @worker_mutex = Mutex.new
  @worker = Worker.new @queue, @write_key, @options

  check_write_key!

  at_exit { @worker_thread && @worker_thread[:should_exit] = true }
end