-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgsa.go
More file actions
92 lines (84 loc) · 2.6 KB
/
Copy pathgsa.go
File metadata and controls
92 lines (84 loc) · 2.6 KB
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
package tango
import (
"context"
"net/url"
)
// ListGsaElibraryContractsOptions filters /api/gsa_elibrary_contracts/.
// Mirrors the Node `ListGsaElibraryContractsOptions` interface and the
// Python `list_gsa_elibrary_contracts` kwargs.
type ListGsaElibraryContractsOptions struct {
ListOptions
Schedule string
ContractNumber string
Key string
PIID string
UEI string
SIN string
Search string
Ordering string
Extra map[string]any
}
func (o *ListGsaElibraryContractsOptions) toQuery() url.Values {
q := url.Values{}
if o == nil {
return q
}
o.ListOptions.applyTo(q)
setIfNotEmpty(q, "schedule", o.Schedule)
setIfNotEmpty(q, "contract_number", o.ContractNumber)
setIfNotEmpty(q, "key", o.Key)
setIfNotEmpty(q, "piid", o.PIID)
setIfNotEmpty(q, "uei", o.UEI)
setIfNotEmpty(q, "sin", o.SIN)
setIfNotEmpty(q, "search", o.Search)
setIfNotEmpty(q, "ordering", o.Ordering)
for k, v := range o.Extra {
q.Set(k, valueToString(v))
}
return q
}
// ListGsaElibraryContracts queries /api/gsa_elibrary_contracts/ — GSA
// eLibrary contract listings.
func (c *Client) ListGsaElibraryContracts(ctx context.Context, opts *ListGsaElibraryContractsOptions) (*PaginatedResponse[Record], error) {
q := url.Values{}
if opts != nil {
q = opts.toQuery()
}
return listGeneric[Record](ctx, c, "/api/gsa_elibrary_contracts/", q)
}
// IterateGsaElibraryContracts walks every GSA eLibrary contract matching
// opts.
func (c *Client) IterateGsaElibraryContracts(ctx context.Context, opts *ListGsaElibraryContractsOptions) *Iterator[Record] {
if opts == nil {
opts = &ListGsaElibraryContractsOptions{}
}
return &Iterator[Record]{
ctx: ctx,
fetch: func(ctx context.Context, page int, cursor string) (*PaginatedResponse[Record], error) {
next := *opts
next.Page = page
next.Cursor = cursor
return c.ListGsaElibraryContracts(ctx, &next)
},
}
}
// GetGsaElibraryContract fetches a single GSA eLibrary contract by UUID.
//
// Note: this is a Python-only method (the Node SDK has no equivalent
// single-record getter). Included here for parity with tango-python.
func (c *Client) GetGsaElibraryContract(ctx context.Context, uuid string, opts *GetEntityOptions) (Record, error) {
if uuid == "" {
return nil, &ValidationError{&APIError{Message: "GSA eLibrary contract UUID is required"}}
}
q := url.Values{}
if opts != nil {
setIfNotEmpty(q, "shape", opts.Shape)
if opts.Flat {
q.Set("flat", "true")
}
if opts.FlatLists {
q.Set("flat_lists", "true")
}
}
return getGeneric[Record](ctx, c, "/api/gsa_elibrary_contracts/"+pathEscape(uuid)+"/", q)
}