class RudderAnalyticsSync::Batch
Attributes
client[R]
payload[R]
Public Class Methods
deserialize(client, payload)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 9 def self.deserialize(client, payload) new(client, symbolize_keys(payload)) end
new(client, payload = { batch: [] })
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 13 def initialize(client, payload = { batch: [] }) @client = client @payload = payload end
Public Instance Methods
alias(options)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 38 def alias(options) add(Operations::Alias, options, __method__) end
commit()
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 54 def commit if payload[:batch].length.zero? raise ArgumentError, 'A batch must contain at least one action' end Request.new(client).post('/v1/batch', payload) end
context=(context)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 42 def context=(context) payload[:context] = context end
group(options)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 34 def group(options) add(Operations::Group, options, __method__) end
identify(options)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 18 def identify(options) add(Operations::Identify, options, __method__) end
integrations=(integrations)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 46 def integrations=(integrations) payload[:integrations] = integrations end
page(options)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 26 def page(options) add(Operations::Page, options, __method__) end
screen(options)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 30 def screen(options) add(Operations::Screen, options, __method__) end
serialize()
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 50 def serialize payload end
track(options)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 22 def track(options) add(Operations::Track, options, __method__) end
Private Instance Methods
add(operation_class, options, action)
click to toggle source
# File lib/rudder_analytics_sync/batch.rb, line 64 def add(operation_class, options, action) operation = operation_class.new(client, symbolize_keys(options)) operation_payload = operation.build_payload operation_payload[:context] = operation_payload[:context].merge(payload[:context] || {}) operation_payload[:integrations] = payload[:integrations] || operation_payload[:integrations] operation_payload[:type] = action payload[:batch] << operation_payload end