Class: Courier::Send::Routing

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

Overview

Allows you to customize which channel(s) Courier will potentially deliver the message. If no routing key is specified, Courier will use the default routing configuration or routing defined by the template.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, channels:, additional_properties: nil) ⇒ Send::Routing

Parameters:

  • method (Send::RoutingMethod)
  • channels (Array<Send::RoutingChannel>)

    A list of channels or providers to send the message through. Can also recursively define sub-routing methods, which can be useful for defining advanced push notification delivery strategies.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



21
22
23
24
25
26
27
28
29
30
# File 'lib/trycourier/send/types/routing.rb', line 21

def initialize(method:, channels:, additional_properties: nil)
  # @type [Send::RoutingMethod]
  @method = method
  # @type [Array<Send::RoutingChannel>] A list of channels or providers to send the message through. Can also recursively define
  #   sub-routing methods, which can be useful for defining advanced push notification
  #   delivery strategies.
  @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.



13
14
15
# File 'lib/trycourier/send/types/routing.rb', line 13

def additional_properties
  @additional_properties
end

#channelsObject (readonly)

Returns the value of attribute channels.



13
14
15
# File 'lib/trycourier/send/types/routing.rb', line 13

def channels
  @channels
end

#methodObject (readonly)

Returns the value of attribute method.



13
14
15
# File 'lib/trycourier/send/types/routing.rb', line 13

def method
  @method
end

Class Method Details

.from_json(json_object:) ⇒ Send::Routing

Deserialize a JSON object to an instance of Routing

Parameters:

  • json_object (JSON)

Returns:



36
37
38
39
40
41
42
43
44
45
# File 'lib/trycourier/send/types/routing.rb', line 36

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  method = struct.method
  channels = parsed_json["channels"]&.map do |v|
    v = v.to_json
    Send::RoutingChannel.from_json(json_object: v)
  end
  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)


58
59
60
61
# File 'lib/trycourier/send/types/routing.rb', line 58

def self.validate_raw(obj:)
  obj.method.is_a?(Send::RoutingMethod) != 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 Routing to a JSON object

Returns:

  • (JSON)


50
51
52
# File 'lib/trycourier/send/types/routing.rb', line 50

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