Class: Courier::Resources::Users::Preferences

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

Overview

Read and write a single user's notification preferences, per topic and per channel.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Preferences

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

Parameters:



223
224
225
# File 'lib/courier/resources/users/preferences.rb', line 223

def initialize(client:)
  @client = client
end

Instance Method Details

#bulk_replace(user_id, topics:, tenant_id: nil, request_options: {}) ⇒ Courier::Models::Users::PreferenceBulkReplaceResponse

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

Replaces a user's entire set of preference overrides. Any topic you leave out is reset to its default, so send the full set rather than a subset.

Parameters:

  • user_id (String)

    Path param: A unique identifier associated with the user whose preferences you w

  • topics (Array<Courier::Models::Users::PreferenceBulkReplaceParams::Topic>)

    Body param: The complete set of topic overrides for the user. Up to 50 topics ma

  • tenant_id (String, nil)

    Query param: Replace the preferences of a user for this specific tenant context.

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

Returns:

See Also:



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/courier/resources/users/preferences.rb', line 57

def bulk_replace(user_id, params)
  query_params = [:tenant_id]
  parsed, options = Courier::Users::PreferenceBulkReplaceParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :put,
    path: ["users/%1$s/preferences", user_id],
    query: query,
    body: parsed.except(*query_params),
    model: Courier::Models::Users::PreferenceBulkReplaceResponse,
    options: options
  )
end

#bulk_update(user_id, topics:, tenant_id: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::Users::PreferenceBulkUpdateResponse

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

Adds or updates a user's preferences for several subscription topics at once. Topics you leave out keep whatever they were set to before.

Parameters:

  • user_id (String)

    Path param: A unique identifier associated with the user whose preferences you w

  • topics (Array<Courier::Models::Users::PreferenceBulkUpdateParams::Topic>)

    Body param: The topics to create or update. Between 1 and 50 topics may be provi

  • tenant_id (String, nil)

    Query param: Update the preferences of a user for this specific tenant context.

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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/courier/resources/users/preferences.rb', line 94

def bulk_update(user_id, params)
  query_params = [:tenant_id]
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  parsed, options = Courier::Users::PreferenceBulkUpdateParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :post,
    path: ["users/%1$s/preferences", user_id],
    query: query,
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*query_params, *header_params.keys),
    model: Courier::Models::Users::PreferenceBulkUpdateResponse,
    options: options
  )
end

#delete_topic(topic_id, user_id:, tenant_id: nil, request_options: {}) ⇒ nil

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

Removes a user's override for one subscription topic, resetting it to the effective default from the tenant or workspace.

Parameters:

  • topic_id (String)

    Path param: A unique identifier associated with a subscription topic.

  • user_id (String)

    Path param: A unique identifier associated with the user whose preferences you w

  • tenant_id (String, nil)

    Query param: Delete the preferences of a user for this specific tenant context.

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

Returns:

  • (nil)

See Also:



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/courier/resources/users/preferences.rb', line 130

def delete_topic(topic_id, params)
  parsed, options = Courier::Users::PreferenceDeleteTopicParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  user_id =
    parsed.delete(:user_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["users/%1$s/preferences/%2$s", user_id, topic_id],
    query: query,
    model: NilClass,
    options: options
  )
end

#retrieve(user_id, tenant_id: nil, request_options: {}) ⇒ Courier::Models::Users::PreferenceRetrieveResponse

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

Returns a user's preference overrides with paging, one entry per subscription topic they have set a choice for.

Parameters:

  • user_id (String)

    A unique identifier associated with the user whose preferences you wish to retri

  • tenant_id (String, nil)

    Query the preferences of a user for this specific tenant context.

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

Returns:

See Also:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/courier/resources/users/preferences.rb', line 26

def retrieve(user_id, params = {})
  parsed, options = Courier::Users::PreferenceRetrieveParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["users/%1$s/preferences", user_id],
    query: query,
    model: Courier::Models::Users::PreferenceRetrieveResponse,
    options: options
  )
end

#retrieve_topic(topic_id, user_id:, tenant_id: nil, request_options: {}) ⇒ Courier::Models::Users::PreferenceRetrieveTopicResponse

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

Returns a user's opt-in status and channel choices for one subscription topic, or the effective default if they have set no override.

Parameters:

  • topic_id (String)

    Path param: A unique identifier associated with a subscription topic.

  • user_id (String)

    Path param: A unique identifier associated with the user whose preferences you w

  • tenant_id (String, nil)

    Query param: Query the preferences of a user for this specific tenant context.

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

Returns:

See Also:



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/courier/resources/users/preferences.rb', line 165

def retrieve_topic(topic_id, params)
  parsed, options = Courier::Users::PreferenceRetrieveTopicParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  user_id =
    parsed.delete(:user_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["users/%1$s/preferences/%2$s", user_id, topic_id],
    query: query,
    model: Courier::Models::Users::PreferenceRetrieveTopicResponse,
    options: options
  )
end

#update_or_create_topic(topic_id, user_id:, topic:, tenant_id: nil, request_options: {}) ⇒ Courier::Models::Users::PreferenceUpdateOrCreateTopicResponse

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

Sets a user's opt-in status and channel choices for one subscription topic, overriding the tenant default for that topic only.

Parameters:

  • topic_id (String)

    Path param: A unique identifier associated with a subscription topic.

  • user_id (String)

    Path param: A unique identifier associated with the user whose preferences you w

  • topic (Courier::Models::Users::PreferenceUpdateOrCreateTopicParams::Topic)

    Body param

  • tenant_id (String, nil)

    Query param: Update the preferences of a user for this specific tenant context.

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

Returns:

See Also:



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/courier/resources/users/preferences.rb', line 202

def update_or_create_topic(topic_id, params)
  query_params = [:tenant_id]
  parsed, options = Courier::Users::PreferenceUpdateOrCreateTopicParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed.slice(*query_params))
  user_id =
    parsed.delete(:user_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["users/%1$s/preferences/%2$s", user_id, topic_id],
    query: query,
    body: parsed.except(*query_params),
    model: Courier::Models::Users::PreferenceUpdateOrCreateTopicResponse,
    options: options
  )
end