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(*args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/kameleoon/data.rb', line 52

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.



45
46
47
# File 'lib/kameleoon/data.rb', line 45

def id
  @id
end

#valueObject

Returns the value of attribute value.



45
46
47
# File 'lib/kameleoon/data.rb', line 45

def value
  @value
end

Instance Method Details

#obtain_full_post_text_lineObject



73
74
75
76
77
# File 'lib/kameleoon/data.rb', line 73

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=" + encode(to_encode) + "&overwrite=true&nonce=" + nonce
end