Class: Courier::Notifications::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/notifications/types/notification.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(created_at:, id:, routing:, additional_properties: nil) ⇒ Notifications::Notification

Parameters:

  • created_at (Long)
  • id (String)
  • routing (Notifications::MessageRouting)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



16
17
18
19
20
21
22
23
24
25
# File 'lib/trycourier/notifications/types/notification.rb', line 16

def initialize(created_at:, id:, routing:, additional_properties: nil)
  # @type [Long]
  @created_at = created_at
  # @type [String]
  @id = id
  # @type [Notifications::MessageRouting]
  @routing = routing
  # @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/notifications/types/notification.rb', line 9

def additional_properties
  @additional_properties
end

#created_atObject (readonly)

Returns the value of attribute created_at.



9
10
11
# File 'lib/trycourier/notifications/types/notification.rb', line 9

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/trycourier/notifications/types/notification.rb', line 9

def id
  @id
end

#routingObject (readonly)

Returns the value of attribute routing.



9
10
11
# File 'lib/trycourier/notifications/types/notification.rb', line 9

def routing
  @routing
end

Class Method Details

.from_json(json_object:) ⇒ Notifications::Notification

Deserialize a JSON object to an instance of Notification

Parameters:

  • json_object (JSON)

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/trycourier/notifications/types/notification.rb', line 31

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 = Notifications::MessageRouting.from_json(json_object: routing)
  end
  new(created_at: created_at, id: id, routing: routing, 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)


56
57
58
59
60
# File 'lib/trycourier/notifications/types/notification.rb', line 56

def self.validate_raw(obj:)
  obj.created_at.is_a?(Long) != 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.")
  Notifications::MessageRouting.validate_raw(obj: obj.routing)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of Notification to a JSON object

Returns:

  • (JSON)


48
49
50
# File 'lib/trycourier/notifications/types/notification.rb', line 48

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