Class: CleverTap::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/clever_tap/uploader.rb

Overview

unit uploading profile data to CleverTap

Constant Summary collapse

HTTP_PATH =
'upload'.freeze
TYPE_EVENT =
:event
TYPE_PROFILE =
:profile
ENTITY_DATA_NAMES =
{
  TYPE_EVENT => 'evtData',
  TYPE_PROFILE => 'profileData'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records, identity_field:, date_field: nil, event_name: nil, dry_run: false) ⇒ Uploader

TODO: make defaults configurable date_field should be a date object responding to ‘to_i` which should returns epoch time profile respond to .to_h



20
21
22
23
24
25
26
27
28
# File 'lib/clever_tap/uploader.rb', line 20

def initialize(records, identity_field:, date_field: nil, event_name: nil, dry_run: false)
  @type = event_name ? TYPE_EVENT : TYPE_PROFILE
  @records = records

  @identity_field = identity_field
  @date_field = date_field
  @event_name = event_name
  @dry_run = dry_run
end

Instance Attribute Details

#date_fieldObject (readonly)

Returns the value of attribute date_field.



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

def date_field
  @date_field
end

#dry_runObject (readonly)

Returns the value of attribute dry_run.



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

def dry_run
  @dry_run
end

#event_nameObject (readonly)

Returns the value of attribute event_name.



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

def event_name
  @event_name
end

#identity_fieldObject (readonly)

Returns the value of attribute identity_field.



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

def identity_field
  @identity_field
end

#recordsObject (readonly)

Returns the value of attribute records.



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

def records
  @records
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#call(client) ⇒ Object



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

def call(client)
  response = client.post(HTTP_PATH, build_request_body) do |request|
    request.params.merge!(dryRun: 1) if dry_run
  end

  parse_response(response)
end