Class: ConnectClient::Event
- Inherits:
-
Object
- Object
- ConnectClient::Event
- Defined in:
- lib/connect_client/event.rb
Constant Summary collapse
- @@RESERVED_PROPERTY_REGEX =
/tp_.+/i
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(data) ⇒ Event
constructor
A new instance of Event.
- #to_json(options = nil) ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(data) ⇒ Event
Returns a new instance of Event.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/connect_client/event.rb', line 12 def initialize(data) event_data_defaults = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601 } @data = event_data_defaults.merge(data) if (@data[:timestamp].respond_to? :iso8601) @data[:timestamp] = @data[:timestamp].iso8601 end validate end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/connect_client/event.rb', line 10 def data @data end |
Instance Method Details
#to_json(options = nil) ⇒ Object
29 30 31 |
# File 'lib/connect_client/event.rb', line 29 def to_json( = nil) @data.to_json end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/connect_client/event.rb', line 33 def to_s "Event Data: #{@data}" end |
#validate ⇒ Object
23 24 25 26 27 |
# File 'lib/connect_client/event.rb', line 23 def validate invalid_properties = @data.keys.grep(@@RESERVED_PROPERTY_REGEX) raise EventDataValidationError.new(invalid_properties) if invalid_properties.any? end |