Class: Courier::Resources::RoutingStrategies

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/routing_strategies.rb,
sig/courier/resources/routing_strategies.rbs

Overview

Define reusable channel routing and failover strategies, and see which templates use them.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ RoutingStrategies

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RoutingStrategies.

Parameters:



186
187
188
# File 'lib/courier/resources/routing_strategies.rb', line 186

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(id, request_options: {}) ⇒ nil

Archive a routing strategy. The strategy must not have associated notification templates. Unlink all templates before archiving.

Parameters:

  • id (String)

    Routing strategy ID (rs_ prefix).

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)
  • request_options: (Courier::request_opts)

Returns:

  • (nil)

See Also:



111
112
113
114
115
116
117
118
# File 'lib/courier/resources/routing_strategies.rb', line 111

def archive(id, params = {})
  @client.request(
    method: :delete,
    path: ["routing-strategies/%1$s", id],
    model: NilClass,
    options: params[:request_options]
  )
end

#create(name:, routing:, channels: nil, description: nil, providers: nil, tags: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::RoutingStrategyGetResponse

Some parameter documentations has been truncated, see Models::RoutingStrategyCreateParams for more details.

Create a routing strategy. Requires a name and routing configuration at minimum. Channels and providers default to empty if omitted.

Parameters:

  • name (String)

    Body param: Human-readable name for the routing strategy.

  • routing (Courier::Models::MessageRouting)

    Body param: Routing tree defining channel selection method and order.

  • channels (Hash{Symbol=>Courier::Models::Channel}, nil)

    Body param: Per-channel delivery configuration. Defaults to empty if omitted.

  • description (String, nil)

    Body param: Optional description of the routing strategy.

  • providers (Hash{Symbol=>Courier::Models::MessageProvidersType}, nil)

    Body param: Per-provider delivery configuration. Defaults to empty if omitted.

  • tags (Array<String>, nil)

    Body param: Optional tags for categorization.

  • idempotency_key (String)

    Header param: A unique key that makes this request idempotent. If Courier receiv

  • x_idempotency_expiration (String)

    Header param: How long the idempotency key remains valid, as a Unix epoch timest

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/courier/resources/routing_strategies.rb', line 37

def create(params)
  parsed, options = Courier::RoutingStrategyCreateParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: "routing-strategies",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::RoutingStrategyGetResponse,
    options: options
  )
end

#list(cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::RoutingStrategyListResponse

List routing strategies in your workspace. Returns metadata only (no routing/channels/providers content). Use GET /routing-strategies/id for full details.

Parameters:

  • cursor (String, nil)

    Opaque pagination cursor from a previous response. Omit for the first page.

  • limit (Integer)

    Maximum number of results per page. Default 20, max 100.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/courier/resources/routing_strategies.rb', line 87

def list(params = {})
  parsed, options = Courier::RoutingStrategyListParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "routing-strategies",
    query: query,
    model: Courier::RoutingStrategyListResponse,
    options: options
  )
end

#list_notifications(id, cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::AssociatedNotificationListResponse

Returns the notification templates using a routing strategy, with paging. Check this before changing a strategy that templates depend on.

Parameters:

  • id (String)

    Routing strategy ID (rs_ prefix).

  • cursor (String, nil)

    Opaque pagination cursor from a previous response. Omit for the first page.

  • limit (Integer)

    Maximum number of results per page. Default 20, max 100.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/courier/resources/routing_strategies.rb', line 136

def list_notifications(id, params = {})
  parsed, options = Courier::RoutingStrategyListNotificationsParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["routing-strategies/%1$s/notifications", id],
    query: query,
    model: Courier::AssociatedNotificationListResponse,
    options: options
  )
end

#replace(id, name:, routing:, channels: nil, description: nil, providers: nil, tags: nil, request_options: {}) ⇒ Courier::Models::RoutingStrategyGetResponse

Replace a routing strategy. Full document replacement; the caller must send the complete desired state. Missing optional fields are cleared.

Parameters:

  • id (String)

    Routing strategy ID (rs_ prefix).

  • name (String)

    Human-readable name for the routing strategy.

  • routing (Courier::Models::MessageRouting)

    Routing tree defining channel selection method and order.

  • channels (Hash{Symbol=>Courier::Models::Channel}, nil)

    Per-channel delivery configuration. Omit to clear.

  • description (String, nil)

    Optional description. Omit or null to clear.

  • providers (Hash{Symbol=>Courier::Models::MessageProvidersType}, nil)

    Per-provider delivery configuration. Omit to clear.

  • tags (Array<String>, nil)

    Optional tags. Omit or null to clear.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



172
173
174
175
176
177
178
179
180
181
# File 'lib/courier/resources/routing_strategies.rb', line 172

def replace(id, params)
  parsed, options = Courier::RoutingStrategyReplaceParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["routing-strategies/%1$s", id],
    body: parsed,
    model: Courier::RoutingStrategyGetResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ Courier::Models::RoutingStrategyGetResponse

Returns one routing strategy by id with its name, tags, channels, and the routing rules that decide provider order and fallback.

Parameters:

  • id (String)

    Routing strategy ID (rs_ prefix).

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



63
64
65
66
67
68
69
70
# File 'lib/courier/resources/routing_strategies.rb', line 63

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["routing-strategies/%1$s", id],
    model: Courier::RoutingStrategyGetResponse,
    options: params[:request_options]
  )
end