Class: Courier::Resources::WorkspacePreferences

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/workspace_preferences.rb,
lib/courier/resources/workspace_preferences/topics.rb,
sig/courier/resources/workspace_preferences.rbs,
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.

Defined Under Namespace

Classes: Topics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ WorkspacePreferences

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

Parameters:



222
223
224
225
# File 'lib/courier/resources/workspace_preferences.rb', line 222

def initialize(client:)
  @client = client
  @topics = Courier::Resources::WorkspacePreferences::Topics.new(client: client)
end

Instance Attribute Details

#topics ⇒ Courier::Resources::WorkspacePreferences::Topics (readonly)



9
10
11
# File 'lib/courier/resources/workspace_preferences.rb', line 9

def topics
  @topics
end

Instance Method Details

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

Archive a workspace preference. The workspace preference must be empty: delete its topics first, otherwise the request fails with 409.

Parameters:

  • section_id (String) —

    Id of the workspace preference.

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

Returns:

  • (nil)

See Also:



102
103
104
105
106
107
108
109
# File 'lib/courier/resources/workspace_preferences.rb', line 102

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

#create(name:, description: nil, has_custom_routing: nil, routing_options: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::WorkspacePreferenceGetResponse

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

Creates a workspace preference and returns its generated id. Add subscription topics to it afterwards with the topics endpoint.

Parameters:

  • name (String) —

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

  • description (String, nil) —

    Body param: Optional description shown under the section on the hosted preferenc

  • has_custom_routing (Boolean, nil) —

    Body param: Whether the workspace preference defines custom routing for its topi

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

    Body param: Default channels for the workspace preference. Defaults to empty if

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



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

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

#list(request_options: {}) ⇒ Courier::Models::WorkspacePreferenceListResponse

Returns the workspace's preferences, each embedding its subscription topics, routing options, and whether custom routing is allowed.

Parameters:

Returns:

See Also:



81
82
83
84
85
86
87
88
# File 'lib/courier/resources/workspace_preferences.rb', line 81

def list(params = {})
  @client.request(
    method: :get,
    path: "preferences/sections",
    model: Courier::WorkspacePreferenceListResponse,
    options: params[:request_options]
  )
end

#list_logs(cursor: nil, limit: nil, since: nil, tenant_id: nil, user_id: nil, request_options: {}) ⇒ Courier::Models::PreferenceLogsListResponse

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

Returns the history of preference changes in this environment, newest first. Each entry records one change a user made to one subscription topic, and carries the value before it where there was one. Supply user_id to read a single user's history instead of the whole environment.

Parameters:

  • cursor (String) —

    A cursor from a previous response's paging.cursor. Continue only while paging.mo

  • limit (Integer) —

    How many entries to return. Defaults to 25.

  • since (String) —

    Return only changes at or after this time, as an ISO-8601 date or date-time. A d

  • tenant_id (String) —

    Narrow to the changes this user made in one tenant context. Only valid together

  • user_id (String) —

    Return only this user's changes. Omit it to read every change in the environment

  • 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/workspace_preferences.rb', line 136

def list_logs(params = {})
  parsed, options = Courier::WorkspacePreferenceListLogsParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "preferences/logs",
    query: query,
    model: Courier::PreferenceLogsListResponse,
    options: options
  )
end

#publish(brand_id: nil, description: nil, heading: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::PublishPreferencesResponse

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

Publishes the workspace preference page, snapshotting every preference and topic, and returns the page id and a preview URL.

Parameters:

  • brand_id (String, nil) —

    Body param: Brand for the hosted page - "default" (workspace default brand), "no

  • description (String, nil) —

    Body param: Description shown under the heading on the hosted preferences page.

  • heading (String, nil) —

    Body param: Heading shown at the top of the hosted preferences page.

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



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

def publish(params = {})
  parsed, options = Courier::WorkspacePreferencePublishParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: "preferences/publish",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::PublishPreferencesResponse,
    options: options
  )
end

#replace(section_id, name:, description: nil, has_custom_routing: nil, routing_options: nil, request_options: {}) ⇒ Courier::Models::WorkspacePreferenceGetResponse

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

Replace a workspace preference. Full document replacement; missing optional fields are cleared. Topics attached to the workspace preference are unaffected.

Parameters:

  • section_id (String) —

    Id of the workspace preference.

  • name (String) —

    Human-readable name for the workspace preference.

  • description (String, nil) —

    Optional description shown under the section on the hosted preferences page. Omi

  • has_custom_routing (Boolean, nil) —

    Whether the workspace preference defines custom routing for its topics.

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

    Default channels for the workspace preference. Omit to clear.

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

Returns:

See Also:



208
209
210
211
212
213
214
215
216
217
# File 'lib/courier/resources/workspace_preferences.rb', line 208

def replace(section_id, params)
  parsed, options = Courier::WorkspacePreferenceReplaceParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["preferences/sections/%1$s", section_id],
    body: parsed,
    model: Courier::WorkspacePreferenceGetResponse,
    options: options
  )
end

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

Returns one workspace preference by id, including its subscription topics, routing options, and custom routing flag.

Parameters:

  • section_id (String) —

    Id of the workspace preference.

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

Returns:

See Also:



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

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