Class: Courier::Send::MessageMetadata
- Inherits:
-
Object
- Object
- Courier::Send::MessageMetadata
- Defined in:
- lib/trycourier/send/types/message_metadata.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
-
#utm ⇒ Object
readonly
Returns the value of attribute utm.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Send::MessageMetadata
Deserialize a JSON object to an instance of MessageMetadata.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(event: nil, tags: nil, utm: nil, trace_id: nil, additional_properties: nil) ⇒ Send::MessageMetadata constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of MessageMetadata to a JSON object.
Constructor Details
#initialize(event: nil, tags: nil, utm: nil, trace_id: nil, additional_properties: nil) ⇒ Send::MessageMetadata
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 17 def initialize(event: nil, tags: nil, utm: nil, trace_id: nil, additional_properties: nil) # @type [String] An arbitrary string to tracks the event that generated this request (e.g. 'signup'). @event = event # @type [Array<String>] An array of up to 9 tags you wish to associate with this request (and corresponding messages) for later analysis. Individual tags cannot be more than 30 characters in length. @tags = # @type [Send::Utm] Identify the campaign that refers traffic to a specific website, and attributes the browser's website session. @utm = utm # @type [String] A unique ID used to correlate this request to processing on your servers. Note: Courier does not verify the uniqueness of this ID. @trace_id = trace_id # @type [OpenStruct] Additional properties unmapped to the current class definition @additional_properties = additional_properties end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
9 10 11 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 9 def additional_properties @additional_properties end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
9 10 11 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 9 def event @event end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
9 10 11 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 9 def @tags end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
9 10 11 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 9 def trace_id @trace_id end |
#utm ⇒ Object (readonly)
Returns the value of attribute utm.
9 10 11 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 9 def utm @utm end |
Class Method Details
.from_json(json_object:) ⇒ Send::MessageMetadata
Deserialize a JSON object to an instance of MessageMetadata
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 34 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) event = struct.event = struct. if parsed_json["utm"].nil? utm = nil else utm = parsed_json["utm"].to_json utm = Send::Utm.from_json(json_object: utm) end trace_id = struct.trace_id new(event: event, tags: , utm: utm, trace_id: trace_id, additional_properties: struct) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
60 61 62 63 64 65 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 60 def self.validate_raw(obj:) obj.event&.is_a?(String) != false || raise("Passed value for field obj.event is not the expected type, validation failed.") obj.&.is_a?(Array) != false || raise("Passed value for field obj.tags is not the expected type, validation failed.") obj.utm.nil? || Send::Utm.validate_raw(obj: obj.utm) obj.trace_id&.is_a?(String) != false || raise("Passed value for field obj.trace_id is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of MessageMetadata to a JSON object
52 53 54 |
# File 'lib/trycourier/send/types/message_metadata.rb', line 52 def to_json(*_args) { "event": @event, "tags": @tags, "utm": @utm, "trace_id": @trace_id }.to_json end |