Class: Courier::Templates::NotificationTemplates

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/templates/types/notification_templates.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(created_at:, id:, routing:, tags:, title:, updated_at:, additional_properties: nil) ⇒ Templates::NotificationTemplates

Parameters:

  • created_at (Integer)

    A UTC timestamp at which notification was created. This is stored as a millisecond representation of the Unix epoch (the time passed since January 1, 1970).

  • id (String)

    A unique identifier associated with the notification.

  • routing (Templates::RoutingStrategy)

    Routing strategy used by this notification.

  • tags (Array<Templates::Tag>)

    A list of tags attached to the notification.

  • title (String)

    The title of the notification.

  • updated_at (Integer)

    A UTC timestamp at which notification was updated. This is stored as a millisecond representation of the Unix epoch (the time passed since January 1, 1970).

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/trycourier/templates/types/notification_templates.rb', line 20

def initialize(created_at:, id:, routing:, tags:, title:, updated_at:, additional_properties: nil)
  # @type [Integer] A UTC timestamp at which notification was created. This is stored as a millisecond representation of the Unix epoch (the time passed since January 1, 1970).
  @created_at = created_at
  # @type [String] A unique identifier associated with the notification.
  @id = id
  # @type [Templates::RoutingStrategy] Routing strategy used by this notification.
  @routing = routing
  # @type [Array<Templates::Tag>] A list of tags attached to the notification.
  @tags = tags
  # @type [String] The title of the notification.
  @title = title
  # @type [Integer] A UTC timestamp at which notification was updated. This is stored as a millisecond representation of the Unix epoch (the time passed since January 1, 1970).
  @updated_at = updated_at
  # @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.



10
11
12
# File 'lib/trycourier/templates/types/notification_templates.rb', line 10

def additional_properties
  @additional_properties
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/trycourier/templates/types/notification_templates.rb', line 10

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/trycourier/templates/types/notification_templates.rb', line 10

def id
  @id
end

#routingObject (readonly)

Returns the value of attribute routing.



10
11
12
# File 'lib/trycourier/templates/types/notification_templates.rb', line 10

def routing
  @routing
end

#tagsObject (readonly)

Returns the value of attribute tags.



10
11
12
# File 'lib/trycourier/templates/types/notification_templates.rb', line 10

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/trycourier/templates/types/notification_templates.rb', line 10

def title
  @title
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



10
11
12
# File 'lib/trycourier/templates/types/notification_templates.rb', line 10

def updated_at
  @updated_at
end

Class Method Details

.from_json(json_object:) ⇒ Templates::NotificationTemplates

Deserialize a JSON object to an instance of NotificationTemplates

Parameters:

  • json_object (JSON)

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/trycourier/templates/types/notification_templates.rb', line 41

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  created_at = struct.created_at
  id = struct.id
  if parsed_json["routing"].nil?
    routing = nil
  else
    routing = parsed_json["routing"].to_json
    routing = Templates::RoutingStrategy.from_json(json_object: routing)
  end
  tags = parsed_json["tags"]&.map do |v|
    v = v.to_json
    Templates::Tag.from_json(json_object: v)
  end
  title = struct.title
  updated_at = struct.updated_at
  new(created_at: created_at, id: id, routing: routing, tags: tags, title: title, updated_at: updated_at,
      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)


80
81
82
83
84
85
86
87
# File 'lib/trycourier/templates/types/notification_templates.rb', line 80

def self.validate_raw(obj:)
  obj.created_at.is_a?(Integer) != false || raise("Passed value for field obj.created_at is not the expected type, validation failed.")
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  Templates::RoutingStrategy.validate_raw(obj: obj.routing)
  obj.tags.is_a?(Array) != false || raise("Passed value for field obj.tags is not the expected type, validation failed.")
  obj.title.is_a?(String) != false || raise("Passed value for field obj.title is not the expected type, validation failed.")
  obj.updated_at.is_a?(Integer) != false || raise("Passed value for field obj.updated_at is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of NotificationTemplates to a JSON object

Returns:

  • (JSON)


65
66
67
68
69
70
71
72
73
74
# File 'lib/trycourier/templates/types/notification_templates.rb', line 65

def to_json(*_args)
  {
    "created_at": @created_at,
    "id": @id,
    "routing": @routing,
    "tags": @tags,
    "title": @title,
    "updated_at": @updated_at
  }.to_json
end