-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopportunities.go
More file actions
297 lines (272 loc) · 8.59 KB
/
Copy pathopportunities.go
File metadata and controls
297 lines (272 loc) · 8.59 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
package tango
import (
"context"
"net/url"
)
// ListOpportunitiesOptions filters /api/opportunities/.
type ListOpportunitiesOptions struct {
ListOptions
Active *bool
Agency string
FirstNoticeDateAfter string
FirstNoticeDateBefore string
LastNoticeDateAfter string
LastNoticeDateBefore string
NAICS string
NoticeType string
Ordering string
PlaceOfPerformance string
PSC string
ResponseDeadlineAfter string
ResponseDeadlineBefore string
Search string
SetAside string
SolicitationNumber string
Extra map[string]any
}
func (o *ListOpportunitiesOptions) toQuery() url.Values {
q := url.Values{}
if o == nil {
return q
}
o.ListOptions.applyTo(q)
setIfNotNilBool(q, "active", o.Active)
setIfNotEmpty(q, "agency", o.Agency)
setIfNotEmpty(q, "first_notice_date_after", o.FirstNoticeDateAfter)
setIfNotEmpty(q, "first_notice_date_before", o.FirstNoticeDateBefore)
setIfNotEmpty(q, "last_notice_date_after", o.LastNoticeDateAfter)
setIfNotEmpty(q, "last_notice_date_before", o.LastNoticeDateBefore)
setIfNotEmpty(q, "naics", o.NAICS)
setIfNotEmpty(q, "notice_type", o.NoticeType)
setIfNotEmpty(q, "ordering", o.Ordering)
setIfNotEmpty(q, "place_of_performance", o.PlaceOfPerformance)
setIfNotEmpty(q, "psc", o.PSC)
setIfNotEmpty(q, "response_deadline_after", o.ResponseDeadlineAfter)
setIfNotEmpty(q, "response_deadline_before", o.ResponseDeadlineBefore)
setIfNotEmpty(q, "search", o.Search)
setIfNotEmpty(q, "set_aside", o.SetAside)
setIfNotEmpty(q, "solicitation_number", o.SolicitationNumber)
for k, v := range o.Extra {
q.Set(k, valueToString(v))
}
return q
}
// ListOpportunities queries /api/opportunities/.
func (c *Client) ListOpportunities(ctx context.Context, opts *ListOpportunitiesOptions) (*PaginatedResponse[Record], error) {
q := url.Values{}
if opts != nil {
q = opts.toQuery()
}
return listGeneric[Record](ctx, c, "/api/opportunities/", q)
}
// IterateOpportunities walks every opportunity matching opts.
func (c *Client) IterateOpportunities(ctx context.Context, opts *ListOpportunitiesOptions) *Iterator[Record] {
if opts == nil {
opts = &ListOpportunitiesOptions{}
}
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.ListOpportunities(ctx, &next)
},
}
}
// ListNoticesOptions filters /api/notices/. The notices viewset rejects
// every ?ordering= value, so it isn't exposed here (mirrors Python/Node).
type ListNoticesOptions struct {
ListOptions
Active *bool
Agency string
NAICS string
NoticeType string
PostedDateAfter string
PostedDateBefore string
PSC string
ResponseDeadlineAfter string
ResponseDeadlineBefore string
Search string
SetAside string
SolicitationNumber string
Extra map[string]any
}
func (o *ListNoticesOptions) toQuery() url.Values {
q := url.Values{}
if o == nil {
return q
}
o.ListOptions.applyTo(q)
setIfNotNilBool(q, "active", o.Active)
setIfNotEmpty(q, "agency", o.Agency)
setIfNotEmpty(q, "naics", o.NAICS)
setIfNotEmpty(q, "notice_type", o.NoticeType)
setIfNotEmpty(q, "posted_date_after", o.PostedDateAfter)
setIfNotEmpty(q, "posted_date_before", o.PostedDateBefore)
setIfNotEmpty(q, "psc", o.PSC)
setIfNotEmpty(q, "response_deadline_after", o.ResponseDeadlineAfter)
setIfNotEmpty(q, "response_deadline_before", o.ResponseDeadlineBefore)
setIfNotEmpty(q, "search", o.Search)
setIfNotEmpty(q, "set_aside", o.SetAside)
setIfNotEmpty(q, "solicitation_number", o.SolicitationNumber)
for k, v := range o.Extra {
q.Set(k, valueToString(v))
}
return q
}
// ListNotices queries /api/notices/.
func (c *Client) ListNotices(ctx context.Context, opts *ListNoticesOptions) (*PaginatedResponse[Record], error) {
q := url.Values{}
if opts != nil {
q = opts.toQuery()
}
return listGeneric[Record](ctx, c, "/api/notices/", q)
}
// ListForecastsOptions filters /api/forecasts/.
type ListForecastsOptions struct {
ListOptions
Agency string
AwardDateAfter string
AwardDateBefore string
FiscalYear string
FiscalYearGte string
FiscalYearLte string
ModifiedAfter string
ModifiedBefore string
NAICSCode string
NAICSStartsWith string
Ordering string
Search string
SourceSystem string
Status string
Extra map[string]any
}
func (o *ListForecastsOptions) toQuery() url.Values {
q := url.Values{}
if o == nil {
return q
}
o.ListOptions.applyTo(q)
setIfNotEmpty(q, "agency", o.Agency)
setIfNotEmpty(q, "award_date_after", o.AwardDateAfter)
setIfNotEmpty(q, "award_date_before", o.AwardDateBefore)
setIfNotEmpty(q, "fiscal_year", o.FiscalYear)
setIfNotEmpty(q, "fiscal_year_gte", o.FiscalYearGte)
setIfNotEmpty(q, "fiscal_year_lte", o.FiscalYearLte)
setIfNotEmpty(q, "modified_after", o.ModifiedAfter)
setIfNotEmpty(q, "modified_before", o.ModifiedBefore)
setIfNotEmpty(q, "naics_code", o.NAICSCode)
setIfNotEmpty(q, "naics_starts_with", o.NAICSStartsWith)
setIfNotEmpty(q, "ordering", o.Ordering)
setIfNotEmpty(q, "search", o.Search)
setIfNotEmpty(q, "source_system", o.SourceSystem)
setIfNotEmpty(q, "status", o.Status)
for k, v := range o.Extra {
q.Set(k, valueToString(v))
}
return q
}
// ListForecasts queries /api/forecasts/.
func (c *Client) ListForecasts(ctx context.Context, opts *ListForecastsOptions) (*PaginatedResponse[Record], error) {
q := url.Values{}
if opts != nil {
q = opts.toQuery()
}
return listGeneric[Record](ctx, c, "/api/forecasts/", q)
}
// ListGrantsOptions filters /api/grants/.
type ListGrantsOptions struct {
ListOptions
Agency string
ApplicantTypes string
CFDANumber string
FundingCategories string
FundingInstruments string
OpportunityNumber string
Ordering string
PostedDateAfter string
PostedDateBefore string
ResponseDateAfter string
ResponseDateBefore string
Search string
Status string
Extra map[string]any
}
func (o *ListGrantsOptions) toQuery() url.Values {
q := url.Values{}
if o == nil {
return q
}
o.ListOptions.applyTo(q)
setIfNotEmpty(q, "agency", o.Agency)
setIfNotEmpty(q, "applicant_types", o.ApplicantTypes)
setIfNotEmpty(q, "cfda_number", o.CFDANumber)
setIfNotEmpty(q, "funding_categories", o.FundingCategories)
setIfNotEmpty(q, "funding_instruments", o.FundingInstruments)
setIfNotEmpty(q, "opportunity_number", o.OpportunityNumber)
setIfNotEmpty(q, "ordering", o.Ordering)
setIfNotEmpty(q, "posted_date_after", o.PostedDateAfter)
setIfNotEmpty(q, "posted_date_before", o.PostedDateBefore)
setIfNotEmpty(q, "response_date_after", o.ResponseDateAfter)
setIfNotEmpty(q, "response_date_before", o.ResponseDateBefore)
setIfNotEmpty(q, "search", o.Search)
setIfNotEmpty(q, "status", o.Status)
for k, v := range o.Extra {
q.Set(k, valueToString(v))
}
return q
}
// ListGrants queries /api/grants/.
func (c *Client) ListGrants(ctx context.Context, opts *ListGrantsOptions) (*PaginatedResponse[Record], error) {
q := url.Values{}
if opts != nil {
q = opts.toQuery()
}
return listGeneric[Record](ctx, c, "/api/grants/", q)
}
// IterateNotices walks every notice matching opts.
func (c *Client) IterateNotices(ctx context.Context, opts *ListNoticesOptions) *Iterator[Record] {
if opts == nil {
opts = &ListNoticesOptions{}
}
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.ListNotices(ctx, &next)
},
}
}
// IterateForecasts walks every forecast matching opts.
func (c *Client) IterateForecasts(ctx context.Context, opts *ListForecastsOptions) *Iterator[Record] {
if opts == nil {
opts = &ListForecastsOptions{}
}
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.ListForecasts(ctx, &next)
},
}
}
// IterateGrants walks every grant matching opts.
func (c *Client) IterateGrants(ctx context.Context, opts *ListGrantsOptions) *Iterator[Record] {
if opts == nil {
opts = &ListGrantsOptions{}
}
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.ListGrants(ctx, &next)
},
}
}