Module: ShopCircle::Orbit

Defined in:
lib/shopcircle_orbit.rb,
lib/shopcircle/orbit/event.rb,
lib/shopcircle/orbit/client.rb,
lib/shopcircle/orbit/errors.rb,
lib/shopcircle/orbit/worker.rb,
lib/shopcircle/orbit/version.rb,
lib/shopcircle/orbit/transport.rb,
lib/shopcircle/orbit/validation.rb,
lib/shopcircle/orbit/configuration.rb,
lib/shopcircle/orbit/rails/railtie.rb,
lib/shopcircle/orbit/rails/middleware.rb

Defined Under Namespace

Modules: Rails, Validation Classes: APIError, AuthenticationError, AuthorizationError, Client, ClientError, Configuration, ConfigurationError, ConnectionError, Error, Event, RateLimitError, TestTransport, TimeoutError, Transport, ValidationError, Worker

Constant Summary collapse

VERSION =
"1.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



19
20
21
# File 'lib/shopcircle_orbit.rb', line 19

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.clientObject

Lazily initialized singleton client.



35
36
37
38
39
40
41
# File 'lib/shopcircle_orbit.rb', line 35

def client
  return @client if @client

  @client_mutex.synchronize do
    @client ||= Client.new(configuration)
  end
end

.configure {|configuration| ... } ⇒ Object

Configure the module-level singleton.

ShopCircle::Orbit.configure do |config|
  config.client_id = "your-client-id"
  config.api_url   = "https://orbit.shopcircle.co"
end

Yields:



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

def configure
  yield(configuration)
end

.flushObject

Force an immediate flush.



71
72
73
74
# File 'lib/shopcircle_orbit.rb', line 71

def flush
  return unless @client
  @client.flush
end

.identify(profile_id, traits = {}) ⇒ Object

Identify a user.

ShopCircle::Orbit.identify("user_123", first_name: "John", email: "john@example.com")


55
56
57
# File 'lib/shopcircle_orbit.rb', line 55

def identify(profile_id, traits = {})
  client.identify(profile_id, traits)
end

.reset!Object

Clear current profile association.



60
61
62
63
# File 'lib/shopcircle_orbit.rb', line 60

def reset!
  return unless @client
  @client.reset!
end

.set_device_id(device_id) ⇒ Object

Set device identifier.



66
67
68
# File 'lib/shopcircle_orbit.rb', line 66

def set_device_id(device_id)
  client.set_device_id(device_id)
end

.shutdown!Object

Flush and stop the singleton client.



77
78
79
80
81
82
83
# File 'lib/shopcircle_orbit.rb', line 77

def shutdown!
  @client_mutex.synchronize do
    return unless @client
    @client.shutdown!
    @client = nil
  end
end

.track(name, properties = {}) ⇒ Object

Track a custom event.

ShopCircle::Orbit.track("purchase", amount: 99.99)


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

def track(name, properties = {})
  client.track(name, properties)
end