Class: Chroma::Resources::Tenant

Inherits:
Object
  • Object
show all
Includes:
APIOperations::Request
Defined in:
lib/chroma/resources/tenant.rb

Overview

A Tenant class represents a tenant by its ID and name.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Request

included

Constructor Details

#initialize(id:, name:) ⇒ Tenant

Returns a new instance of Tenant.



12
13
14
15
# File 'lib/chroma/resources/tenant.rb', line 12

def initialize(id:, name:)
  @id = id
  @name = name
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/chroma/resources/tenant.rb', line 9

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/chroma/resources/tenant.rb', line 10

def name
  @name
end

Class Method Details

.create(name) ⇒ Object

Create a new tenant.

name - The name of the tenant.

Examples

tenant = Chorma::Resources::Tenant.create("tenant-name")

Returns true if the tenant was successfully created, raises Chroma::APIError otherwise.



26
27
28
29
30
31
32
33
34
# File 'lib/chroma/resources/tenant.rb', line 26

def self.create(name)
  payload = {name: name}

  result = execute_request(:post, "#{Chroma.api_url}/tenants", payload)

  return true if result.success?

  raise_failure_error(result)
end

.get(tenant_name) ⇒ Object

Retrieves a tenant.

tenant_name - The name of the tenant to retrieve.

Examples

Chroma::Resources::Tenant.get("tenant-name")

Returns The retrieved tenant object. Raises Chroma::APIError if not found.



45
46
47
48
49
50
51
52
53
54
# File 'lib/chroma/resources/tenant.rb', line 45

def self.get(tenant_name)
  result = execute_request(:get, "#{Chroma.api_url}/tenants/#{tenant_name}")

  if result.success?
    data = result.success.body
    new(id: data["id"], name: data["name"])
  else
    raise_failure_error(result)
  end
end