Class: Courier::Messages::RenderOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/messages/types/render_output.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel:, channel_id:, content:, additional_properties: nil) ⇒ Messages::RenderOutput

Parameters:

  • channel (String)

    The channel used for rendering the message.

  • channel_id (String)

    The ID of channel used for rendering the message.

  • content (Messages::RenderedMessageContent)

    Content details of the rendered message.

  • 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/messages/types/render_output.rb', line 16

def initialize(channel:, channel_id:, content:, additional_properties: nil)
  # @type [String] The channel used for rendering the message.
  @channel = channel
  # @type [String] The ID of channel used for rendering the message.
  @channel_id = channel_id
  # @type [Messages::RenderedMessageContent] Content details of the rendered message.
  @content = content
  # @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/messages/types/render_output.rb', line 9

def additional_properties
  @additional_properties
end

#channelObject (readonly)

Returns the value of attribute channel.


9
10
11
# File 'lib/trycourier/messages/types/render_output.rb', line 9

def channel
  @channel
end

#channel_idObject (readonly)

Returns the value of attribute channel_id.


9
10
11
# File 'lib/trycourier/messages/types/render_output.rb', line 9

def channel_id
  @channel_id
end

#contentObject (readonly)

Returns the value of attribute content.


9
10
11
# File 'lib/trycourier/messages/types/render_output.rb', line 9

def content
  @content
end

Class Method Details

.from_json(json_object:) ⇒ Messages::RenderOutput

Deserialize a JSON object to an instance of RenderOutput

Parameters:

  • json_object (JSON)

Returns:


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

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  channel = struct.channel
  channel_id = struct.channel_id
  if parsed_json["content"].nil?
    content = nil
  else
    content = parsed_json["content"].to_json
    content = Messages::RenderedMessageContent.from_json(json_object: content)
  end
  new(channel: channel, channel_id: channel_id, content: content, 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/messages/types/render_output.rb', line 56

def self.validate_raw(obj:)
  obj.channel.is_a?(String) != false || raise("Passed value for field obj.channel is not the expected type, validation failed.")
  obj.channel_id.is_a?(String) != false || raise("Passed value for field obj.channel_id is not the expected type, validation failed.")
  Messages::RenderedMessageContent.validate_raw(obj: obj.content)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of RenderOutput to a JSON object

Returns:

  • (JSON)

48
49
50
# File 'lib/trycourier/messages/types/render_output.rb', line 48

def to_json(*_args)
  { "channel": @channel, "channel_id": @channel_id, "content": @content }.to_json
end