Class: Courier::Resources::Users::Tokens

Inherits:
Object
  • Object
show all
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

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.

Parameters:



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.

Parameters:

  • user_id (String)

    The user's ID. This can be any uniquely identifiable string.

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

Returns:

  • (nil)

See Also:



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.

Parameters:

Returns:

  • (nil)

See Also:



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, options = 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: 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.

Parameters:

  • token (String)

    The full token string.

  • user_id (String)

    The user's ID. This can be any uniquely identifiable string.

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

Returns:

  • (nil)

See Also:



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, options = 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: 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.

Parameters:

  • user_id (String)

    The user's ID. This can be any uniquely identifiable string.

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

Returns:

See Also:



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.

Parameters:

  • token (String)

    The full token string.

  • user_id (String)

    The user's ID. This can be any uniquely identifiable string.

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

Returns:

See Also:



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, options = 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: 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.

Parameters:

Returns:

  • (nil)

See Also:



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, options = 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: options
  )
end