Class: Courier::Send::MessageMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/send/types/message_metadata.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event: nil, tags: nil, utm: nil, trace_id: nil, additional_properties: nil) ⇒ Send::MessageMetadata

Parameters:

  • event (String) (defaults to: nil)

    An arbitrary string to tracks the event that generated this request (e.g. ‘signup’).

  • tags (Array<String>) (defaults to: nil)

    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.

  • utm (Send::Utm) (defaults to: nil)

    Identify the campaign that refers traffic to a specific website, and attributes the browser’s website session.

  • trace_id (String) (defaults to: nil)

    A unique ID used to correlate this request to processing on your servers. Note: Courier does not verify the uniqueness of this ID.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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 = 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_propertiesObject (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

#eventObject (readonly)

Returns the value of attribute event.



9
10
11
# File 'lib/trycourier/send/types/message_metadata.rb', line 9

def event
  @event
end

#tagsObject (readonly)

Returns the value of attribute tags.



9
10
11
# File 'lib/trycourier/send/types/message_metadata.rb', line 9

def tags
  @tags
end

#trace_idObject (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

#utmObject (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

Parameters:

  • json_object (JSON)

Returns:



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
  tags = struct.tags
  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: 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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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.tags&.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

Returns:

  • (JSON)


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