Class: Courier::Resources::WorkspacePreferences::Topics

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

Overview

Manage the workspace catalog of subscription topics, the sections that group them, and publishing the preference page.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Topics

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 Topics.

Parameters:



182
183
184
# File 'lib/courier/resources/workspace_preferences/topics.rb', line 182

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(topic_id, section_id:, request_options: {}) ⇒ nil

Archives a subscription topic and removes it from its workspace preference, addressed by section id and topic id.

Parameters:

  • topic_id (String)

    Id of the subscription preference topic.

  • section_id (String)

    Id of the workspace preference.

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

Returns:

  • (nil)

See Also:



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/courier/resources/workspace_preferences/topics.rb', line 119

def archive(topic_id, params)
  parsed, options = Courier::WorkspacePreferences::TopicArchiveParams.dump_request(params)
  section_id =
    parsed.delete(:section_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["preferences/sections/%1$s/topics/%2$s", section_id, topic_id],
    model: NilClass,
    options: options
  )
end

#create(section_id, default_status:, name:, allowed_preferences: nil, description: nil, include_unsubscribe_header: nil, routing_options: nil, topic_data: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::WorkspacePreferenceTopicGetResponse

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

Creates a subscription topic inside a workspace preference. The default status sets whether users start opted in, opted out, or required.

Parameters:

  • section_id (String)

    Path param: Id of the workspace preference to create the topic in.

  • default_status (Symbol, Courier::Models::WorkspacePreferenceTopicCreateRequest::DefaultStatus)

    Body param: The default subscription status applied when a recipient has not set

  • name (String)

    Body param: Human-readable name for the preference topic.

  • allowed_preferences (Array<Symbol, Courier::Models::WorkspacePreferenceTopicCreateRequest::AllowedPreference>, nil)

    Body param: Preference controls a recipient may customize for this topic. Defaul

  • description (String, nil)

    Body param: Optional description shown under the topic on the hosted preferences

  • include_unsubscribe_header (Boolean, nil)

    Body param: Whether to include a list-unsubscribe header on emails for this topi

  • routing_options (Array<Symbol, Courier::Models::ChannelClassification>, nil)

    Body param: Default channels delivered for this topic. Defaults to empty if omit

  • topic_data (Hash{Symbol=>Object}, nil)

    Body param: Arbitrary metadata associated with the topic.

  • 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:



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/courier/resources/workspace_preferences/topics.rb', line 42

def create(section_id, params)
  parsed, options = Courier::WorkspacePreferences::TopicCreateParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: ["preferences/sections/%1$s/topics", section_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::WorkspacePreferenceTopicGetResponse,
    options: options
  )
end

#list(section_id, request_options: {}) ⇒ Courier::Models::WorkspacePreferenceTopicListResponse

Returns the subscription topics inside a workspace preference, each with its default status and routing options.

Parameters:

  • section_id (String)

    Id of the workspace preference.

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

Returns:

See Also:



96
97
98
99
100
101
102
103
# File 'lib/courier/resources/workspace_preferences/topics.rb', line 96

def list(section_id, params = {})
  @client.request(
    method: :get,
    path: ["preferences/sections/%1$s/topics", section_id],
    model: Courier::WorkspacePreferenceTopicListResponse,
    options: params[:request_options]
  )
end

#replace(topic_id, section_id:, default_status:, name:, allowed_preferences: nil, description: nil, include_unsubscribe_header: nil, routing_options: nil, topic_data: nil, request_options: {}) ⇒ Courier::Models::WorkspacePreferenceTopicGetResponse

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

Replace a topic within a workspace preference. Full document replacement; missing optional fields are cleared. Same 404 rules as GET.

Parameters:

  • topic_id (String)

    Path param: Id of the subscription preference topic.

  • section_id (String)

    Path param: Id of the workspace preference.

  • default_status (Symbol, Courier::Models::WorkspacePreferenceTopicReplaceRequest::DefaultStatus)

    Body param: The default subscription status applied when a recipient has not set

  • name (String)

    Body param: Human-readable name for the preference topic.

  • allowed_preferences (Array<Symbol, Courier::Models::WorkspacePreferenceTopicReplaceRequest::AllowedPreference>, nil)

    Body param: Preference controls a recipient may customize. Omit to clear.

  • description (String, nil)

    Body param: Optional description shown under the topic on the hosted preferences

  • include_unsubscribe_header (Boolean, nil)

    Body param: Whether to include a list-unsubscribe header on emails for this topi

  • routing_options (Array<Symbol, Courier::Models::ChannelClassification>, nil)

    Body param: Default channels delivered for this topic. Omit to clear.

  • topic_data (Hash{Symbol=>Object}, nil)

    Body param: Arbitrary metadata associated with the topic. Omit to clear.

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

Returns:

See Also:



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/courier/resources/workspace_preferences/topics.rb', line 164

def replace(topic_id, params)
  parsed, options = Courier::WorkspacePreferences::TopicReplaceParams.dump_request(params)
  section_id =
    parsed.delete(:section_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["preferences/sections/%1$s/topics/%2$s", section_id, topic_id],
    body: parsed,
    model: Courier::WorkspacePreferenceTopicGetResponse,
    options: options
  )
end

#retrieve(topic_id, section_id:, request_options: {}) ⇒ Courier::Models::WorkspacePreferenceTopicGetResponse

Returns one subscription topic with its default status, routing options, allowed preferences, and unsubscribe header setting.

Parameters:

  • topic_id (String)

    Id of the subscription preference topic.

  • section_id (String)

    Id of the workspace preference.

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

Returns:

See Also:



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/courier/resources/workspace_preferences/topics.rb', line 70

def retrieve(topic_id, params)
  parsed, options = Courier::WorkspacePreferences::TopicRetrieveParams.dump_request(params)
  section_id =
    parsed.delete(:section_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["preferences/sections/%1$s/topics/%2$s", section_id, topic_id],
    model: Courier::WorkspacePreferenceTopicGetResponse,
    options: options
  )
end