Class: SamsaraSDK::Client

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

Overview

A client for ingesting events into Samsara. It is the main interface to communicate with Samsara API.

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

initialize

Parameters:

  • config (Hash)

    Configuration overrides.

Raises:



15
16
17
18
19
20
# File 'lib/samsara_sdk/client.rb', line 15

def initialize(config)
  Config.setup! config
  @publisher = Publisher.new
  @queue = RingBuffer.new(Config.get[:max_buffer_size])
  @activity = Thread.new { publishing_activity } if Config.get[:start_publishing_thread]
end

Instance Method Details

#publish_events(events) ⇒ Boolean

Publishes given events list to Ingestion API immediately.

Parameters:

  • events (Array<Hash>)

    List of events.

Returns:

  • (Boolean)

    The result of publish operation.

Raises:

See Also:



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

def publish_events(events)
  events = events.map { |event| Event.validate(Event.enrich(event)) }
  @publisher.post events
end

#record_event(event) ⇒ Object

Pushes event to internal events’ queue.

Parameters:

  • event (Hash)

    Event data.

  • data (Hash)

    a customizable set of options

See Also:



40
41
42
43
# File 'lib/samsara_sdk/client.rb', line 40

def record_event(event)
  event = Event.validate(Event.enrich(event))
  @queue << event
end