Class: SimpleSegment::Batch

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/simple_segment/batch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

included, #isoify_dates, #isoify_dates!, #maybe_datetime_in_iso8601, #symbolize_keys

Constructor Details

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

Returns a new instance of Batch.



13
14
15
16
# File 'lib/simple_segment/batch.rb', line 13

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/simple_segment/batch.rb', line 7

def client
  @client
end

#payloadObject (readonly)

Returns the value of attribute payload.



7
8
9
# File 'lib/simple_segment/batch.rb', line 7

def payload
  @payload
end

Class Method Details

.deserialize(client, payload) ⇒ Object



9
10
11
# File 'lib/simple_segment/batch.rb', line 9

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

Instance Method Details

#commitObject



46
47
48
49
50
51
52
# File 'lib/simple_segment/batch.rb', line 46

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) ⇒ Object



34
35
36
# File 'lib/simple_segment/batch.rb', line 34

def context=(context)
  payload[:context] = context
end

#group(options) ⇒ Object



30
31
32
# File 'lib/simple_segment/batch.rb', line 30

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

#identify(options) ⇒ Object



18
19
20
# File 'lib/simple_segment/batch.rb', line 18

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

#integrations=(integrations) ⇒ Object



38
39
40
# File 'lib/simple_segment/batch.rb', line 38

def integrations=(integrations)
  payload[:integrations] = integrations
end

#page(options) ⇒ Object



26
27
28
# File 'lib/simple_segment/batch.rb', line 26

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

#serializeObject



42
43
44
# File 'lib/simple_segment/batch.rb', line 42

def serialize
  payload
end

#track(options) ⇒ Object



22
23
24
# File 'lib/simple_segment/batch.rb', line 22

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