Class: CleverTap

Inherits:
Object
  • Object
show all
Defined in:
lib/clever_tap.rb,
lib/clever_tap/event.rb,
lib/clever_tap/client.rb,
lib/clever_tap/config.rb,
lib/clever_tap/entity.rb,
lib/clever_tap/profile.rb,
lib/clever_tap/version.rb,
lib/clever_tap/response.rb,
lib/clever_tap/uploader.rb,
lib/clever_tap/failed_response.rb,
lib/clever_tap/successful_response.rb

Overview

the main module of the system

Defined Under Namespace

Classes: Client, Config, Entity, Event, FailedResponse, MissingEventNameError, MissingIdentityError, NoDataError, NotConsistentArrayError, Profile, Response, SuccessfulResponse, Uploader

Constant Summary collapse

VERSION =
'0.3.0'.freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) {|@config| ... } ⇒ CleverTap

Returns a new instance of CleverTap.

Yields:



30
31
32
33
34
35
36
# File 'lib/clever_tap.rb', line 30

def initialize(**params)
  @config = Config.new(params)
  yield(@config) if block_given?

  @config.validate
  @config.freeze
end

Class Attribute Details

.account_idObject

Returns the value of attribute account_id.



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

def 
  @account_id
end

.account_passcodeObject

Returns the value of attribute account_passcode.



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

def 
  @account_passcode
end

.identity_fieldObject

Returns the value of attribute identity_field.



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

def identity_field
  @identity_field
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



15
16
17
# File 'lib/clever_tap.rb', line 15

def config
  @config
end

Class Method Details

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (CleverTap)

    the object that the method was called on



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

def setup
  yield(self)
end

Instance Method Details

#clientObject



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

def client
  @client ||= Client.new(config., config.passcode, &config.configure_faraday)
end

#upload_event(event, **options) ⇒ Object



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

def upload_event(event, **options)
  upload_events([event], options)
end

#upload_events(events, name:, **rest) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/clever_tap.rb', line 42

def upload_events(events, name:, **rest)
  options = rest.merge(event_name: name, identity_field: config.identity_field)

  response = Uploader.new(events, options).call(client)

  normalize_response(response, records: events)
rescue Faraday::Error::TimeoutError, Faraday::Error::ClientError => e
  FailedResponse.new(records: events, message: e.message)
end

#upload_profile(profile, **options) ⇒ Object



65
66
67
# File 'lib/clever_tap.rb', line 65

def upload_profile(profile, **options)
  upload_profiles([profile], options)
end

#upload_profiles(profiles, **options) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/clever_tap.rb', line 56

def upload_profiles(profiles, **options)
  options = options.merge(identity_field: config.identity_field)
  response = Uploader.new(profiles, **options).call(client)

  normalize_response(response, records: profiles)
rescue Faraday::Error::TimeoutError, Faraday::Error::ClientError => e
  FailedResponse.new(records: profiles, message: e.message)
end