Class: SnowplowTracker::Payload
- Inherits:
-
Object
- Object
- SnowplowTracker::Payload
- Includes:
- Contracts
- Defined in:
- lib/snowplow-tracker/payload.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #add(name, value) ⇒ Object
- #add_dict(dict) ⇒ Object
- #add_json(dict, encode_base64, type_when_encoded, type_when_not_encoded) ⇒ Object
-
#initialize ⇒ Payload
constructor
A new instance of Payload.
Constructor Details
#initialize ⇒ Payload
Returns a new instance of Payload.
30 31 32 33 |
# File 'lib/snowplow-tracker/payload.rb', line 30 def initialize @context = {} self end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
27 28 29 |
# File 'lib/snowplow-tracker/payload.rb', line 27 def context @context end |
Instance Method Details
#add(name, value) ⇒ Object
38 39 40 41 42 |
# File 'lib/snowplow-tracker/payload.rb', line 38 def add(name, value) if value != "" and not value.nil? @context[name] = value end end |
#add_dict(dict) ⇒ Object
47 48 49 50 51 |
# File 'lib/snowplow-tracker/payload.rb', line 47 def add_dict(dict) for f in dict self.add(f[0], f[1]) end end |
#add_json(dict, encode_base64, type_when_encoded, type_when_not_encoded) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/snowplow-tracker/payload.rb', line 56 def add_json(dict, encode_base64, type_when_encoded, type_when_not_encoded) if dict.nil? return end dict_string = JSON.generate(dict) if encode_base64 self.add(type_when_encoded, Base64.strict_encode64(dict_string)) else self.add(type_when_not_encoded, dict_string) end end |