Class: Courier::Send::ElementalContentSugar

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/send/types/elemental_content_sugar.rb

Overview

Syntatic Sugar to provide a fast shorthand for Courier Elemental Blocks.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, body:, additional_properties: nil) ⇒ Send::ElementalContentSugar

Parameters:

  • title (String)

    The title to be displayed by supported channels i.e. push, email (as subject)

  • body (String)

    The text content displayed in the notification.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



15
16
17
18
19
20
21
22
# File 'lib/trycourier/send/types/elemental_content_sugar.rb', line 15

def initialize(title:, body:, additional_properties: nil)
  # @type [String] The title to be displayed by supported channels i.e. push, email (as subject)
  @title = title
  # @type [String] The text content displayed in the notification.
  @body = body
  # @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/send/types/elemental_content_sugar.rb', line 9

def additional_properties
  @additional_properties
end

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/trycourier/send/types/elemental_content_sugar.rb', line 9

def body
  @body
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/trycourier/send/types/elemental_content_sugar.rb', line 9

def title
  @title
end

Class Method Details

.from_json(json_object:) ⇒ Send::ElementalContentSugar

Deserialize a JSON object to an instance of ElementalContentSugar

Parameters:

  • json_object (JSON)

Returns:



28
29
30
31
32
33
34
# File 'lib/trycourier/send/types/elemental_content_sugar.rb', line 28

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  JSON.parse(json_object)
  title = struct.title
  body = struct.body
  new(title: title, body: body, 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)


47
48
49
50
# File 'lib/trycourier/send/types/elemental_content_sugar.rb', line 47

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

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of ElementalContentSugar to a JSON object

Returns:

  • (JSON)


39
40
41
# File 'lib/trycourier/send/types/elemental_content_sugar.rb', line 39

def to_json(*_args)
  { "title": @title, "body": @body }.to_json
end