Class: Courier::Notifications::NotificationBlock

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, type:, alias_: nil, context: nil, content: nil, locales: nil, checksum: nil, additional_properties: nil) ⇒ Notifications::NotificationBlock

Parameters:

  • alias_ (String) (defaults to: nil)
  • context (String) (defaults to: nil)
  • id (String)
  • type (Notifications::BlockType)
  • content (Notifications::NotificationContent) (defaults to: nil)
  • locales (Hash{String => String}) (defaults to: nil)
  • checksum (String) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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

#checksumObject (readonly)

Returns the value of attribute checksum.



10
11
12
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10

def checksum
  @checksum
end

#contentObject (readonly)

Returns the value of attribute content.



10
11
12
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10

def content
  @content
end

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10

def context
  @context
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10

def id
  @id
end

#localesObject (readonly)

Returns the value of attribute locales.



10
11
12
# File 'lib/trycourier/notifications/types/notification_block.rb', line 10

def locales
  @locales
end

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

Parameters:

  • json_object (JSON)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (JSON)


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