Class: Courier::Resources::Users::Preferences
- Inherits:
-
Object
- Object
- Courier::Resources::Users::Preferences
- Defined in:
- lib/courier/resources/users/preferences.rb,
sig/courier/resources/users/preferences.rbs
Instance Method Summary collapse
-
#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.
-
#bulk_update(user_id, topics:, tenant_id: nil, request_options: {}) ⇒ Courier::Models::Users::PreferenceBulkUpdateResponse
Some parameter documentations has been truncated, see Models::Users::PreferenceBulkUpdateParams for more details.
-
#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.
-
#initialize(client:) ⇒ Preferences
constructor
private
A new instance of Preferences.
-
#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.
-
#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.
-
#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.
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.
242 243 244 |
# File 'lib/courier/resources/users/preferences.rb', line 242 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.
Replace a user's complete set of preference overrides in a single request. The
topics in the request body become the recipient's entire set of overrides:
listed topics are created or updated, and every existing override that is not
included in the body is reset to its topic default. Submitting an empty topics
array is a valid clear-all that resets every existing override.
This operation is validation-atomic (all-or-nothing): structural validation
fails fast with a single 400, and if any topic is semantically invalid (an
unknown topic, a REQUIRED topic that cannot be opted out, or a custom routing
request that is not available on the workspace's plan) the request returns a
single 400 aggregating every failure in errors and writes nothing. On
success it returns 200 with items (the complete resulting override set) and
deleted (the ids of the overrides that were reset to default).
Every topic_id in the response — in items, deleted, and any errors — is
returned in Courier's canonical topic id form, regardless of the form supplied
in the request.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/courier/resources/users/preferences.rb', line 69 def bulk_replace(user_id, params) query_params = [:tenant_id] parsed, = 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: ) end |
#bulk_update(user_id, topics:, tenant_id: nil, request_options: {}) ⇒ Courier::Models::Users::PreferenceBulkUpdateResponse
Some parameter documentations has been truncated, see Models::Users::PreferenceBulkUpdateParams for more details.
Additively create or update a user's preferences for one or more subscription topics in a single request. Only the topics included in the request body are created or updated; any existing overrides for topics not listed are left untouched.
Structural validation of the request body fails fast with a single 400. Beyond
that, each topic is processed independently (partial-success, not
all-or-nothing): valid topics are written and returned in items, while topics
that cannot be applied are collected in errors with a per-topic reason (for
example an unknown topic, a REQUIRED topic that cannot be opted out, a custom
routing request that is not available on the workspace's plan, or a write
failure). The request therefore returns 200 with both lists whenever the body
is structurally valid.
Every topic_id in the response — in both items and errors — is returned in
Courier's canonical topic id form, regardless of the form supplied in the
request.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/courier/resources/users/preferences.rb', line 117 def bulk_update(user_id, params) query_params = [:tenant_id] parsed, = 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, body: parsed.except(*query_params), model: Courier::Models::Users::PreferenceBulkUpdateResponse, 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.
Remove a user's preferences for a specific subscription topic, resetting the topic to its effective default. This operation is idempotent: deleting a preference that does not exist succeeds with no error.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/courier/resources/users/preferences.rb', line 151 def delete_topic(topic_id, params) parsed, = 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: ) 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.
Fetch all user preferences.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/courier/resources/users/preferences.rb', line 23 def retrieve(user_id, params = {}) parsed, = 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: ) 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.
Fetch user preferences for a specific subscription topic.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/courier/resources/users/preferences.rb', line 185 def retrieve_topic(topic_id, params) parsed, = 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: ) 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.
Update or Create user preferences for a specific subscription topic.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/courier/resources/users/preferences.rb', line 221 def update_or_create_topic(topic_id, params) query_params = [:tenant_id] parsed, = 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: ) end |