Class: Optimizely::OdpEvent
- Inherits:
-
Object
- Object
- Optimizely::OdpEvent
- Defined in:
- lib/optimizely/odp/odp_event.rb
Constant Summary collapse
- KEY_FOR_USER_ID =
Representation of an odp event which can be sent to the Optimizely odp platform.
Helpers::Constants::ODP_MANAGER_CONFIG[:KEY_FOR_USER_ID]
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_common_event_data(custom_data) ⇒ Object
- #convert_identifiers(identifiers) ⇒ Object
-
#initialize(type:, action:, identifiers:, data:) ⇒ OdpEvent
constructor
A new instance of OdpEvent.
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(type:, action:, identifiers:, data:) ⇒ OdpEvent
Returns a new instance of OdpEvent.
28 29 30 31 32 33 |
# File 'lib/optimizely/odp/odp_event.rb', line 28 def initialize(type:, action:, identifiers:, data:) @type = type @action = action @identifiers = convert_identifiers(identifiers) @data = add_common_event_data(data) end |
Instance Method Details
#==(other) ⇒ Object
71 72 73 |
# File 'lib/optimizely/odp/odp_event.rb', line 71 def ==(other) to_json == other.to_json end |
#add_common_event_data(custom_data) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/optimizely/odp/odp_event.rb', line 35 def add_common_event_data(custom_data) data = { idempotence_id: SecureRandom.uuid, data_source_type: 'sdk', data_source: 'ruby-sdk', data_source_version: VERSION } data.update(custom_data) data end |
#convert_identifiers(identifiers) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/optimizely/odp/odp_event.rb', line 46 def convert_identifiers(identifiers) # Convert incorrect case/separator of identifier key `fs_user_id` # (ie. `fs-user-id`, `FS_USER_ID`). identifiers.clone.each_key do |key| break if key == KEY_FOR_USER_ID if ['fs-user-id', KEY_FOR_USER_ID].include?(key.downcase) identifiers[KEY_FOR_USER_ID] = identifiers.delete(key) break end end identifiers end |
#to_json(*_args) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/optimizely/odp/odp_event.rb', line 62 def to_json(*_args) { type: @type, action: @action, identifiers: @identifiers, data: @data }.to_json end |