Class: Kameleoon::CustomData

Inherits:
Data
  • Object
show all
Defined in:
lib/kameleoon/data.rb

Instance Attribute Summary collapse

Attributes inherited from Data

#instance, #sent

Instance Method Summary collapse

Methods inherited from Data

#encode

Constructor Details

#initialize(arg0, *args) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kameleoon/data.rb', line 62

def initialize(arg0, *args)
  @instance = DataType::CUSTOM
  @sent = false
  if arg0.is_a?(Hash)
    hash = arg0
    id = hash['id']
    raise Kameleoon::Exception::NotFound.new('id') if id.nil?
    @id = id.to_s
    value = hash['value']
    values = hash['values']
    raise Kameleoon::Exception::NotFound.new('values') if values.nil? && value.nil?
    if values.nil?
      @values = [value]
    else
      @values = values.dup
      @values.append(value) unless value.nil?
    end
  else
    @id = arg0.to_s
    @values = args
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#valuesObject (readonly)

Returns the value of attribute values.



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

def values
  @values
end

Instance Method Details

#obtain_full_post_text_lineObject



85
86
87
88
89
90
91
# File 'lib/kameleoon/data.rb', line 85

def obtain_full_post_text_line
  return '' if @values.empty?
  
  str_values = "[[\"#{@values.join('",1],["')}\",1]]"
  nonce = Kameleoon::Utils.generate_random_string(NONCE_LENGTH)
  "eventType=customData&index=#{@id}&valueToCount=#{encode(str_values)}&overwrite=true&nonce=#{nonce}"
end