Class: TrophyApiClient::Admin::AsyncTenantsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trophy_api_client/admin/tenants/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ TrophyApiClient::Admin::AsyncTenantsClient

Parameters:



195
196
197
# File 'lib/trophy_api_client/admin/tenants/client.rb', line 195

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientTrophyApiClient::AsyncRequestClient (readonly)



191
192
193
# File 'lib/trophy_api_client/admin/tenants/client.rb', line 191

def request_client
  @request_client
end

Instance Method Details

#create(request:, request_options: nil) ⇒ TrophyApiClient::CreateTenantsResponse

Create tenants.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.tenants.create(request: [{ customer_id: "customer_12345", name: "Acme Corp" }, { customer_id: "customer_67890", name: "Globex Inc" }])

Parameters:

Returns:



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/trophy_api_client/admin/tenants/client.rb', line 253

def create(request:, 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["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.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 || {}), **(request_options&.additional_body_parameters || {}) }.compact
      req.url "#{@request_client.get_url(environment: admin, request_options: request_options)}/tenants"
    end
    TrophyApiClient::CreateTenantsResponse.from_json(json_object: response.body)
  end
end

#delete(ids: nil, request_options: nil) ⇒ TrophyApiClient::DeleteTenantsResponse

Delete tenants by ID.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.tenants.delete

Parameters:

  • ids (String) (defaults to: nil)

    Tenant IDs to delete. Repeat the query param or provide a comma-separated list.

  • request_options (TrophyApiClient::RequestOptions) (defaults to: nil)

Returns:



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/trophy_api_client/admin/tenants/client.rb', line 286

def delete(ids: nil, 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["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      req.params = { **(request_options&.additional_query_parameters || {}), "ids": ids }.compact
      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(environment: admin, request_options: request_options)}/tenants"
    end
    TrophyApiClient::DeleteTenantsResponse.from_json(json_object: response.body)
  end
end

#get(id:, request_options: nil) ⇒ TrophyApiClient::AdminTenant

Get a tenant by ID.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.tenants.get(id: "550e8400-e29b-41d4-a716-446655440000")

Parameters:

Returns:



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/trophy_api_client/admin/tenants/client.rb', line 352

def get(id:, 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["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.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(environment: admin, request_options: request_options)}/tenants/#{id}"
    end
    TrophyApiClient::AdminTenant.from_json(json_object: response.body)
  end
end

#list(limit: nil, skip: nil, request_options: nil) ⇒ TrophyApiClient::LIST_TENANTS_RESPONSE

List tenants in the current environment.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.tenants.list(limit: 1, skip: 1)

Parameters:

  • limit (Integer) (defaults to: nil)

    Number of records to return.

  • skip (Integer) (defaults to: nil)

    Number of records to skip from the start of the list.

  • request_options (TrophyApiClient::RequestOptions) (defaults to: nil)

Returns:



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/trophy_api_client/admin/tenants/client.rb', line 212

def list(limit: nil, skip: nil, 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["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      req.params = {
        **(request_options&.additional_query_parameters || {}),
        "limit": limit,
        "skip": skip
      }.compact
      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(environment: admin, request_options: request_options)}/tenants"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json&.map do |item|
      item = item.to_json
      TrophyApiClient::AdminTenant.from_json(json_object: item)
    end
  end
end

#update(request:, request_options: nil) ⇒ TrophyApiClient::UpdateTenantsResponse

Update tenants by ID.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.tenants.update(request: [{ id: "550e8400-e29b-41d4-a716-446655440000", name: "Acme Corporation" }])

Parameters:

Returns:



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/trophy_api_client/admin/tenants/client.rb', line 319

def update(request:, request_options: nil)
  Async do
    response = @request_client.conn.patch do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.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 || {}), **(request_options&.additional_body_parameters || {}) }.compact
      req.url "#{@request_client.get_url(environment: admin, request_options: request_options)}/tenants"
    end
    TrophyApiClient::UpdateTenantsResponse.from_json(json_object: response.body)
  end
end