Class: Braintrust::Resources::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/resources/role.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Role

Returns a new instance of Role.



6
7
8
# File 'lib/braintrust/resources/role.rb', line 6

def initialize(client:)
  @client = client
end

Instance Method Details

#create(params = {}, opts = {}) ⇒ Braintrust::Models::Role

Create a new role. If there is an existing role with the same name as the one specified in the request, will return the existing role unmodified

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :name (String)

    Name of the role

  • :description (String)

    Textual description of the role

  • :member_permissions (Array<Symbol>)

    Permissions which belong to this role

  • :member_roles (Array<String>)

    Ids of the roles this role inherits from

    An inheriting role has all the permissions contained in its member roles, as well as all of their inherited permissions

  • :org_name (String)

    For nearly all users, this parameter should be unnecessary. But in the rare case that your API key belongs to multiple organizations, you may specify the name of the organization the role belongs in.

Returns:



28
29
30
31
32
33
34
35
# File 'lib/braintrust/resources/role.rb', line 28

def create(params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/role"
  req[:body] = params
  req[:model] = Braintrust::Models::Role
  @client.request(req, opts)
end

#delete(role_id, opts = {}) ⇒ Braintrust::Models::Role

Delete a role object by its id

Parameters:

  • role_id (String)

    Role id

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Returns:



117
118
119
120
121
122
123
# File 'lib/braintrust/resources/role.rb', line 117

def delete(role_id, opts = {})
  req = {}
  req[:method] = :delete
  req[:path] = "/v1/role/#{role_id}"
  req[:model] = Braintrust::Models::Role
  @client.request(req, opts)
end

#list(params = {}, opts = {}) ⇒ Braintrust::ListObjects<Braintrust::Models::Role>

List out all roles. The roles are sorted by creation date, with the most recently-created roles coming first

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :ending_before (String)

    Pagination cursor id.

    For example, if the initial item in the last page you fetched had an id of foo, pass ending_before=foo to fetch the previous page. Note: you may only pass one of starting_after and ending_before

  • :ids (Array<String>|String)

    Filter search results to a particular set of object IDs. To specify a list of IDs, include the query param multiple times

  • :limit (Integer)

    Limit the number of objects to return

  • :org_name (String)

    Filter search results to within a particular organization

  • :role_name (String)

    Name of the role to search for

  • :starting_after (String)

    Pagination cursor id.

    For example, if the final item in the last page you fetched had an id of foo, pass starting_after=foo to fetch the next page. Note: you may only pass one of starting_after and ending_before

Returns:



101
102
103
104
105
106
107
108
109
# File 'lib/braintrust/resources/role.rb', line 101

def list(params = {}, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/role"
  req[:query] = params
  req[:page] = Braintrust::ListObjects
  req[:model] = Braintrust::Models::Role
  @client.request(req, opts)
end

#replace(params = {}, opts = {}) ⇒ Braintrust::Models::Role

NOTE: This operation is deprecated and will be removed in a future revision of the API. Create or replace a new role. If there is an existing role with the same name as the one specified in the request, will return the existing role unmodified, will replace the existing role with the provided fields

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :name (String)

    Name of the role

  • :description (String)

    Textual description of the role

  • :member_permissions (Array<Symbol>)

    Permissions which belong to this role

  • :member_roles (Array<String>)

    Ids of the roles this role inherits from

    An inheriting role has all the permissions contained in its member roles, as well as all of their inherited permissions

  • :org_name (String)

    For nearly all users, this parameter should be unnecessary. But in the rare case that your API key belongs to multiple organizations, you may specify the name of the organization the role belongs in.

Returns:



145
146
147
148
149
150
151
152
# File 'lib/braintrust/resources/role.rb', line 145

def replace(params = {}, opts = {})
  req = {}
  req[:method] = :put
  req[:path] = "/v1/role"
  req[:body] = params
  req[:model] = Braintrust::Models::Role
  @client.request(req, opts)
end

#retrieve(role_id, opts = {}) ⇒ Braintrust::Models::Role

Get a role object by its id

Parameters:

  • role_id (String)

    Role id

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Returns:



43
44
45
46
47
48
49
# File 'lib/braintrust/resources/role.rb', line 43

def retrieve(role_id, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/role/#{role_id}"
  req[:model] = Braintrust::Models::Role
  @client.request(req, opts)
end

#update(role_id, params = {}, opts = {}) ⇒ Braintrust::Models::Role

Partially update a role object. Specify the fields to update in the payload. Any object-type fields will be deep-merged with existing content. Currently we do not support removing fields or setting them to null.

Parameters:

  • role_id (String)

    Role id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :description (String)

    Textual description of the role

  • :member_permissions (Array<Symbol>)

    Permissions which belong to this role

  • :member_roles (Array<String>)

    Ids of the roles this role inherits from

    An inheriting role has all the permissions contained in its member roles, as well as all of their inherited permissions

  • :name (String)

    Name of the role

Returns:



69
70
71
72
73
74
75
76
# File 'lib/braintrust/resources/role.rb', line 69

def update(role_id, params = {}, opts = {})
  req = {}
  req[:method] = :patch
  req[:path] = "/v1/role/#{role_id}"
  req[:body] = params
  req[:model] = Braintrust::Models::Role
  @client.request(req, opts)
end