Class: Stactics::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, host: DEFAULT_HOST, timeout: 5, transport: nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
# File 'lib/stactics/client.rb', line 19

def initialize(api_key:, host: DEFAULT_HOST, timeout: 5, transport: nil)
  raise ArgumentError, "api_key is required" if api_key.to_s.strip.empty?

  @api_key = api_key
  @host = host.to_s.delete_suffix("/")
  @timeout = timeout
  @transport = transport || method(:perform_request)
end

Instance Method Details

#batch(events) ⇒ Object



33
34
35
36
# File 'lib/stactics/client.rb', line 33

def batch(events)
  payload = { "events" => events.map { |event| stringify_keys(event) } }
  request("/v1/events/batch", payload)
end

#track(event_type, attributes = {}) ⇒ Object



28
29
30
31
# File 'lib/stactics/client.rb', line 28

def track(event_type, attributes = {})
  payload = stringify_keys(attributes).merge("event_type" => event_type.to_s)
  request("/v1/events", payload)
end