Class: Courier::Notifications::Notification
- Inherits:
-
Object
- Object
- Courier::Notifications::Notification
- Defined in:
- lib/trycourier/notifications/types/notification.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#routing ⇒ Object
readonly
Returns the value of attribute routing.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Notifications::Notification
Deserialize a JSON object to an instance of Notification.
-
.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(created_at:, id:, routing:, additional_properties: nil) ⇒ Notifications::Notification constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of Notification to a JSON object.
Constructor Details
#initialize(created_at:, id:, routing:, additional_properties: nil) ⇒ Notifications::Notification
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_properties ⇒ Object (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_at ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/trycourier/notifications/types/notification.rb', line 9 def id @id end |
#routing ⇒ Object (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
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.
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
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 |