Class: Courier::Notifications::NotificationBlock
- Inherits:
-
Object
- Object
- Courier::Notifications::NotificationBlock
- Defined in:
- lib/trycourier/notifications/types/notification_block.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#alias_ ⇒ Object
readonly
Returns the value of attribute alias_.
-
#checksum ⇒ Object
readonly
Returns the value of attribute checksum.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#locales ⇒ Object
readonly
Returns the value of attribute locales.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Notifications::NotificationBlock
Deserialize a JSON object to an instance of NotificationBlock.
-
.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(id:, type:, alias_: nil, context: nil, content: nil, locales: nil, checksum: nil, additional_properties: nil) ⇒ Notifications::NotificationBlock constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of NotificationBlock to a JSON object.
Constructor Details
#initialize(id:, type:, alias_: nil, context: nil, content: nil, locales: nil, checksum: nil, additional_properties: nil) ⇒ Notifications::NotificationBlock
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 21 def initialize(id:, type:, alias_: nil, context: nil, content: nil, locales: nil, checksum: nil, additional_properties: nil) # @type [String] @alias_ = alias_ # @type [String] @context = context # @type [String] @id = id # @type [Notifications::BlockType] @type = type # @type [Notifications::NotificationContent] @content = content # @type [Hash{String => String}] @locales = locales # @type [String] @checksum = checksum # @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.
10 11 12 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10 def additional_properties @additional_properties end |
#alias_ ⇒ Object (readonly)
Returns the value of attribute alias_.
10 11 12 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10 def alias_ @alias_ end |
#checksum ⇒ Object (readonly)
Returns the value of attribute checksum.
10 11 12 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10 def checksum @checksum end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10 def content @content end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
10 11 12 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10 def context @context end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10 def id @id end |
#locales ⇒ Object (readonly)
Returns the value of attribute locales.
10 11 12 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10 def locales @locales end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10 def type @type end |
Class Method Details
.from_json(json_object:) ⇒ Notifications::NotificationBlock
Deserialize a JSON object to an instance of NotificationBlock
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 45 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) alias_ = struct.alias context = struct.context id = struct.id type = struct.type if parsed_json["content"].nil? content = nil else content = parsed_json["content"].to_json content = Notifications::NotificationContent.from_json(json_object: content) end locales = struct.locales checksum = struct.checksum new(alias_: alias_, context: context, id: id, type: type, content: content, locales: locales, checksum: checksum, 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.
83 84 85 86 87 88 89 90 91 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 83 def self.validate_raw(obj:) obj.alias_&.is_a?(String) != false || raise("Passed value for field obj.alias_ is not the expected type, validation failed.") obj.context&.is_a?(String) != false || raise("Passed value for field obj.context 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.") obj.type.is_a?(Notifications::BlockType) != false || raise("Passed value for field obj.type is not the expected type, validation failed.") obj.content.nil? || Notifications::NotificationContent.validate_raw(obj: obj.content) obj.locales&.is_a?(Hash) != false || raise("Passed value for field obj.locales is not the expected type, validation failed.") obj.checksum&.is_a?(String) != false || raise("Passed value for field obj.checksum is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of NotificationBlock to a JSON object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/trycourier/notifications/types/notification_block.rb', line 67 def to_json(*_args) { "alias": @alias_, "context": @context, "id": @id, "type": @type, "content": @content, "locales": @locales, "checksum": @checksum }.to_json end |