collections.go

v1.0.0
Doc Versions Source
1
package bitwarden
2
3
import (
4
	"context"
5
	"net/url"
6
)
7
8
// CollectionsService handles collection operations (read-only for user collections).
9
type CollectionsService struct {
10
	t *transport
11
}
12
13
// List returns all collections, optionally filtered.
14
func (s *CollectionsService) List(ctx context.Context, organizationID, search string) ([]Collection, error) {
15
	q := url.Values{}
16
	if organizationID != "" {
17
		q.Set("organizationid", organizationID)
18
	}
19
	if search != "" {
20
		q.Set("search", search)
21
	}
22
	data, err := s.t.get(ctx, "/list/object/collections", q)
23
	if err != nil {
24
		return nil, err
25
	}
26
	return decodeListResponse[Collection](data)
27
}
28
29
// Get returns a single collection by ID.
30
func (s *CollectionsService) Get(ctx context.Context, id string) (*Collection, error) {
31
	data, err := s.t.get(ctx, "/object/collection/"+id, nil)
32
	if err != nil {
33
		return nil, err
34
	}
35
	return decodeObjectResponsePtr[Collection](data)
36
}
37

Source Files