org_collections.go

v1.0.0
Doc Versions Source
1
package bitwarden
2
3
import (
4
	"context"
5
	"net/url"
6
)
7
8
// OrgCollectionsService handles organization collection operations.
9
type OrgCollectionsService struct {
10
	t *transport
11
}
12
13
// List returns all organization collections. organizationID is required.
14
func (s *OrgCollectionsService) List(ctx context.Context, organizationID string, search string) ([]OrgCollection, error) {
15
	q := url.Values{
16
		"organizationid": {organizationID},
17
	}
18
	if search != "" {
19
		q.Set("search", search)
20
	}
21
	data, err := s.t.get(ctx, "/list/object/org-collections", q)
22
	if err != nil {
23
		return nil, err
24
	}
25
	return decodeListResponse[OrgCollection](data)
26
}
27
28
// Get returns a single organization collection by ID.
29
func (s *OrgCollectionsService) Get(ctx context.Context, id string) (*OrgCollection, error) {
30
	data, err := s.t.get(ctx, "/object/org-collection/"+id, nil)
31
	if err != nil {
32
		return nil, err
33
	}
34
	return decodeObjectResponsePtr[OrgCollection](data)
35
}
36
37
// Create creates a new organization collection.
38
func (s *OrgCollectionsService) Create(ctx context.Context, collection OrgCollection) (*OrgCollection, error) {
39
	data, err := s.t.post(ctx, "/object/org-collection", collection)
40
	if err != nil {
41
		return nil, err
42
	}
43
	return decodeObjectResponsePtr[OrgCollection](data)
44
}
45
46
// Update updates an existing organization collection.
47
func (s *OrgCollectionsService) Update(ctx context.Context, id string, collection OrgCollection) (*OrgCollection, error) {
48
	data, err := s.t.put(ctx, "/object/org-collection/"+id, collection)
49
	if err != nil {
50
		return nil, err
51
	}
52
	return decodeObjectResponsePtr[OrgCollection](data)
53
}
54
55
// Delete deletes an organization collection.
56
func (s *OrgCollectionsService) Delete(ctx context.Context, id string) error {
57
	_, err := s.t.del(ctx, "/object/org-collection/"+id)
58
	return err
59
}
60

Source Files