Class: Courier::Resources::Users::Tokens
- Inherits:
-
Object
- Object
- Courier::Resources::Users::Tokens
- Defined in:
- lib/courier/resources/users/tokens.rb,
sig/courier/resources/users/tokens.rbs
Overview
Register and manage the APNS and FCM device tokens Courier delivers push notifications to.
Instance Method Summary collapse
-
#add_multiple(user_id, request_options: {}) ⇒ nil
Registers several device tokens for a user in one call, overwriting any stored token with a matching value.
-
#add_single(token, user_id:, provider_key:, device: nil, expiry_date: nil, properties: nil, tracking: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::Users::TokenAddSingleParams for more details.
-
#delete(token, user_id:, request_options: {}) ⇒ nil
Deletes one device token for a user, addressed by the token value, so push sends no longer target that device.
-
#initialize(client:) ⇒ Tokens
constructor
private
A new instance of Tokens.
-
#list(user_id, request_options: {}) ⇒ Courier::Models::Users::TokenListResponse
Returns every device token registered for a user, each with its provider key, status, and expiry date.
-
#retrieve(token, user_id:, request_options: {}) ⇒ Courier::Models::Users::TokenRetrieveResponse
Returns one device token with its provider key, status and status reason, expiry date, and any properties stored alongside it.
-
#update(token, user_id:, patch:, request_options: {}) ⇒ nil
Applies a JSON Patch to a device token, changing its status, expiry, or properties without re-registering it.
Constructor Details
#initialize(client:) ⇒ Tokens
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 Tokens.
183 184 185 |
# File 'lib/courier/resources/users/tokens.rb', line 183 def initialize(client:) @client = client end |
Instance Method Details
#add_multiple(user_id, request_options: {}) ⇒ nil
Registers several device tokens for a user in one call, overwriting any stored token with a matching value.
129 130 131 132 133 134 135 136 |
# File 'lib/courier/resources/users/tokens.rb', line 129 def add_multiple(user_id, params = {}) @client.request( method: :put, path: ["users/%1$s/tokens", user_id], model: NilClass, options: params[:request_options] ) end |
#add_single(token, user_id:, provider_key:, device: nil, expiry_date: nil, properties: nil, tracking: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::Users::TokenAddSingleParams for more details.
Registers one device token for a user against a provider key, overwriting the token if it already exists. Push sends resolve tokens per user.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/courier/resources/users/tokens.rb', line 165 def add_single(token, params) parsed, = Courier::Users::TokenAddSingleParams.dump_request(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/tokens/%2$s", user_id, token], body: parsed, model: NilClass, options: ) end |
#delete(token, user_id:, request_options: {}) ⇒ nil
Deletes one device token for a user, addressed by the token value, so push sends no longer target that device.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/courier/resources/users/tokens.rb', line 103 def delete(token, params) parsed, = Courier::Users::TokenDeleteParams.dump_request(params) user_id = parsed.delete(:user_id) do raise ArgumentError.new("missing required path argument #{_1}") end @client.request( method: :delete, path: ["users/%1$s/tokens/%2$s", user_id, token], model: NilClass, options: ) end |
#list(user_id, request_options: {}) ⇒ Courier::Models::Users::TokenListResponse
Returns every device token registered for a user, each with its provider key, status, and expiry date.
80 81 82 83 84 85 86 87 |
# File 'lib/courier/resources/users/tokens.rb', line 80 def list(user_id, params = {}) @client.request( method: :get, path: ["users/%1$s/tokens", user_id], model: Courier::Models::Users::TokenListResponse, options: params[:request_options] ) end |
#retrieve(token, user_id:, request_options: {}) ⇒ Courier::Models::Users::TokenRetrieveResponse
Returns one device token with its provider key, status and status reason, expiry date, and any properties stored alongside it.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/courier/resources/users/tokens.rb', line 23 def retrieve(token, params) parsed, = Courier::Users::TokenRetrieveParams.dump_request(params) user_id = parsed.delete(:user_id) do raise ArgumentError.new("missing required path argument #{_1}") end @client.request( method: :get, path: ["users/%1$s/tokens/%2$s", user_id, token], model: Courier::Models::Users::TokenRetrieveResponse, options: ) end |
#update(token, user_id:, patch:, request_options: {}) ⇒ nil
Applies a JSON Patch to a device token, changing its status, expiry, or properties without re-registering it.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/courier/resources/users/tokens.rb', line 53 def update(token, params) parsed, = Courier::Users::TokenUpdateParams.dump_request(params) user_id = parsed.delete(:user_id) do raise ArgumentError.new("missing required path argument #{_1}") end @client.request( method: :patch, path: ["users/%1$s/tokens/%2$s", user_id, token], body: parsed, model: NilClass, options: ) end |