class EventHubClient::BatchEventHubClient

Attributes

batch_size[R]
client[R]
queue[R]

Public Class Methods

new(client, queue, batch_size) click to toggle source
# File lib/event_hub_client.rb, line 16
def initialize(client, queue, batch_size)
  @client = client
  @queue = queue
  @batch_size = batch_size
end

Public Instance Methods

alias(from_id, to_id) click to toggle source
# File lib/event_hub_client.rb, line 39
def alias(from_id, to_id)
  client.alias(from_id, to_id)
end
flush() click to toggle source
# File lib/event_hub_client.rb, line 34
def flush
  client.send_request("events/batch_track", { "events" => queue.to_json })
  @queue = []
end
track(event_type, user_id, event_properties) click to toggle source
# File lib/event_hub_client.rb, line 22
def track(event_type, user_id, event_properties)
  params = {}.merge(event_properties).merge({
    "event_type" => event_type,
    "external_user_id" => user_id,
  })
  queue.push(params)
  if queue.size % batch_size == 0
    client.send_request("events/batch_track", { "events" => queue.to_json })
    @queue = []
  end
end