Class: Courier::Templates::RoutingStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/templates/types/routing_strategy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, channels:, additional_properties: nil) ⇒ Templates::RoutingStrategy

Parameters:

  • method (Templates::RoutingStrategyMethod)

    The method for selecting channels to send the message with. Value can be either ‘single’ or ‘all’. If not provided will default to ‘single’

  • channels (Array<Templates::CHANNEL_IDENTIFIER>)

    An array of valid channel identifiers (like email, push, sms, etc.) and additional routing nodes.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



16
17
18
19
20
21
22
23
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 16

def initialize(method:, channels:, additional_properties: nil)
  # @type [Templates::RoutingStrategyMethod] The method for selecting channels to send the message with. Value can be either 'single' or 'all'. If not provided will default to 'single'
  @method = method
  # @type [Array<Templates::CHANNEL_IDENTIFIER>] An array of valid channel identifiers (like email, push, sms, etc.) and additional routing nodes.
  @channels = channels
  # @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/templates/types/routing_strategy.rb', line 10

def additional_properties
  @additional_properties
end

#channelsObject (readonly)

Returns the value of attribute channels.



10
11
12
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 10

def channels
  @channels
end

#methodObject (readonly)

Returns the value of attribute method.



10
11
12
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 10

def method
  @method
end

Class Method Details

.from_json(json_object:) ⇒ Templates::RoutingStrategy

Deserialize a JSON object to an instance of RoutingStrategy

Parameters:

  • json_object (JSON)

Returns:



29
30
31
32
33
34
35
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 29

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


48
49
50
51
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 48

def self.validate_raw(obj:)
  obj.method.is_a?(Templates::RoutingStrategyMethod) != false || raise("Passed value for field obj.method is not the expected type, validation failed.")
  obj.channels.is_a?(Array) != false || raise("Passed value for field obj.channels is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of RoutingStrategy to a JSON object

Returns:

  • (JSON)


40
41
42
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 40

def to_json(*_args)
  { "method": @method, "channels": @channels }.to_json
end