Class: Courier::Send::Channel

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(brand_id: nil, providers: nil, routing_method: nil, if_: nil, timeouts: nil, override: nil, metadata: nil, additional_properties: nil) ⇒ Send::Channel

Parameters:

  • brand_id (String) (defaults to: nil)

    Id of the brand that should be used for rendering the message. If not specified, the brand configured as default brand will be used.

  • providers (Array<String>) (defaults to: nil)

    A list of providers enabled for this channel. Courier will select one provider to send through unless routing_method is set to all.

  • routing_method (Send::RoutingMethod) (defaults to: nil)

    The method for selecting the providers to send the message with. Single will send to one of the available providers for this channel, all will send the message through all channels. Defaults to ‘single`.

  • if_ (String) (defaults to: nil)

    A JavaScript conditional expression to determine if the message should be sent through the channel. Has access to the data and profile object. For example, ‘data.name === profile.name`

  • timeouts (Send::Timeouts) (defaults to: nil)
  • override (Send::Override) (defaults to: nil)

    Channel specific overrides.

  • metadata (Send::ChannelMetadata) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trycourier/send/types/channel.rb', line 29

def initialize(brand_id: nil, providers: nil, routing_method: nil, if_: nil, timeouts: nil, override: nil,
               metadata: nil, additional_properties: nil)
  # @type [String] Id of the brand that should be used for rendering the message.
  #   If not specified, the brand configured as default brand will be used.
  @brand_id = brand_id
  # @type [Array<String>] A list of providers enabled for this channel. Courier will select
  #   one provider to send through unless routing_method is set to all.
  @providers = providers
  # @type [Send::RoutingMethod] The method for selecting the providers to send the message with.
  #   Single will send to one of the available providers for this channel,
  #   all will send the message through all channels. Defaults to `single`.
  @routing_method = routing_method
  # @type [String] A JavaScript conditional expression to determine if the message should
  #   be sent through the channel. Has access to the data and profile object.
  #   For example, `data.name === profile.name`
  @if_ = if_
  # @type [Send::Timeouts]
  @timeouts = timeouts
  # @type [Send::Override] Channel specific overrides.
  @override = override
  # @type [Send::ChannelMetadata]
  @metadata = 
  # @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.



12
13
14
# File 'lib/trycourier/send/types/channel.rb', line 12

def additional_properties
  @additional_properties
end

#brand_idObject (readonly)

Returns the value of attribute brand_id.



12
13
14
# File 'lib/trycourier/send/types/channel.rb', line 12

def brand_id
  @brand_id
end

#if_Object (readonly)

Returns the value of attribute if_.



12
13
14
# File 'lib/trycourier/send/types/channel.rb', line 12

def if_
  @if_
end

#metadataObject (readonly)

Returns the value of attribute metadata.



12
13
14
# File 'lib/trycourier/send/types/channel.rb', line 12

def 
  @metadata
end

#overrideObject (readonly)

Returns the value of attribute override.



12
13
14
# File 'lib/trycourier/send/types/channel.rb', line 12

def override
  @override
end

#providersObject (readonly)

Returns the value of attribute providers.



12
13
14
# File 'lib/trycourier/send/types/channel.rb', line 12

def providers
  @providers
end

#routing_methodObject (readonly)

Returns the value of attribute routing_method.



12
13
14
# File 'lib/trycourier/send/types/channel.rb', line 12

def routing_method
  @routing_method
end

#timeoutsObject (readonly)

Returns the value of attribute timeouts.



12
13
14
# File 'lib/trycourier/send/types/channel.rb', line 12

def timeouts
  @timeouts
end

Class Method Details

.from_json(json_object:) ⇒ Send::Channel

Deserialize a JSON object to an instance of Channel

Parameters:

  • json_object (JSON)

Returns:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/trycourier/send/types/channel.rb', line 59

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  brand_id = struct.brand_id
  providers = struct.providers
  routing_method = struct.routing_method
  if_ = struct.if
  if parsed_json["timeouts"].nil?
    timeouts = nil
  else
    timeouts = parsed_json["timeouts"].to_json
    timeouts = Send::Timeouts.from_json(json_object: timeouts)
  end
  override = struct.override
  if parsed_json["metadata"].nil?
     = nil
  else
     = parsed_json["metadata"].to_json
     = Send::ChannelMetadata.from_json(json_object: )
  end
  new(brand_id: brand_id, providers: providers, routing_method: routing_method, if_: if_, timeouts: timeouts,
      override: override, metadata: , 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)


102
103
104
105
106
107
108
109
110
# File 'lib/trycourier/send/types/channel.rb', line 102

def self.validate_raw(obj:)
  obj.brand_id&.is_a?(String) != false || raise("Passed value for field obj.brand_id is not the expected type, validation failed.")
  obj.providers&.is_a?(Array) != false || raise("Passed value for field obj.providers is not the expected type, validation failed.")
  obj.routing_method&.is_a?(Send::RoutingMethod) != false || raise("Passed value for field obj.routing_method is not the expected type, validation failed.")
  obj.if_&.is_a?(String) != false || raise("Passed value for field obj.if_ is not the expected type, validation failed.")
  obj.timeouts.nil? || Send::Timeouts.validate_raw(obj: obj.timeouts)
  obj.override&.is_a?(Send::Override) != false || raise("Passed value for field obj.override is not the expected type, validation failed.")
  obj..nil? || Send::ChannelMetadata.validate_raw(obj: obj.)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of Channel to a JSON object

Returns:

  • (JSON)


86
87
88
89
90
91
92
93
94
95
96
# File 'lib/trycourier/send/types/channel.rb', line 86

def to_json(*_args)
  {
    "brand_id": @brand_id,
    "providers": @providers,
    "routing_method": @routing_method,
    "if": @if_,
    "timeouts": @timeouts,
    "override": @override,
    "metadata": @metadata
  }.to_json
end