Class: EventHubClient::BatchEventHubClient
- Inherits:
-
Object
- Object
- EventHubClient::BatchEventHubClient
- Defined in:
- lib/event_hub_client.rb
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #alias(from_id, to_id) ⇒ Object
- #flush ⇒ Object
-
#initialize(client, queue, batch_size) ⇒ BatchEventHubClient
constructor
A new instance of BatchEventHubClient.
- #track(event_type, user_id, event_properties) ⇒ Object
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_size ⇒ Object (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 |
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/event_hub_client.rb', line 14 def client @client end |
#queue ⇒ Object (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 |
#flush ⇒ Object
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 |