class CleverTap::Entity

Constants

ALLOWED_IDENTITIES
IDENTITY_STRING
TIMESTAMP_STRING
TYPE_KEY_STRING
TYPE_VALUE_STRING
UPLOAD_LIMIT

Public Class Methods

all_same_type?(items) click to toggle source
# File lib/clever_tap/entity.rb, line 27
def all_same_type?(items)
  items.all? { |i| i.class == self }
end
new(**args) click to toggle source
# File lib/clever_tap/entity.rb, line 32
def initialize(**args)
  @data = args[:data]
  @identity = choose_identity(args)
  @timestamp = choose_timestamp(args)
end
upload_limit() click to toggle source
# File lib/clever_tap/entity.rb, line 23
def upload_limit
  self::UPLOAD_LIMIT
end

Public Instance Methods

to_h() click to toggle source
# File lib/clever_tap/entity.rb, line 38
def to_h
  put_identity_pair
    .merge(put_timestamp_pair)
    .merge(put_type_pair)
    .merge(put_data)
end

Private Instance Methods

allowed?(identity) click to toggle source
# File lib/clever_tap/entity.rb, line 83
def allowed?(identity)
  ALLOWED_IDENTITIES.include?(identity)
end
choose_identity(args) click to toggle source
# File lib/clever_tap/entity.rb, line 71
def choose_identity(args)
  identity = args[:identity].to_s

  return identity if allowed?(identity) && @data.to_h.key?(identity)
  CleverTap.identity_field.to_s
end
choose_timestamp(args) click to toggle source
# File lib/clever_tap/entity.rb, line 78
def choose_timestamp(args)
  return args[:custom_timestamp].to_i if args[:custom_timestamp]
  return @data.delete(args[:timestamp_field].to_s).to_i if args[:timestamp_field]
end
put_data() click to toggle source
# File lib/clever_tap/entity.rb, line 63
def put_data
  raise NoDataError if @data.to_h.empty?
  @data.delete(@identity) if allowed?(@identity)
  {
    self.class::DATA_STRING => @data
  }
end
put_identity_pair() click to toggle source
# File lib/clever_tap/entity.rb, line 47
def put_identity_pair
  raise NoDataError if @data.to_h.empty?
  raise MissingIdentityError if @identity == '' || @data[@identity].nil?
  return { @identity => @data[@identity].to_s } if allowed?(@identity)
  { IDENTITY_STRING => @data[@identity].to_s }
end
put_timestamp_pair() click to toggle source
# File lib/clever_tap/entity.rb, line 54
def put_timestamp_pair
  return {} unless @timestamp
  { TIMESTAMP_STRING => @timestamp }
end
put_type_pair() click to toggle source
# File lib/clever_tap/entity.rb, line 59
def put_type_pair
  { TYPE_KEY_STRING => self.class::TYPE_VALUE_STRING }
end