Class: RudderAnalyticsSync::Batch

Inherits:
Object
  • Object
show all
Includes:
Constants, Utils
Defined in:
lib/rudder_analytics_sync/batch.rb

Constant Summary

Constants included from Constants

Constants::BASE_URL, Constants::DEFAULT_CONTEXT, Constants::DEFAULT_HEADERS, Constants::MAX_BATCH_SIZE, Constants::MAX_MESSAGE_SIZE

Constants included from Utils

Utils::UTC_OFFSET_WITHOUT_COLON, Utils::UTC_OFFSET_WITH_COLON

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#date_in_iso8601, #formatted_offset, included, #isoify_dates, #isoify_dates!, #maybe_datetime_in_iso8601, #seconds_to_utc_offset, #symbolize_keys, #time_in_iso8601, #uid, #valid_date?

Constructor Details

#initialize(client, payload = { batch: [] }) ⇒ Batch

Returns a new instance of Batch.



16
17
18
19
# File 'lib/rudder_analytics_sync/batch.rb', line 16

def initialize(client, payload = { batch: [] })
  @client = client
  @payload = payload
end

Instance Attribute Details

#batch_contextObject (readonly)

Returns the value of attribute batch_context.



10
11
12
# File 'lib/rudder_analytics_sync/batch.rb', line 10

def batch_context
  @batch_context
end

#batch_integrationsObject (readonly)

Returns the value of attribute batch_integrations.



10
11
12
# File 'lib/rudder_analytics_sync/batch.rb', line 10

def batch_integrations
  @batch_integrations
end

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/rudder_analytics_sync/batch.rb', line 10

def client
  @client
end

#payloadObject (readonly)

Returns the value of attribute payload.



10
11
12
# File 'lib/rudder_analytics_sync/batch.rb', line 10

def payload
  @payload
end

Class Method Details

.deserialize(client, payload) ⇒ Object



12
13
14
# File 'lib/rudder_analytics_sync/batch.rb', line 12

def self.deserialize(client, payload)
  new(client, symbolize_keys(payload))
end

Instance Method Details

#alias(options) ⇒ Object



41
42
43
# File 'lib/rudder_analytics_sync/batch.rb', line 41

def alias(options)
  add(Operations::Alias, options, __method__)
end

#commitObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rudder_analytics_sync/batch.rb', line 60

def commit
  if payload[:batch].length.zero?
    raise ArgumentError, 'A batch must contain at least one action'
  end

  if payload[:batch].inspect.length > MAX_BATCH_SIZE
    raise ArgumentError, 'Max batch size is 500 KB'
  end

  Request.new(client).post('/v1/batch', payload)
end

#context=(context) ⇒ Object



45
46
47
48
49
50
# File 'lib/rudder_analytics_sync/batch.rb', line 45

def context=(context)
  if context # rubocop:disable Style/SafeNavigation
    context.delete(:library)
  end
  @batch_context = context
end

#group(options) ⇒ Object



37
38
39
# File 'lib/rudder_analytics_sync/batch.rb', line 37

def group(options)
  add(Operations::Group, options, __method__)
end

#identify(options) ⇒ Object



21
22
23
# File 'lib/rudder_analytics_sync/batch.rb', line 21

def identify(options)
  add(Operations::Identify, options, __method__)
end

#integrations=(integrations) ⇒ Object



52
53
54
# File 'lib/rudder_analytics_sync/batch.rb', line 52

def integrations=(integrations)
  @batch_integrations = integrations
end

#page(options) ⇒ Object



29
30
31
# File 'lib/rudder_analytics_sync/batch.rb', line 29

def page(options)
  add(Operations::Page, options, __method__)
end

#screen(options) ⇒ Object



33
34
35
# File 'lib/rudder_analytics_sync/batch.rb', line 33

def screen(options)
  add(Operations::Screen, options, __method__)
end

#serializeObject



56
57
58
# File 'lib/rudder_analytics_sync/batch.rb', line 56

def serialize
  payload
end

#track(options) ⇒ Object



25
26
27
# File 'lib/rudder_analytics_sync/batch.rb', line 25

def track(options)
  add(Operations::Track, options, __method__)
end