Class: Courier::Users::AsyncTokensClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/users/tokens/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Users::AsyncTokensClient

Parameters:



139
140
141
142
# File 'lib/trycourier/users/tokens/client.rb', line 139

def initialize(request_client:)
  # @type [AsyncRequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



135
136
137
# File 'lib/trycourier/users/tokens/client.rb', line 135

def request_client
  @request_client
end

Instance Method Details

#add(user_id:, token:, request:, request_options: nil) ⇒ Void

Adds a single token to a user and overwrites a matching existing token.

Parameters:

  • user_id (String)

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

  • token (String)

    The full token string.

  • request (Hash)

    Request of type Users::Tokens::UserToken, as a Hash

    • :token (String)

    • :provider_key (Users::Tokens::ProviderKey)

    • :expiry_date (Hash)

    • :properties (Object)

    • :device (Hash)

      • :app_id (String)

      • :ad_id (String)

      • :device_id (String)

      • :platform (String)

      • :manufacturer (String)

      • :model (String)

    • :tracking (Hash)

      • :os_version (String)

      • :ip (String)

      • :lat (String)

      • :long (String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/trycourier/users/tokens/client.rb', line 185

def add(user_id:, token:, request:, request_options: nil)
  Async do
    @request_client.conn.put("/users/#{user_id}/tokens/#{token}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    end
  end
end

#add_multiple(user_id:, request_options: nil) ⇒ Void

Adds multiple tokens to a user and overwrites matching existing tokens.

Parameters:

  • user_id (String)

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

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/trycourier/users/tokens/client.rb', line 149

def add_multiple(user_id:, request_options: nil)
  Async do
    @request_client.conn.put("/users/#{user_id}/tokens") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
  end
end

#get(user_id:, token:, request_options: nil) ⇒ Users::Tokens::GetUserTokenResponse

Get single token available for a ‘:token`

Parameters:

  • user_id (String)

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

  • token (String)

    The full token string.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/trycourier/users/tokens/client.rb', line 227

def get(user_id:, token:, request_options: nil)
  Async do
    response = @request_client.conn.get("/users/#{user_id}/tokens/#{token}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Users::Tokens::GetUserTokenResponse.from_json(json_object: response.body)
  end
end

#list(user_id:, request_options: nil) ⇒ Users::Tokens::GET_ALL_TOKENS_RESPONSE

Gets all tokens available for a :user_id

Parameters:

  • user_id (String)

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

  • request_options (RequestOptions) (defaults to: nil)

Returns:



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/trycourier/users/tokens/client.rb', line 246

def list(user_id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/users/#{user_id}/tokens") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    response.body&.map do |v|
      v = v.to_json
      Users::Tokens::UserToken.from_json(json_object: v)
    end
  end
end

#update(user_id:, token:, request:, request_options: nil) ⇒ Void

Apply a JSON Patch (RFC 6902) to the specified token.

Parameters:

  • user_id (String)

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

  • token (String)

    The full token string.

  • request (Hash)

    Request of type Users::Tokens::PatchUserTokenOpts, as a Hash

    • :patch (Array<Users::Tokens::PatchOperation>)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/trycourier/users/tokens/client.rb', line 207

def update(user_id:, token:, request:, request_options: nil)
  Async do
    @request_client.conn.patch("/users/#{user_id}/tokens/#{token}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    end
  end
end