Class: EventHubClient::BatchEventHubClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, queue, batch_size) ⇒ BatchEventHubClient

Returns a new instance of BatchEventHubClient.



16
17
18
19
20
# File 'lib/event_hub_client.rb', line 16

def initialize(client, queue, batch_size)
  @client = client
  @queue = queue
  @batch_size = batch_size
end

Instance Attribute Details

#batch_sizeObject (readonly)

Returns the value of attribute batch_size.



14
15
16
# File 'lib/event_hub_client.rb', line 14

def batch_size
  @batch_size
end

#clientObject (readonly)

Returns the value of attribute client.



14
15
16
# File 'lib/event_hub_client.rb', line 14

def client
  @client
end

#queueObject (readonly)

Returns the value of attribute queue.



14
15
16
# File 'lib/event_hub_client.rb', line 14

def queue
  @queue
end

Instance Method Details

#alias(from_id, to_id) ⇒ Object



39
40
41
# File 'lib/event_hub_client.rb', line 39

def alias(from_id, to_id)
  client.alias(from_id, to_id)
end

#flushObject



34
35
36
37
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# 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