usaspending-rb 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +49 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +354 -0
  5. data/lib/usaspending/client.rb +153 -0
  6. data/lib/usaspending/configuration.rb +58 -0
  7. data/lib/usaspending/error.rb +66 -0
  8. data/lib/usaspending/resources/agency.rb +274 -0
  9. data/lib/usaspending/resources/autocomplete.rb +302 -0
  10. data/lib/usaspending/resources/award_spending.rb +24 -0
  11. data/lib/usaspending/resources/awards.rb +240 -0
  12. data/lib/usaspending/resources/base.rb +31 -0
  13. data/lib/usaspending/resources/budget_functions.rb +28 -0
  14. data/lib/usaspending/resources/bulk_download.rb +79 -0
  15. data/lib/usaspending/resources/disaster.rb +294 -0
  16. data/lib/usaspending/resources/download.rb +129 -0
  17. data/lib/usaspending/resources/federal_accounts.rb +111 -0
  18. data/lib/usaspending/resources/federal_obligations.rb +24 -0
  19. data/lib/usaspending/resources/financial_balances.rb +22 -0
  20. data/lib/usaspending/resources/financial_spending.rb +44 -0
  21. data/lib/usaspending/resources/idv.rb +93 -0
  22. data/lib/usaspending/resources/recipient.rb +130 -0
  23. data/lib/usaspending/resources/references.rb +236 -0
  24. data/lib/usaspending/resources/reporting.rb +117 -0
  25. data/lib/usaspending/resources/search.rb +228 -0
  26. data/lib/usaspending/resources/spending.rb +111 -0
  27. data/lib/usaspending/resources/spending_explorer.rb +31 -0
  28. data/lib/usaspending/resources/subawards.rb +24 -0
  29. data/lib/usaspending/resources/transactions.rb +24 -0
  30. data/lib/usaspending/response.rb +164 -0
  31. data/lib/usaspending/version.rb +5 -0
  32. data/lib/usaspending.rb +212 -0
  33. metadata +209 -0
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module USAspending
4
+ # Base error class. All gem errors inherit from this.
5
+ class Error < StandardError; end
6
+
7
+ # Base class for all HTTP errors (4xx and 5xx).
8
+ # Carries the status code and response body for programmatic handling.
9
+ #
10
+ # @example
11
+ # begin
12
+ # USAspending.awards.find("INVALID")
13
+ # rescue USAspending::HttpError => e
14
+ # puts e.status # => 404
15
+ # puts e.body # => { "detail" => "..." }
16
+ # end
17
+ class HttpError < Error
18
+ # @return [Integer, nil] the HTTP status code
19
+ attr_reader :status
20
+
21
+ # @return [Hash, String, nil] the response body
22
+ attr_reader :body
23
+
24
+ # @param message [String, nil] error message
25
+ # @param status [Integer, nil] HTTP status code
26
+ # @param body [Hash, String, nil] response body
27
+ def initialize(message = nil, status: nil, body: nil)
28
+ @status = status
29
+ @body = body
30
+ super(message || default_message)
31
+ end
32
+
33
+ private
34
+
35
+ def default_message
36
+ "HTTP #{status}: #{body}"
37
+ end
38
+ end
39
+
40
+ # Raised when the API returns a 4xx response.
41
+ class ClientError < HttpError; end
42
+
43
+ # Raised when the API returns a 400 (bad request / malformed params).
44
+ class BadRequestError < ClientError; end
45
+
46
+ # Raised when the API returns a 404.
47
+ class NotFoundError < ClientError; end
48
+
49
+ # Raised when the API returns a 422 (invalid filter params).
50
+ class UnprocessableEntityError < ClientError; end
51
+
52
+ # Raised when the API returns a 429 and retries are exhausted.
53
+ class RateLimitError < ClientError; end
54
+
55
+ # Raised when the API returns a 5xx response after retries are exhausted.
56
+ class ServerError < HttpError
57
+ private
58
+
59
+ def default_message
60
+ "Server error HTTP #{status}"
61
+ end
62
+ end
63
+
64
+ # Raised on network-level failures (timeout, connection refused, DNS, etc.).
65
+ class ConnectionError < Error; end
66
+ end
@@ -0,0 +1,274 @@
1
+ # frozen_string_literal: true
2
+
3
+ module USAspending
4
+ module Resources
5
+ class Agency < Base
6
+ # ------------------------------------------------------------------
7
+ # 1. Agency overview including budget, obligations, outlay totals.
8
+ # `GET /api/v2/agency/{toptier_code}/`
9
+ #
10
+ # @param toptier_code [String] e.g. "020" for Treasury, "097" for DoD
11
+ # @param fiscal_year [Integer] defaults to most recent available
12
+ # @return [USAspending::Response]
13
+ # @raise [USAspending::ClientError] on 4xx responses
14
+ # @raise [USAspending::ServerError] on 5xx responses
15
+ # @raise [USAspending::ConnectionError] on network failures
16
+ #
17
+ # @example Fetch Treasury Department overview
18
+ # client = USAspending::Client.new
19
+ # response = client.agency.overview("020", fiscal_year: 2024)
20
+ # response.data["agency_name"] #=> "Department of the Treasury"
21
+ def overview(toptier_code, fiscal_year: nil)
22
+ get("agency/#{toptier_code}/", fy_params(fiscal_year))
23
+ end
24
+
25
+ # ------------------------------------------------------------------
26
+ # 2. Awards summary for an agency.
27
+ # `GET /api/v2/agency/{toptier_code}/awards/`
28
+ #
29
+ # @param toptier_code [String]
30
+ # @param fiscal_year [Integer]
31
+ # @return [USAspending::Response]
32
+ def awards(toptier_code, fiscal_year: nil)
33
+ get("agency/#{toptier_code}/awards/", fy_params(fiscal_year))
34
+ end
35
+
36
+ # ------------------------------------------------------------------
37
+ # 3. Count of new awards for an agency.
38
+ # `GET /api/v2/agency/{toptier_code}/awards/new/count/`
39
+ #
40
+ # @param toptier_code [String]
41
+ # @param fiscal_year [Integer]
42
+ # @return [USAspending::Response]
43
+ def new_awards_count(toptier_code, fiscal_year: nil)
44
+ get("agency/#{toptier_code}/awards/new/count/", fy_params(fiscal_year))
45
+ end
46
+
47
+ # ------------------------------------------------------------------
48
+ # 4. Award type counts (not scoped to a single agency).
49
+ # GET /api/v2/agency/awards/count/
50
+ #
51
+ # @param fiscal_year [Integer]
52
+ # @return [USAspending::Response]
53
+ def awards_count(fiscal_year: nil)
54
+ get('agency/awards/count/', fy_params(fiscal_year))
55
+ end
56
+
57
+ # ------------------------------------------------------------------
58
+ # 5. Budget functions list for an agency.
59
+ # `GET /api/v2/agency/{toptier_code}/budget_function/`
60
+ #
61
+ # @param toptier_code [String]
62
+ # @param fiscal_year [Integer]
63
+ # @param limit [Integer]
64
+ # @param page [Integer]
65
+ # @return [USAspending::Response]
66
+ def budget_function(toptier_code, fiscal_year: nil, limit: 10, page: 1)
67
+ get("agency/#{toptier_code}/budget_function/", fy_params(fiscal_year, limit: limit, page: page))
68
+ end
69
+
70
+ # ------------------------------------------------------------------
71
+ # 6. Count of budget functions for an agency.
72
+ # `GET /api/v2/agency/{toptier_code}/budget_function/count/`
73
+ #
74
+ # @param toptier_code [String]
75
+ # @param fiscal_year [Integer]
76
+ # @return [USAspending::Response]
77
+ def budget_function_count(toptier_code, fiscal_year: nil)
78
+ get("agency/#{toptier_code}/budget_function/count/", fy_params(fiscal_year))
79
+ end
80
+
81
+ # ------------------------------------------------------------------
82
+ # 7. Budgetary resources for an agency across fiscal years.
83
+ # `GET /api/v2/agency/{toptier_code}/budgetary_resources/`
84
+ #
85
+ # @param toptier_code [String]
86
+ # @param fiscal_year [Integer]
87
+ # @return [USAspending::Response]
88
+ def budgetary_resources(toptier_code, fiscal_year: nil)
89
+ get("agency/#{toptier_code}/budgetary_resources/", fy_params(fiscal_year))
90
+ end
91
+
92
+ # ------------------------------------------------------------------
93
+ # 8. Federal account breakdown for an agency.
94
+ # `GET /api/v2/agency/{toptier_code}/federal_account/`
95
+ #
96
+ # @param toptier_code [String]
97
+ # @param fiscal_year [Integer]
98
+ # @param limit [Integer]
99
+ # @param page [Integer]
100
+ # @return [USAspending::Response]
101
+ def federal_accounts(toptier_code, fiscal_year: nil, limit: 10, page: 1)
102
+ get("agency/#{toptier_code}/federal_account/", fy_params(fiscal_year, limit: limit, page: page))
103
+ end
104
+
105
+ # ------------------------------------------------------------------
106
+ # 9. Count of federal accounts for an agency.
107
+ # `GET /api/v2/agency/{toptier_code}/federal_account/count/`
108
+ #
109
+ # @param toptier_code [String]
110
+ # @param fiscal_year [Integer]
111
+ # @return [USAspending::Response]
112
+ def federal_account_count(toptier_code, fiscal_year: nil)
113
+ get("agency/#{toptier_code}/federal_account/count/", fy_params(fiscal_year))
114
+ end
115
+
116
+ # ------------------------------------------------------------------
117
+ # 10. Object classes for an agency.
118
+ # `GET /api/v2/agency/{toptier_code}/object_class/`
119
+ #
120
+ # @param toptier_code [String]
121
+ # @param fiscal_year [Integer]
122
+ # @param limit [Integer]
123
+ # @param page [Integer]
124
+ # @return [USAspending::Response]
125
+ def object_class(toptier_code, fiscal_year: nil, limit: 10, page: 1)
126
+ get("agency/#{toptier_code}/object_class/", fy_params(fiscal_year, limit: limit, page: page))
127
+ end
128
+
129
+ # ------------------------------------------------------------------
130
+ # 11. Count of object classes for an agency.
131
+ # `GET /api/v2/agency/{toptier_code}/object_class/count/`
132
+ #
133
+ # @param toptier_code [String]
134
+ # @param fiscal_year [Integer]
135
+ # @return [USAspending::Response]
136
+ def object_class_count(toptier_code, fiscal_year: nil)
137
+ get("agency/#{toptier_code}/object_class/count/", fy_params(fiscal_year))
138
+ end
139
+
140
+ # ------------------------------------------------------------------
141
+ # 12. Obligations breakdown by award category.
142
+ # `GET /api/v2/agency/{toptier_code}/obligations_by_award_category/`
143
+ #
144
+ # @param toptier_code [String]
145
+ # @param fiscal_year [Integer]
146
+ # @return [USAspending::Response]
147
+ def obligations_by_award_category(toptier_code, fiscal_year: nil)
148
+ get("agency/#{toptier_code}/obligations_by_award_category/", fy_params(fiscal_year))
149
+ end
150
+
151
+ # ------------------------------------------------------------------
152
+ # 13. Program activities for an agency.
153
+ # `GET /api/v2/agency/{toptier_code}/program_activity/`
154
+ #
155
+ # @param toptier_code [String]
156
+ # @param fiscal_year [Integer]
157
+ # @param limit [Integer]
158
+ # @param page [Integer]
159
+ # @return [USAspending::Response]
160
+ def program_activity(toptier_code, fiscal_year: nil, limit: 10, page: 1)
161
+ get("agency/#{toptier_code}/program_activity/", fy_params(fiscal_year, limit: limit, page: page))
162
+ end
163
+
164
+ # ------------------------------------------------------------------
165
+ # 14. Count of program activities for an agency.
166
+ # `GET /api/v2/agency/{toptier_code}/program_activity/count/`
167
+ #
168
+ # @param toptier_code [String]
169
+ # @param fiscal_year [Integer]
170
+ # @return [USAspending::Response]
171
+ def program_activity_count(toptier_code, fiscal_year: nil)
172
+ get("agency/#{toptier_code}/program_activity/count/", fy_params(fiscal_year))
173
+ end
174
+
175
+ # ------------------------------------------------------------------
176
+ # 15. Sub-agencies for a given top-tier agency.
177
+ # `GET /api/v2/agency/{toptier_code}/sub_agency/`
178
+ #
179
+ # @param toptier_code [String]
180
+ # @param fiscal_year [Integer]
181
+ # @param limit [Integer]
182
+ # @param page [Integer]
183
+ # @return [USAspending::Response]
184
+ def sub_agencies(toptier_code, fiscal_year: nil, limit: 10, page: 1)
185
+ get("agency/#{toptier_code}/sub_agency/", fy_params(fiscal_year, limit: limit, page: page))
186
+ end
187
+
188
+ # ------------------------------------------------------------------
189
+ # 16. Count of sub-agencies for an agency.
190
+ # `GET /api/v2/agency/{toptier_code}/sub_agency/count/`
191
+ #
192
+ # @param toptier_code [String]
193
+ # @param fiscal_year [Integer]
194
+ # @return [USAspending::Response]
195
+ def sub_agency_count(toptier_code, fiscal_year: nil)
196
+ get("agency/#{toptier_code}/sub_agency/count/", fy_params(fiscal_year))
197
+ end
198
+
199
+ # ------------------------------------------------------------------
200
+ # 17. Bureaus (sub-components) for an agency.
201
+ # `GET /api/v2/agency/{toptier_code}/sub_components/`
202
+ #
203
+ # @param toptier_code [String]
204
+ # @param fiscal_year [Integer]
205
+ # @param limit [Integer]
206
+ # @param page [Integer]
207
+ # @return [USAspending::Response]
208
+ def sub_components(toptier_code, fiscal_year: nil, limit: 10, page: 1)
209
+ get("agency/#{toptier_code}/sub_components/", fy_params(fiscal_year, limit: limit, page: page))
210
+ end
211
+
212
+ # ------------------------------------------------------------------
213
+ # 18. Federal accounts for a specific bureau within an agency.
214
+ # `GET /api/v2/agency/{toptier_code}/sub_components/{bureau_slug}/`
215
+ #
216
+ # @param toptier_code [String]
217
+ # @param bureau_slug [String]
218
+ # @param fiscal_year [Integer]
219
+ # @param limit [Integer]
220
+ # @param page [Integer]
221
+ # @return [USAspending::Response]
222
+ def sub_component_federal_accounts(toptier_code, bureau_slug, fiscal_year: nil, limit: 10, page: 1)
223
+ get("agency/#{toptier_code}/sub_components/#{bureau_slug}/", fy_params(fiscal_year, limit: limit, page: page))
224
+ end
225
+
226
+ # ------------------------------------------------------------------
227
+ # 19. Object classes for a Treasury Account Symbol (TAS).
228
+ # `GET /api/v2/agency/treasury_account/{tas}/object_class/`
229
+ #
230
+ # @param tas [String] Treasury Account Symbol
231
+ # @param fiscal_year [Integer]
232
+ # @param limit [Integer]
233
+ # @param page [Integer]
234
+ # @return [USAspending::Response]
235
+ def treasury_account_object_class(tas, fiscal_year: nil, limit: 10, page: 1)
236
+ get("agency/treasury_account/#{tas}/object_class/", fy_params(fiscal_year, limit: limit, page: page))
237
+ end
238
+
239
+ # ------------------------------------------------------------------
240
+ # 20. Program activities for a Treasury Account Symbol (TAS).
241
+ # `GET /api/v2/agency/treasury_account/{tas}/program_activity/`
242
+ #
243
+ # @param tas [String] Treasury Account Symbol
244
+ # @param fiscal_year [Integer]
245
+ # @param limit [Integer]
246
+ # @param page [Integer]
247
+ # @return [USAspending::Response]
248
+ def treasury_account_program_activity(tas, fiscal_year: nil, limit: 10, page: 1)
249
+ get("agency/treasury_account/#{tas}/program_activity/", fy_params(fiscal_year, limit: limit, page: page))
250
+ end
251
+
252
+ # ------------------------------------------------------------------
253
+ # List all top-tier agencies with their toptier_codes.
254
+ # GET /api/v2/references/toptier_agencies/
255
+ #
256
+ # @return [USAspending::Response]
257
+ def list
258
+ get('references/toptier_agencies/')
259
+ end
260
+
261
+ private
262
+
263
+ # Builds query params hash with optional fiscal_year and any extras.
264
+ # @param fiscal_year [Integer, nil]
265
+ # @param extras [Hash] additional params (limit, page, etc.)
266
+ # @return [Hash]
267
+ def fy_params(fiscal_year, **extras)
268
+ params = extras.dup
269
+ params[:fiscal_year] = fiscal_year if fiscal_year
270
+ params
271
+ end
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,302 @@
1
+ # frozen_string_literal: true
2
+
3
+ module USAspending
4
+ module Resources
5
+ class Autocomplete < Base
6
+ # Awarding agency autocomplete.
7
+ #
8
+ # @param search_text [String]
9
+ # @param limit [Integer]
10
+ # @return [USAspending::Response]
11
+ # @raise [USAspending::ClientError] on 4xx responses
12
+ # @raise [USAspending::ServerError] on 5xx responses
13
+ # @raise [USAspending::ConnectionError] on network failures
14
+ def awarding_agency(search_text, limit: 10)
15
+ post('autocomplete/awarding_agency/', {
16
+ search_text: search_text,
17
+ limit: limit
18
+ })
19
+ end
20
+
21
+ # Funding agency autocomplete.
22
+ #
23
+ # @param search_text [String]
24
+ # @param limit [Integer]
25
+ # @return [USAspending::Response]
26
+ # @raise [USAspending::ClientError] on 4xx responses
27
+ # @raise [USAspending::ServerError] on 5xx responses
28
+ # @raise [USAspending::ConnectionError] on network failures
29
+ def funding_agency(search_text, limit: 10)
30
+ post('autocomplete/funding_agency/', {
31
+ search_text: search_text,
32
+ limit: limit
33
+ })
34
+ end
35
+
36
+ # Awarding agency + office autocomplete.
37
+ #
38
+ # @param search_text [String]
39
+ # @param limit [Integer]
40
+ # @return [USAspending::Response]
41
+ # @raise [USAspending::ClientError] on 4xx responses
42
+ # @raise [USAspending::ServerError] on 5xx responses
43
+ # @raise [USAspending::ConnectionError] on network failures
44
+ def awarding_agency_office(search_text, limit: 10)
45
+ post('autocomplete/awarding_agency_office/', {
46
+ search_text: search_text,
47
+ limit: limit
48
+ })
49
+ end
50
+
51
+ # Funding agency + office autocomplete.
52
+ #
53
+ # @param search_text [String]
54
+ # @param limit [Integer]
55
+ # @return [USAspending::Response]
56
+ # @raise [USAspending::ClientError] on 4xx responses
57
+ # @raise [USAspending::ServerError] on 5xx responses
58
+ # @raise [USAspending::ConnectionError] on network failures
59
+ def funding_agency_office(search_text, limit: 10)
60
+ post('autocomplete/funding_agency_office/', {
61
+ search_text: search_text,
62
+ limit: limit
63
+ })
64
+ end
65
+
66
+ # CFDA program autocomplete.
67
+ #
68
+ # @param search_text [String]
69
+ # @param limit [Integer]
70
+ # @return [USAspending::Response]
71
+ # @raise [USAspending::ClientError] on 4xx responses
72
+ # @raise [USAspending::ServerError] on 5xx responses
73
+ # @raise [USAspending::ConnectionError] on network failures
74
+ def cfda(search_text, limit: 10)
75
+ post('autocomplete/cfda/', {
76
+ search_text: search_text,
77
+ limit: limit
78
+ })
79
+ end
80
+
81
+ # NAICS code and title autocomplete.
82
+ #
83
+ # @param search_text [String] code fragment or industry description
84
+ # @param limit [Integer]
85
+ # @return [USAspending::Response]
86
+ # @raise [USAspending::ClientError] on 4xx responses
87
+ # @raise [USAspending::ServerError] on 5xx responses
88
+ # @raise [USAspending::ConnectionError] on network failures
89
+ def naics(search_text, limit: 10)
90
+ post('autocomplete/naics/', {
91
+ search_text: search_text,
92
+ limit: limit
93
+ })
94
+ end
95
+
96
+ # PSC (Product Service Code) autocomplete.
97
+ #
98
+ # @param search_text [String]
99
+ # @param limit [Integer]
100
+ # @return [USAspending::Response]
101
+ # @raise [USAspending::ClientError] on 4xx responses
102
+ # @raise [USAspending::ServerError] on 5xx responses
103
+ # @raise [USAspending::ConnectionError] on network failures
104
+ def psc(search_text, limit: 10)
105
+ post('autocomplete/psc/', {
106
+ search_text: search_text,
107
+ limit: limit
108
+ })
109
+ end
110
+
111
+ # Program activity autocomplete.
112
+ #
113
+ # @param search_text [String]
114
+ # @param limit [Integer]
115
+ # @return [USAspending::Response]
116
+ # @raise [USAspending::ClientError] on 4xx responses
117
+ # @raise [USAspending::ServerError] on 5xx responses
118
+ # @raise [USAspending::ConnectionError] on network failures
119
+ def program_activity(search_text, limit: 10)
120
+ post('autocomplete/program_activity/', {
121
+ search_text: search_text,
122
+ limit: limit
123
+ })
124
+ end
125
+
126
+ # Recipient name/UEI autocomplete.
127
+ #
128
+ # @param search_text [String]
129
+ # @param limit [Integer]
130
+ # @return [USAspending::Response]
131
+ # @raise [USAspending::ClientError] on 4xx responses
132
+ # @raise [USAspending::ServerError] on 5xx responses
133
+ # @raise [USAspending::ConnectionError] on network failures
134
+ def recipient(search_text, limit: 10)
135
+ post('autocomplete/recipient/', {
136
+ search_text: search_text,
137
+ limit: limit
138
+ })
139
+ end
140
+
141
+ # Glossary term autocomplete.
142
+ #
143
+ # @param search_text [String]
144
+ # @param limit [Integer]
145
+ # @return [USAspending::Response]
146
+ # @raise [USAspending::ClientError] on 4xx responses
147
+ # @raise [USAspending::ServerError] on 5xx responses
148
+ # @raise [USAspending::ConnectionError] on network failures
149
+ def glossary(search_text, limit: 10)
150
+ post('autocomplete/glossary/', {
151
+ search_text: search_text,
152
+ limit: limit
153
+ })
154
+ end
155
+
156
+ # City name autocomplete.
157
+ #
158
+ # @param search_text [String]
159
+ # @param scope [String] "recipient_location" or "primary_place_of_performance"
160
+ # (default: "recipient_location")
161
+ # @param country_code [String] ISO 3166-1 alpha-3 country code (default: "USA")
162
+ # @param state_code [String, nil] optional two-letter state abbreviation
163
+ # @param limit [Integer]
164
+ # @return [USAspending::Response]
165
+ # @raise [USAspending::ClientError] on 4xx responses
166
+ # @raise [USAspending::ServerError] on 5xx responses
167
+ # @raise [USAspending::ConnectionError] on network failures
168
+ def city(search_text, scope: 'recipient_location', country_code: 'USA', state_code: nil, limit: 10)
169
+ filter = { country_code: country_code, scope: scope }
170
+ filter[:state_code] = state_code if state_code
171
+ post('autocomplete/city/', {
172
+ search_text: search_text,
173
+ limit: limit,
174
+ filter: filter
175
+ })
176
+ end
177
+
178
+ # Location autocomplete. Used to resolve zip codes to districts.
179
+ #
180
+ # @param search_text [String] zip code, city name, state, etc.
181
+ # @param geo_layer [String] "state", "county", "city",
182
+ # "congressional_district", "zip_code", "country"
183
+ # @param limit [Integer]
184
+ # @return [USAspending::Response]
185
+ # @raise [USAspending::ClientError] on 4xx responses
186
+ # @raise [USAspending::ServerError] on 5xx responses
187
+ # @raise [USAspending::ConnectionError] on network failures
188
+ def location(search_text, geo_layer: nil, limit: 10)
189
+ body = { search_text: search_text, limit: limit }
190
+ body[:geo_layer] = geo_layer if geo_layer
191
+ post('autocomplete/location/', body)
192
+ end
193
+
194
+ # ------------------------------------------------------------------
195
+ # TAS (Treasury Account Symbol) component autocomplete endpoints
196
+ #
197
+ # Each accounts/* endpoint accepts search_text, limit, and an
198
+ # optional filters hash whose keys are other TAS component values
199
+ # (e.g. ata, aid, bpoa, epoa, a, main, sub).
200
+ # ------------------------------------------------------------------
201
+
202
+ # TAS ATA (Allocation Transfer Agency) autocomplete.
203
+ #
204
+ # @param search_text [String]
205
+ # @param filters [Hash] TAS component filters
206
+ # @param limit [Integer]
207
+ # @return [USAspending::Response]
208
+ # @raise [USAspending::ClientError] on 4xx responses
209
+ # @raise [USAspending::ServerError] on 5xx responses
210
+ # @raise [USAspending::ConnectionError] on network failures
211
+ def accounts_ata(search_text, filters: {}, limit: 10)
212
+ accounts_autocomplete('ata', search_text, filters, limit)
213
+ end
214
+
215
+ # TAS AID (Agency Identifier) autocomplete.
216
+ #
217
+ # @param search_text [String]
218
+ # @param filters [Hash] TAS component filters
219
+ # @param limit [Integer]
220
+ # @return [USAspending::Response]
221
+ # @raise [USAspending::ClientError] on 4xx responses
222
+ # @raise [USAspending::ServerError] on 5xx responses
223
+ # @raise [USAspending::ConnectionError] on network failures
224
+ def accounts_aid(search_text, filters: {}, limit: 10)
225
+ accounts_autocomplete('aid', search_text, filters, limit)
226
+ end
227
+
228
+ # TAS BPOA (Beginning Period of Availability) autocomplete.
229
+ #
230
+ # @param search_text [String]
231
+ # @param filters [Hash] TAS component filters
232
+ # @param limit [Integer]
233
+ # @return [USAspending::Response]
234
+ # @raise [USAspending::ClientError] on 4xx responses
235
+ # @raise [USAspending::ServerError] on 5xx responses
236
+ # @raise [USAspending::ConnectionError] on network failures
237
+ def accounts_bpoa(search_text, filters: {}, limit: 10)
238
+ accounts_autocomplete('bpoa', search_text, filters, limit)
239
+ end
240
+
241
+ # TAS EPOA (Ending Period of Availability) autocomplete.
242
+ #
243
+ # @param search_text [String]
244
+ # @param filters [Hash] TAS component filters
245
+ # @param limit [Integer]
246
+ # @return [USAspending::Response]
247
+ # @raise [USAspending::ClientError] on 4xx responses
248
+ # @raise [USAspending::ServerError] on 5xx responses
249
+ # @raise [USAspending::ConnectionError] on network failures
250
+ def accounts_epoa(search_text, filters: {}, limit: 10)
251
+ accounts_autocomplete('epoa', search_text, filters, limit)
252
+ end
253
+
254
+ # TAS Availability Type Code autocomplete.
255
+ #
256
+ # @param search_text [String]
257
+ # @param filters [Hash] TAS component filters
258
+ # @param limit [Integer]
259
+ # @return [USAspending::Response]
260
+ # @raise [USAspending::ClientError] on 4xx responses
261
+ # @raise [USAspending::ServerError] on 5xx responses
262
+ # @raise [USAspending::ConnectionError] on network failures
263
+ def accounts_a(search_text, filters: {}, limit: 10)
264
+ accounts_autocomplete('a', search_text, filters, limit)
265
+ end
266
+
267
+ # TAS Main Account Code autocomplete.
268
+ #
269
+ # @param search_text [String]
270
+ # @param filters [Hash] TAS component filters
271
+ # @param limit [Integer]
272
+ # @return [USAspending::Response]
273
+ # @raise [USAspending::ClientError] on 4xx responses
274
+ # @raise [USAspending::ServerError] on 5xx responses
275
+ # @raise [USAspending::ConnectionError] on network failures
276
+ def accounts_main(search_text, filters: {}, limit: 10)
277
+ accounts_autocomplete('main', search_text, filters, limit)
278
+ end
279
+
280
+ # TAS Sub-Account Code autocomplete.
281
+ #
282
+ # @param search_text [String]
283
+ # @param filters [Hash] TAS component filters
284
+ # @param limit [Integer]
285
+ # @return [USAspending::Response]
286
+ # @raise [USAspending::ClientError] on 4xx responses
287
+ # @raise [USAspending::ServerError] on 5xx responses
288
+ # @raise [USAspending::ConnectionError] on network failures
289
+ def accounts_sub(search_text, filters: {}, limit: 10)
290
+ accounts_autocomplete('sub', search_text, filters, limit)
291
+ end
292
+
293
+ private
294
+
295
+ def accounts_autocomplete(component, search_text, filters, limit)
296
+ body = { search_text: search_text, limit: limit }
297
+ body[:filters] = filters unless filters.nil? || filters.empty?
298
+ post("autocomplete/accounts/#{component}/", body)
299
+ end
300
+ end
301
+ end
302
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module USAspending
4
+ module Resources
5
+ class AwardSpending < Base
6
+ # Returns all award spending by recipient for a given fiscal year and agency.
7
+ #
8
+ # @param fiscal_year [Integer]
9
+ # @param awarding_agency_id [Integer]
10
+ # @param limit [Integer]
11
+ # @param page [Integer]
12
+ # @return [USAspending::Response]
13
+ # @raise [USAspending::ClientError] on 4xx responses
14
+ # @raise [USAspending::ServerError] on 5xx responses
15
+ # @raise [USAspending::ConnectionError] on network failures
16
+ def by_recipient(fiscal_year:, awarding_agency_id:, limit: 10, page: 1)
17
+ get('award_spending/recipient/', {
18
+ fiscal_year: fiscal_year, awarding_agency_id: awarding_agency_id,
19
+ limit: limit, page: page
20
+ })
21
+ end
22
+ end
23
+ end
24
+ end