Class: Courier::Notifications::NotificationChannel

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, type: nil, content: nil, locales: nil, checksum: nil, additional_properties: nil) ⇒ Notifications::NotificationChannel

Parameters:

  • id (String)
  • type (String) (defaults to: nil)
  • content (Notifications::NotificationChannelContent) (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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/trycourier/notifications/types/notification_channel.rb', line 18

def initialize(id:, type: nil, content: nil, locales: nil, checksum: nil, additional_properties: nil)
  # @type [String]
  @id = id
  # @type [String]
  @type = type
  # @type [Notifications::NotificationChannelContent]
  @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.



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

def additional_properties
  @additional_properties
end

#checksumObject (readonly)

Returns the value of attribute checksum.



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

def checksum
  @checksum
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#localesObject (readonly)

Returns the value of attribute locales.



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

def locales
  @locales
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ Notifications::NotificationChannel

Deserialize a JSON object to an instance of NotificationChannel

Parameters:

  • json_object (JSON)

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/trycourier/notifications/types/notification_channel.rb', line 37

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = struct.id
  type = struct.type
  if parsed_json["content"].nil?
    content = nil
  else
    content = parsed_json["content"].to_json
    content = Notifications::NotificationChannelContent.from_json(json_object: content)
  end
  locales = struct.locales
  checksum = struct.checksum
  new(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)


64
65
66
67
68
69
70
# File 'lib/trycourier/notifications/types/notification_channel.rb', line 64

def self.validate_raw(obj:)
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.type&.is_a?(String) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  obj.content.nil? || Notifications::NotificationChannelContent.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 NotificationChannel to a JSON object

Returns:

  • (JSON)


56
57
58
# File 'lib/trycourier/notifications/types/notification_channel.rb', line 56

def to_json(*_args)
  { "id": @id, "type": @type, "content": @content, "locales": @locales, "checksum": @checksum }.to_json
end