Class: Chroma::Resources::Tenant
- Inherits:
-
Object
- Object
- Chroma::Resources::Tenant
- 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
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.create(name) ⇒ Object
Create a new tenant.
-
.get(tenant_name) ⇒ Object
Retrieves a tenant.
Instance Method Summary collapse
-
#initialize(id:, name:) ⇒ Tenant
constructor
A new instance of Tenant.
Methods included from APIOperations::Request
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/chroma/resources/tenant.rb', line 9 def id @id end |
#name ⇒ Object (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
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 |