-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization.go
executable file
·158 lines (141 loc) · 6.36 KB
/
organization.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package braintrust
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"github.com/braintrustdata/braintrust-go/internal/apijson"
"github.com/braintrustdata/braintrust-go/internal/apiquery"
"github.com/braintrustdata/braintrust-go/internal/param"
"github.com/braintrustdata/braintrust-go/internal/requestconfig"
"github.com/braintrustdata/braintrust-go/option"
"github.com/braintrustdata/braintrust-go/packages/pagination"
"github.com/braintrustdata/braintrust-go/shared"
)
// OrganizationService contains methods and other services that help with
// interacting with the braintrust API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewOrganizationService] method instead.
type OrganizationService struct {
Options []option.RequestOption
Members *OrganizationMemberService
}
// NewOrganizationService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewOrganizationService(opts ...option.RequestOption) (r *OrganizationService) {
r = &OrganizationService{}
r.Options = opts
r.Members = NewOrganizationMemberService(opts...)
return
}
// Get an organization object by its id
func (r *OrganizationService) Get(ctx context.Context, organizationID string, opts ...option.RequestOption) (res *shared.Organization, err error) {
opts = append(r.Options[:], opts...)
if organizationID == "" {
err = errors.New("missing required organization_id parameter")
return
}
path := fmt.Sprintf("v1/organization/%s", organizationID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Partially update an organization 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.
func (r *OrganizationService) Update(ctx context.Context, organizationID string, body OrganizationUpdateParams, opts ...option.RequestOption) (res *shared.Organization, err error) {
opts = append(r.Options[:], opts...)
if organizationID == "" {
err = errors.New("missing required organization_id parameter")
return
}
path := fmt.Sprintf("v1/organization/%s", organizationID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// List out all organizations. The organizations are sorted by creation date, with
// the most recently-created organizations coming first
func (r *OrganizationService) List(ctx context.Context, query OrganizationListParams, opts ...option.RequestOption) (res *pagination.ListObjects[shared.Organization], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v1/organization"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List out all organizations. The organizations are sorted by creation date, with
// the most recently-created organizations coming first
func (r *OrganizationService) ListAutoPaging(ctx context.Context, query OrganizationListParams, opts ...option.RequestOption) *pagination.ListObjectsAutoPager[shared.Organization] {
return pagination.NewListObjectsAutoPager(r.List(ctx, query, opts...))
}
// Delete an organization object by its id
func (r *OrganizationService) Delete(ctx context.Context, organizationID string, opts ...option.RequestOption) (res *shared.Organization, err error) {
opts = append(r.Options[:], opts...)
if organizationID == "" {
err = errors.New("missing required organization_id parameter")
return
}
path := fmt.Sprintf("v1/organization/%s", organizationID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
type OrganizationUpdateParams struct {
APIURL param.Field[string] `json:"api_url"`
IsUniversalAPI param.Field[bool] `json:"is_universal_api"`
// Name of the organization
Name param.Field[string] `json:"name"`
ProxyURL param.Field[string] `json:"proxy_url"`
RealtimeURL param.Field[string] `json:"realtime_url"`
}
func (r OrganizationUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type OrganizationListParams struct {
// 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`
EndingBefore param.Field[string] `query:"ending_before" format:"uuid"`
// Filter search results to a particular set of object IDs. To specify a list of
// IDs, include the query param multiple times
IDs param.Field[OrganizationListParamsIDsUnion] `query:"ids" format:"uuid"`
// Limit the number of objects to return
Limit param.Field[int64] `query:"limit"`
// Filter search results to within a particular organization
OrgName param.Field[string] `query:"org_name"`
// 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`
StartingAfter param.Field[string] `query:"starting_after" format:"uuid"`
}
// URLQuery serializes [OrganizationListParams]'s query parameters as `url.Values`.
func (r OrganizationListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Filter search results to a particular set of object IDs. To specify a list of
// IDs, include the query param multiple times
//
// Satisfied by [shared.UnionString], [OrganizationListParamsIDsArray].
type OrganizationListParamsIDsUnion interface {
ImplementsOrganizationListParamsIDsUnion()
}
type OrganizationListParamsIDsArray []string
func (r OrganizationListParamsIDsArray) ImplementsOrganizationListParamsIDsUnion() {}