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

Constructor Details

#initialize(*args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kameleoon/data.rb', line 42

def initialize(*args)
  @instance = DataType::CUSTOM
  @sent = false
  unless args.empty?
    if args.length == 1
      hash = args.first
      if hash["id"].nil?
        raise NotFoundError.new("id")
      end
      @id = hash["id"].to_s
      if hash["value"].nil?
        raise NotFoundError.new(hash["value"])
      end
      @value = hash["value"]
    elsif args.length == 2
      @id = args[0].to_s
      @value = args[1]
    end
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



35
36
37
# File 'lib/kameleoon/data.rb', line 35

def id
  @id
end

#valueObject

Returns the value of attribute value.



35
36
37
# File 'lib/kameleoon/data.rb', line 35

def value
  @value
end

Instance Method Details

#obtain_full_post_text_lineObject



63
64
65
66
67
# File 'lib/kameleoon/data.rb', line 63

def obtain_full_post_text_line
  to_encode = "[[\"" + @value.to_s.gsub("\"", "\\\"") + "\",1]]"
  nonce = Kameleoon::Utils.generate_random_string(NONCE_LENGTH)
  "eventType=customData&index=" + @id.to_s + "&valueToCount=" + URI.encode_www_form_component(to_encode) + "&overwrite=true&nonce=" + nonce
end