Class: NewDemoApiClient::AsyncUserClient

Inherits:
Object
  • Object
show all
Defined in:
lib/test_sdk/user/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ NewDemoApiClient::AsyncUserClient

Parameters:



189
190
191
# File 'lib/test_sdk/user/client.rb', line 189

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientNewDemoApiClient::AsyncRequestClient (readonly)



185
186
187
# File 'lib/test_sdk/user/client.rb', line 185

def request_client
  @request_client
end

Instance Method Details

#create_or_replace_api_key(request_options: nil) ⇒ NewDemoApiClient::CreateAPIKeyResponse

Create or replace an API key for the current user.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.create_or_replace_api_key

Parameters:

Returns:



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/test_sdk/user/client.rb', line 307

def create_or_replace_api_key(request_options: nil)
  Async do
    response = @request_client.conn.put do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/user/api-key"
    end
    NewDemoApiClient::CreateAPIKeyResponse.from_json(json_object: response.body)
  end
end

#delete_api_key(request_options: nil) ⇒ Hash{String => Object}

Delete an API key for the current user.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.delete_api_key

Parameters:

Returns:

  • (Hash{String => Object})


340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/test_sdk/user/client.rb', line 340

def delete_api_key(request_options: nil)
  Async do
    response = @request_client.conn.delete do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/user/api-key"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json
  end
end

#get_token(api_key:, request_options: nil) ⇒ NewDemoApiClient::AuthenticateAPIKeyResponse

Authenticate an API key and return an access token

Returns a client JWT for the provided API key, where the JWT contains claims for
permissions and access and can be
refreshed as part of an OAuth flow.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.get_token(api_key: "api_key")

Parameters:

Returns:



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/test_sdk/user/client.rb', line 208

def get_token(api_key:, request_options: nil)
  Async do
    response = @request_client.conn.post do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = { **(request_options&.additional_body_parameters || {}), api_key: api_key }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/auth/get-token"
    end
    NewDemoApiClient::AuthenticateAPIKeyResponse.from_json(json_object: response.body)
  end
end

#me(request_options: nil) ⇒ NewDemoApiClient::UserWithPermissionsResponse

Get the current user.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.me

Parameters:

Returns:



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/test_sdk/user/client.rb', line 239

def me(request_options: nil)
  Async do
    response = @request_client.conn.get do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      unless request_options.nil? || request_options&.additional_body_parameters.nil?
        req.body = { **(request_options&.additional_body_parameters || {}) }.compact
      end
      req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/user/me"
    end
    NewDemoApiClient::UserWithPermissionsResponse.from_json(json_object: response.body)
  end
end

#upload_user_avatar(image:, request_options: nil) ⇒ NewDemoApiClient::UserWithGroupsResponse

Upload an avatar for a user.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.upload_user_avatar(image: my_file.txt)

Parameters:

Returns:



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/test_sdk/user/client.rb', line 273

def upload_user_avatar(image:, request_options: nil)
  Async do
    response = @request_client.conn.post do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        image: NewDemoApiClient::FileUtilities.as_faraday_multipart(file_like: image)
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/user/me/avatar"
    end
    NewDemoApiClient::UserWithGroupsResponse.from_json(json_object: response.body)
  end
end