Class: SimpleSegment::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

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

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



12
13
14
# File 'lib/simple_segment/client.rb', line 12

def initialize(options = {})
  @config = Configuration.new(options)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/simple_segment/client.rb', line 10

def config
  @config
end

Instance Method Details

#alias(options) ⇒ Object

Parameters:

  • options (Hash)
  • :user_id (Hash)

    a customizable set of options

  • :anonymous_id (Hash)

    a customizable set of options

  • :previous_id (Hash)

    a customizable set of options

  • :traits (Hash)

    a customizable set of options

  • :context (Hash)

    a customizable set of options

  • :integrations (Hash)

    a customizable set of options

  • :timestamp (Hash)

    a customizable set of options



71
72
73
# File 'lib/simple_segment/client.rb', line 71

def alias(options)
  Operations::Alias.new(self, symbolize_keys(options)).call
end

#batch {|batch| ... } ⇒ Object

Examples:

client.batch do |analytics|
  analytics.context = { 'foo' => 'bar' }
  analytics.identify(user_id: 'id')
  analytics.track(event: 'Delivered Package', user_id: 'id')
end

Yields:

  • (batch)

    Yields a special batch object that can be used to group ‘identify`, `track`, `page` and `group` calls into a single API request.



84
85
86
87
88
# File 'lib/simple_segment/client.rb', line 84

def batch
  batch = Batch.new(self)
  yield(batch)
  batch.commit
end

#flushObject

A no op, added for backwards compatibility with ‘analytics-ruby`



91
# File 'lib/simple_segment/client.rb', line 91

def flush; end

#group(options) ⇒ Object

Parameters:

  • options (Hash)
  • :user_id (Hash)

    a customizable set of options

  • :anonymous_id (Hash)

    a customizable set of options

  • :group_id (Hash)

    a customizable set of options

  • :traits (Hash)

    a customizable set of options

  • :context (Hash)

    a customizable set of options

  • :integrations (Hash)

    a customizable set of options

  • :timestamp (Hash)

    a customizable set of options



59
60
61
# File 'lib/simple_segment/client.rb', line 59

def group(options)
  Operations::Group.new(self, symbolize_keys(options)).call
end

#identify(options) ⇒ Object

Parameters:

  • options (Hash)
  • :user_id (Hash)

    a customizable set of options

  • :anonymous_id (Hash)

    a customizable set of options

  • :traits (Hash)

    a customizable set of options

  • :context (Hash)

    a customizable set of options

  • :integrations (Hash)

    a customizable set of options

  • :timestamp (Hash)

    a customizable set of options



23
24
25
# File 'lib/simple_segment/client.rb', line 23

def identify(options)
  Operations::Identify.new(self, symbolize_keys(options)).call
end

#page(options) ⇒ Object

Parameters:

  • options (Hash)
  • :user_id (Hash)

    a customizable set of options

  • :anonymous_id (Hash)

    a customizable set of options

  • :name (Hash)

    a customizable set of options

  • :properties (Hash)

    a customizable set of options

  • :context (Hash)

    a customizable set of options

  • :integrations (Hash)

    a customizable set of options

  • :timestamp (Hash)

    a customizable set of options



47
48
49
# File 'lib/simple_segment/client.rb', line 47

def page(options)
  Operations::Page.new(self, symbolize_keys(options)).call
end

#track(options) ⇒ Object

Parameters:

  • options (Hash)
  • :event (Hash)

    a customizable set of options

  • :user_id (Hash)

    a customizable set of options

  • :anonymous_id (Hash)

    a customizable set of options

  • :properties (Hash)

    a customizable set of options

  • :context (Hash)

    a customizable set of options

  • :integrations (Hash)

    a customizable set of options

  • :timestamp (Hash)

    a customizable set of options



35
36
37
# File 'lib/simple_segment/client.rb', line 35

def track(options)
  Operations::Track.new(self, symbolize_keys(options)).call
end