Class: Braintrust::Resources::Groups

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Groups

Returns a new instance of Groups.



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

def initialize(client:)
  @client = client
end

Instance Method Details

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

Create a new group. If there is an existing group with the same name as the one specified in the request, will return the existing group 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 group

  • :description (String)

    Textual description of the group

  • :member_groups (Array<String>)

    Ids of the groups this group inherits from

    An inheriting group has all the users contained in its member groups, as well as all of their inherited users

  • :member_users (Array<String>)

    Ids of users which belong to this group

  • :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 group belongs in.

Returns:



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

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

#delete(group_id, opts = {}) ⇒ Braintrust::Models::Group

Delete a group object by its id

Parameters:

  • group_id (String)

    Group id

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

    Options to specify HTTP behaviour for this request.

Returns:



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

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

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

List out all groups. The groups are sorted by creation date, with the most recently-created groups 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

  • :group_name (String)

    Name of the group to search for

  • :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

  • :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:



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

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

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

Create or replace group. If there is an existing group with the same name as the one specified in the request, will replace the existing group 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 group

  • :description (String)

    Textual description of the group

  • :member_groups (Array<String>)

    Ids of the groups this group inherits from

    An inheriting group has all the users contained in its member groups, as well as all of their inherited users

  • :member_users (Array<String>)

    Ids of users which belong to this group

  • :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 group belongs in.

Returns:



143
144
145
146
147
148
149
150
# File 'lib/braintrust/resources/groups.rb', line 143

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

#retrieve(group_id, opts = {}) ⇒ Braintrust::Models::Group

Get a group object by its id

Parameters:

  • group_id (String)

    Group 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/groups.rb', line 43

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

#update(group_id, params = {}, opts = {}) ⇒ Braintrust::Models::Group

Partially update a group 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:

  • group_id (String)

    Group 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):

  • :add_member_groups (Array<String>)

    A list of group IDs to add to the group's inheriting-from set

  • :add_member_users (Array<String>)

    A list of user IDs to add to the group

  • :description (String)

    Textual description of the group

  • :name (String)

    Name of the group

  • :remove_member_groups (Array<String>)

    A list of group IDs to remove from the group's inheriting-from set

  • :remove_member_users (Array<String>)

    A list of user IDs to remove from the group

Returns:



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

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