census_api 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -0
- data/README.md +64 -61
- data/Rakefile +9 -1
- data/census_api.gemspec +5 -2
- data/lib/census_api/client.rb +1 -1
- data/lib/census_api/request.rb +24 -14
- data/lib/census_api/version.rb +1 -1
- data/lib/{yml → data}/census_shapes.yml +95 -4
- data/lib/data/geography.json +1569 -0
- data/spec/census_api/client_spec.rb +2 -0
- data/spec/census_api/examples_spec.rb +26 -0
- data/spec/census_api/request_spec.rb +7 -17
- data/spec/spec_helper.rb +33 -4
- data/spec/support/data/census_2010_dec_sf1.rb +351 -0
- data/spec/support/data/census_2012_acs_acs1.rb +61 -0
- data/spec/support/data/census_2015_acs_acs5.rb +191 -0
- data/spec/support/examples.rb +65 -0
- data/spec/vcr_setup.rb +1 -0
- metadata +63 -15
- data/spec/api_key.sample.rb +0 -1
- data/spec/census_api/example_spec.rb +0 -37
- data/spec/support/census_examples.rb +0 -84
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d339bee3037ab0d8bb8392064a3cc83ab41aa4ae
|
4
|
+
data.tar.gz: bc7c082251040e2010950612a3b4c7406d59876f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e963d9624c8ba6b03023736dcbfbc53902f782a8f6cc347f55fa0e959a025c7c1671a1f5f04f4e48df54f294e5ceadbfc766fc3caf5efc0e61c4b2fd9851688
|
7
|
+
data.tar.gz: 9e02121dbae295a01b861741ccdddefdeb8f26e113f47e13fc1d8756fcc15434ce71e52d9e667966f44dc01e0ca4cb0fe2262cfd3494c1c17dbaedf7d838d79c
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -5,11 +5,8 @@ This gem provides a Ruby wrapper around the Census Bureau API.
|
|
5
5
|
|
6
6
|
## Obtaining an API key
|
7
7
|
|
8
|
-
To be able to use this gem, you'll need a Census Bureau API key. To request an API key,
|
9
|
-
[http://www.census.gov/developers/tos/key_request.html]
|
10
|
-
|
11
|
-
[key]: (http://www.census.gov/developers/tos/key_request.html)
|
12
|
-
|
8
|
+
To be able to use this gem, you'll need a Census Bureau API key. To request an API key,
|
9
|
+
[visit http://www.census.gov/developers/tos/key_request.html](http://www.census.gov/developers/tos/key_request.html) and follow the instructions.
|
13
10
|
|
14
11
|
## Installing the gem
|
15
12
|
|
@@ -19,6 +16,12 @@ To use this gem, install it with <tt>gem install census_api</tt> or add it to yo
|
|
19
16
|
|
20
17
|
And install it with <tt>bundle install</tt>
|
21
18
|
|
19
|
+
## Notice: Breaking API Changes
|
20
|
+
|
21
|
+
The US Census Bureau is currently centralizing ["all data in the Census API into a uniform and consistent format across all datasets and surveys"](https://www.census.gov/data/developers/updates/api-format-changes--sf1-2010.html) which will result in breaking changes. Some variable names have changed and [a complete variable mapping is not available.](https://www.census.gov/data/developers/updates/api-format-changes--sf1-2010.html)
|
22
|
+
|
23
|
+
This Readme and test suite examples have been updated. 1/10/19
|
24
|
+
|
22
25
|
## Usage / Retrieving Census Data
|
23
26
|
|
24
27
|
### (Optional) Set the API key as an environment variable
|
@@ -57,7 +60,7 @@ To query the 2006-2010 ACS5 dataset, set the dataset to 'ACS5':
|
|
57
60
|
Then, use `Client#where` with an options hash to query for Census data. The fields and level parameters are required. The within parameter is optional and scopes the query. For example:
|
58
61
|
|
59
62
|
```ruby
|
60
|
-
@client.where({ fields: '
|
63
|
+
@client.where({ fields: 'P001001', level: 'COUNTY:001', within: 'STATE:06' })
|
61
64
|
|
62
65
|
```
|
63
66
|
|
@@ -83,39 +86,39 @@ The 'within' parameter is optional, or required, depending upon the geography ty
|
|
83
86
|
|
84
87
|
Retrieve fields for all States:
|
85
88
|
|
86
|
-
`@client.where({ fields: '
|
89
|
+
`@client.where({ fields: 'P001001', level: 'STATE' })`
|
87
90
|
|
88
91
|
Retrieve fields for California (geoid: 06):
|
89
92
|
|
90
|
-
`@client.where({ fields: '
|
93
|
+
`@client.where({ fields: 'P001001', level: 'STATE:06' })`
|
91
94
|
|
92
95
|
Retrieve fields for California and Alaska:
|
93
96
|
|
94
|
-
`@client.where({ fields: '
|
97
|
+
`@client.where({ fields: 'P001001', level: 'STATE:06,02' })`
|
95
98
|
|
96
99
|
#### COUNTY - *(050) state-county*
|
97
100
|
|
98
101
|
Retrieve fields for all Counties:
|
99
102
|
|
100
|
-
`@client.where({ fields: '
|
103
|
+
`@client.where({ fields: 'P001001', level: 'COUNTY' })`
|
101
104
|
|
102
105
|
Retrieve fields for Counties in California:
|
103
106
|
|
104
|
-
`@client.where({ fields: '
|
107
|
+
`@client.where({ fields: 'P001001', level: 'COUNTY', within: 'STATE:06' })`
|
105
108
|
|
106
109
|
Retrieve fields for a specific County in California:
|
107
110
|
|
108
|
-
`@client.where({ fields: '
|
111
|
+
`@client.where({ fields: 'P001001', level: 'COUNTY:001', within: 'STATE:06' })`
|
109
112
|
|
110
113
|
#### COUSUB - *(060) state-county-county subdivision*
|
111
114
|
|
112
115
|
Retrieve fields for all County Subdivisions within a specific County:
|
113
116
|
|
114
|
-
`@client.where({ fields: '
|
117
|
+
`@client.where({ fields: 'P001001', level: 'COUSUB', within: 'STATE:02+COUNTY:290' })`
|
115
118
|
|
116
119
|
Retrieve fields for a specific County Subdivision within a specific County:
|
117
120
|
|
118
|
-
`@client.where({ fields: '
|
121
|
+
`@client.where({ fields: 'P001001', level: 'COUSUB:86690', within: 'STATE:02+COUNTY:290' })`
|
119
122
|
|
120
123
|
Note: You must also specify the State the County belongs to.
|
121
124
|
|
@@ -123,231 +126,231 @@ Note: You must also specify the State the County belongs to.
|
|
123
126
|
|
124
127
|
Retrieve fields for all Subminor Civil Subdivisions within a specific County Subdivision:
|
125
128
|
|
126
|
-
`@client.where({ fields: '
|
129
|
+
`@client.where({ fields: 'P001001', level: 'SUBMCD', within: 'STATE:72+COUNTY:127+COUSUB:79693' })`
|
127
130
|
|
128
131
|
Retrieve fields for a specific Subminor Civil Subdivisions within a specific County Subdivision:
|
129
132
|
|
130
|
-
`@client.where({ fields: '
|
133
|
+
`@client.where({ fields: 'P001001', level: 'SUBMCD:02350', within: 'STATE:72+COUNTY:127+COUSUB:79693' })`
|
131
134
|
|
132
135
|
#### TABBLOCK - *(101) state-county-tract-block*
|
133
136
|
|
134
137
|
Retrieve fields for all Blocks within a specific Tract
|
135
138
|
|
136
|
-
`@client.where({ fields: '
|
139
|
+
`@client.where({ fields: 'P001001', level: 'TABBLOCK', within: 'STATE:02+COUNTY:290+TRACT:00100' })`
|
137
140
|
|
138
141
|
Retrieve fields for a specific Subminor Civil Subdivisions within a specific County Subdivision:
|
139
142
|
|
140
|
-
`@client.where({ fields: '
|
143
|
+
`@client.where({ fields: 'P001001', level: 'SUBMCD:02350', within: 'STATE:72+COUNTY:127+COUSUB:79693' })`
|
141
144
|
|
142
145
|
#### TRACT - *(140) state-county-tract*
|
143
146
|
|
144
147
|
Retrieve fields for all Tracts within a specific County:
|
145
148
|
|
146
|
-
`@client.where({ fields: '
|
149
|
+
`@client.where({ fields: 'P001001', level: 'TRACT', within: 'STATE:02+COUNTY:170' })`
|
147
150
|
|
148
151
|
Retrieve fields for a specific Tract within a specific County:
|
149
152
|
|
150
|
-
`@client.where({ fields: '
|
153
|
+
`@client.where({ fields: 'P001001', level: 'TRACT:000101', within: 'STATE:02+COUNTY:170' })`
|
151
154
|
|
152
155
|
#### BG - *(150) state-county- tract-block group*
|
153
156
|
|
154
157
|
Retrieve fields for all Block Groups within a specific Tract:
|
155
158
|
|
156
|
-
`@client.where({ fields: '
|
159
|
+
`@client.where({ fields: 'P001001', level: 'BG', within: 'STATE:02+COUNTY:170+TRACT:000101' })`
|
157
160
|
|
158
161
|
Retrieve fields for a specific Block Group within a specific Tract:
|
159
162
|
|
160
|
-
`@client.where({ fields: '
|
163
|
+
`@client.where({ fields: 'P001001', level: 'BG:1', within: 'STATE:02+COUNTY:170+TRACT:000101' })`
|
161
164
|
|
162
165
|
#### PLACE -*(160) state-place*
|
163
166
|
|
164
167
|
Retrieve fields for all Places:
|
165
168
|
|
166
|
-
`@client.where({ fields: '
|
169
|
+
`@client.where({ fields: 'P001001', level: 'PLACE' })`
|
167
170
|
|
168
171
|
Retrieve fields for all Places within a specific State:
|
169
172
|
|
170
|
-
`@client.where({ fields: '
|
173
|
+
`@client.where({ fields: 'P001001', level: 'PLACE', within: 'STATE:06' })`
|
171
174
|
|
172
175
|
Retrieve fields for a specific place within a specific State:
|
173
176
|
|
174
|
-
`@client.where({ fields: '
|
177
|
+
`@client.where({ fields: 'P001001', level: 'PLACE:00135', within: 'STATE:06' })`
|
175
178
|
|
176
179
|
#### ANRC - *(260) state-alaska native regional corporation*
|
177
180
|
|
178
181
|
Retrieve fields for all Alaska Native Regional Corporations:
|
179
182
|
|
180
|
-
`@client.where({ fields: '
|
183
|
+
`@client.where({ fields: 'P001001', level: 'ANRC' })`
|
181
184
|
|
182
185
|
Retrieve fields for all Alaska Native Regional Corporations within a specific State:
|
183
186
|
|
184
|
-
`@client.where({ fields: '
|
187
|
+
`@client.where({ fields: 'P001001', level: 'ANRC', within: 'STATE:02' })`
|
185
188
|
|
186
189
|
Retrieve fields for all Alaska Native Regional Corporations within a specific State:
|
187
190
|
|
188
|
-
`@client.where({ fields: '
|
191
|
+
`@client.where({ fields: 'P001001', level: 'ANRC:00590', within: 'STATE:02' })`
|
189
192
|
|
190
193
|
#### AIANNH - *(280) state-american indian area/alaska native area/hawaiian home land*
|
191
194
|
|
192
195
|
Retrieve fields for all American Indian Area/Alaska Native Area/Hawaiian Home Land:
|
193
196
|
|
194
|
-
`@client.where({ fields: '
|
197
|
+
`@client.where({ fields: 'P001001', level: 'AIANNH' })`
|
195
198
|
|
196
199
|
Retrieve fields for all American Indian Area/Alaska Native Area/Hawaiian Home Land within a specific State:
|
197
200
|
|
198
|
-
`@client.where({ fields: '
|
201
|
+
`@client.where({ fields: 'P001001', level: 'AIANNH', within: 'STATE:02 }')`
|
199
202
|
|
200
203
|
Retrieve fields for a specific American Indian Area/Alaska Native Area/Hawaiian Home Land within a specific State:
|
201
204
|
|
202
|
-
`@client.where({ fields: '
|
205
|
+
`@client.where({ fields: 'P001001', level: 'AIANNH:03800', within: 'STATE:02' })`
|
203
206
|
|
204
207
|
#### AITS - *(281) state-american indian area-tribal subdivision*
|
205
208
|
|
206
209
|
Retrieve fields for all American Indian Area-Tribal Subdivisions:
|
207
210
|
|
208
|
-
__DOES NOT WORK__: `@client.where({ fields: '
|
211
|
+
__DOES NOT WORK__: `@client.where({ fields: 'P001001', level: 'AITS' })`
|
209
212
|
|
210
213
|
Retrieve fields for all American Indian Area-Tribal Subdivisions in a specific American Indian Area:
|
211
214
|
|
212
|
-
`@client.where({ fields: '
|
215
|
+
`@client.where({ fields: 'P001001', level: 'AITS', within: 'STATE:40+AIANNH:13735' })`
|
213
216
|
|
214
217
|
Retrieve fields for a specific American Indian Area-Tribal Subdivision in a specific American Indian Area:
|
215
218
|
|
216
|
-
`@client.where({ fields: '
|
219
|
+
`@client.where({ fields: 'P001001', level: 'AITS:83127', within: 'STATE:40+AIANNH:13735' })`
|
217
220
|
|
218
221
|
#### CBSA - *(320) state-metropolitan statistical area/micropolitan statistical area*
|
219
222
|
|
220
223
|
Retrieve fields from all Metropolitan Statistical Areas / Micropolitan Statistical Areas in a specific State:
|
221
224
|
|
222
|
-
`@client.where({ fields: '
|
225
|
+
`@client.where({ fields: 'P001001', level: 'CBSA', within: 'STATE:02' })`
|
223
226
|
|
224
227
|
Retrieve fields from a specific Metropolitan Statistical Areas / Micropolitan Statistical Areas in a specific State:
|
225
228
|
|
226
|
-
`@client.where({ fields: '
|
229
|
+
`@client.where({ fields: 'P001001', level: 'CBSA:11260', within: 'STATE:02' })`
|
227
230
|
|
228
231
|
#### METDIV - *(323) state-metropolitan statistical area/micropolitan statistical area- metropolitan division*
|
229
232
|
|
230
233
|
Retrieve fields from all Metropolitan Divisions in a specific Metropolitan Statistical Area / Micropolitan Statistical Area:
|
231
234
|
|
232
|
-
`@client.where({ fields: '
|
235
|
+
`@client.where({ fields: 'P001001', level: 'METDIV', within: 'STATE:06+CBSA:31100' })`
|
233
236
|
|
234
237
|
Retrieve fields from all Metropolitan Division in a specific Metropolitan Statistical Area / Micropolitan Statistical Area:
|
235
238
|
|
236
|
-
`@client.where({ fields: '
|
239
|
+
`@client.where({ fields: 'P001001', level: 'METDIV', within: 'STATE:06+CBSA:31100' })`
|
237
240
|
|
238
241
|
Retrieve fields from a specific Metropolitan Division in a specific Metropolitan Statistical Area / Micropolitan Statistical Area:
|
239
242
|
|
240
|
-
`@client.where({ fields: '
|
243
|
+
`@client.where({ fields: 'P001001', level: 'METDIV:31084', within: 'STATE:06+CBSA:31100' })`
|
241
244
|
|
242
245
|
#### CSA - *(340) - state-combined statistical area*
|
243
246
|
|
244
247
|
Retrieve fields from all Combined Statistical Areas in a specific State:
|
245
248
|
|
246
|
-
`@client.where({ fields: '
|
249
|
+
`@client.where({ fields: 'P001001', level: 'CSA', within: 'STATE:24' })`
|
247
250
|
|
248
251
|
Retrieve fields from a specific Combined Statistical Area in a specific State:
|
249
252
|
|
250
|
-
`@client.where({ fields: '
|
253
|
+
`@client.where({ fields: 'P001001', level: 'CSA:428', within: 'STATE:24' })`
|
251
254
|
|
252
255
|
#### CD - *(500) state-congressional district*
|
253
256
|
|
254
257
|
Retrieve fields from all Congressional Districts in a specific State:
|
255
258
|
|
256
|
-
`@client.where({ fields: '
|
259
|
+
`@client.where({ fields: 'P001001', level: 'CD', within: 'STATE:24' })`
|
257
260
|
|
258
261
|
Retrieve fields from a specific Congressional District in a specific State:
|
259
262
|
|
260
|
-
`@client.where({ fields: '
|
263
|
+
`@client.where({ fields: 'P001001', level: 'CD:01', within: 'STATE:24' })`
|
261
264
|
|
262
265
|
#### COUNTY (Remainder) - *(510) state-congressional district-county*
|
263
266
|
|
264
267
|
Retrieve fields for all Counties within a specific Congressional District:
|
265
268
|
|
266
|
-
`@client.where({ fields: '
|
269
|
+
`@client.where({ fields: 'P001001', level: 'COUNTY', within: 'STATE:24+CD:01' })`
|
267
270
|
|
268
271
|
Retrieve fields for a specific County within a specific Congressional District:
|
269
272
|
|
270
|
-
`@client.where({ fields: '
|
273
|
+
`@client.where({ fields: 'P001001', level: 'COUNTY:003', within: 'STATE:24+CD:01' })`
|
271
274
|
|
272
275
|
#### TRACT (Remainder) - *(511) state-congressional district-county-tract*
|
273
276
|
|
274
277
|
Retrieve fields for all Tracts within a specific Congressional District, County Remainder:
|
275
278
|
|
276
|
-
`@client.where({ fields: '
|
279
|
+
`@client.where({ fields: 'P001001', level: 'TRACT', within: 'STATE:24+CD:01+COUNTY:003' })`
|
277
280
|
|
278
281
|
Retrieve fields for a specific County within a specific Congressional District, County Remainder:
|
279
282
|
|
280
|
-
`@client.where({ fields: '
|
283
|
+
`@client.where({ fields: 'P001001', level: 'TRACT:702100', within: 'STATE:24+CD:01+COUNTY:003' })`
|
281
284
|
|
282
285
|
### COUSUB (Remainder) - *(521) state-congressional district-county-county subdivision*
|
283
286
|
|
284
287
|
Retrieve fields for all County Subdivisions within a specific Congressional District, County Remainder:
|
285
288
|
|
286
|
-
`@client.where({ fields: '
|
289
|
+
`@client.where({ fields: 'P001001', level: 'COUSUB', within: 'STATE:24+CD:01+COUNTY:003' })`
|
287
290
|
|
288
291
|
Retrieve fields for a specific County Subdivision within a specific Congressional District, County Remainder:
|
289
292
|
|
290
|
-
`@client.where({ fields: '
|
293
|
+
`@client.where({ fields: 'P001001', level: 'COUSUB:90100', within: 'STATE:24+CD:01+COUNTY:003' })`
|
291
294
|
|
292
295
|
#### PLACE (Remainder) - *(531) state congressional district-place*
|
293
296
|
|
294
297
|
Retrieve fields for all Places within a specific Congressional District:
|
295
298
|
|
296
|
-
`@client.where({ fields: '
|
299
|
+
`@client.where({ fields: 'P001001', level: 'PLACE', within: 'STATE:24+CD:01' })`
|
297
300
|
|
298
301
|
Retrieve fields for a specific Place within a specific Congressional District, County Remainder:
|
299
302
|
|
300
|
-
`@client.where({ fields: '
|
303
|
+
`@client.where({ fields: 'P001001', level: 'PLACE:00125', within: 'STATE:24+CD:01' })`
|
301
304
|
|
302
305
|
#### AIANNH (Remainder) - *550) state-congressional district-american indian area/alaska native area/hawaiian home land*
|
303
306
|
|
304
307
|
Retrieve fields for all American Indian Area/Alaska Native Area/Hawaiian Home Lands within a specific Congressional District:
|
305
308
|
|
306
|
-
`@client.where({ fields: '
|
309
|
+
`@client.where({ fields: 'P001001', level: 'AIANNH', within: 'STATE:02+CD:00' })`
|
307
310
|
|
308
311
|
Retrieve fields for a specific American Indian Area/Alaska Native Area/Hawaiian Home Land within a specific Congressional District:
|
309
312
|
|
310
|
-
__DOES NOT WORK__: `@client.where({ fields: '
|
313
|
+
__DOES NOT WORK__: `@client.where({ fields: 'P001001', level: 'AIANNH:0010', within: 'STATE:02+CD:00' })`
|
311
314
|
|
312
315
|
#### ANRC (Remainder) - *(560) state-congressional district-alaska native regional corporation*
|
313
316
|
|
314
317
|
Retrieve fields for all Alaska Native Regional Corporations within a specific Congressional District:
|
315
318
|
|
316
|
-
`@client.where({ fields: '
|
319
|
+
`@client.where({ fields: 'P001001', level: 'AIANNH', within: 'STATE:02+CD:00' })`
|
317
320
|
|
318
321
|
Retrieve fields for a specific Alaska Native Regional Corporation within a specific Congressional District:
|
319
322
|
|
320
|
-
`@client.where({ fields: '
|
323
|
+
`@client.where({ fields: 'P001001', level: 'AIANNH:00590', within: 'STATE:02+CD:00' })`
|
321
324
|
|
322
325
|
#### SLDU - *(610) state-state legislative district (upper chamber)*
|
323
326
|
|
324
327
|
Retrieve fields for all State Legislative Districts (Upper Chamber) within a State:
|
325
328
|
|
326
|
-
`@client.where({ fields: '
|
329
|
+
`@client.where({ fields: 'P001001', level: 'SLDU', within: 'STATE:02' })`
|
327
330
|
|
328
331
|
Retrieve fields for a specific State Legislative District (Upper Chamber) within a State:
|
329
332
|
|
330
|
-
`@client.where({ fields: '
|
333
|
+
`@client.where({ fields: 'P001001', level: 'SLDU:00A', within: 'STATE:02' })`
|
331
334
|
|
332
335
|
#### SLDU - *(620) state-state legislative district (lower chamber)*
|
333
336
|
|
334
337
|
Retrieve fields for all State Legislative Districts (Lower Chamber) within a State:
|
335
338
|
|
336
|
-
`@client.where({ fields: '
|
339
|
+
`@client.where({ fields: 'P001001', level: 'SLDL', within: 'STATE:02' })`
|
337
340
|
|
338
341
|
Retrieve fields for a specific State Legislative District (Lower Chamber) within a State:
|
339
342
|
|
340
|
-
`@client.where({ fields: '
|
343
|
+
`@client.where({ fields: 'P001001', level: 'SLDL:001', within: 'STATE:02' })`
|
341
344
|

|
342
345
|
#### ZCTA5 - *(871) state-zip code tabulation area*
|
343
346
|
|
344
347
|
Retrieve fields for all Zip Code Tabulation Areas within a specific State:
|
345
348
|
|
346
|
-
`@client.where({ fields: '
|
349
|
+
`@client.where({ fields: 'P001001', level: 'ZCTA5', within: 'STATE:02' })`
|
347
350
|
|
348
351
|
Retrieve fields for a specific Zip Code Tabulation Area within a specific State:
|
349
352
|
|
350
|
-
`@client.where({ fields: '
|
353
|
+
`@client.where({ fields: 'P001001', level: 'ZCTA5:99501', within: 'STATE:02' })`
|
351
354
|
|
352
355
|
## ACS5 2010 Examples and Supported Geography
|
353
356
|
|
data/Rakefile
CHANGED
data/census_api.gemspec
CHANGED
@@ -22,8 +22,11 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.require_paths = ['lib']
|
23
23
|
|
24
24
|
gem.add_runtime_dependency 'http'
|
25
|
+
gem.add_development_dependency 'bundler', '~> 2.0.1'
|
26
|
+
gem.add_development_dependency 'rake'
|
25
27
|
gem.add_development_dependency 'rspec'
|
26
|
-
gem.add_development_dependency 'webmock', '
|
27
|
-
gem.add_development_dependency 'vcr'
|
28
|
+
gem.add_development_dependency 'webmock', '>= 3.4.2'
|
29
|
+
gem.add_development_dependency 'vcr', '>= 4.0'
|
28
30
|
gem.add_development_dependency 'rubocop'
|
31
|
+
gem.add_development_dependency 'rest-client'
|
29
32
|
end
|
data/lib/census_api/client.rb
CHANGED
@@ -29,7 +29,7 @@ module CensusApi
|
|
29
29
|
[:fields, :level].each do |f|
|
30
30
|
fail ArgumentError, "#{f} is a requied parameter" if options[f].nil?
|
31
31
|
end
|
32
|
-
options[:within] = [options[:within]]
|
32
|
+
options[:within] = [options[:within]] unless options[:within].nil?
|
33
33
|
Request.find(dataset, options)
|
34
34
|
end
|
35
35
|
|
data/lib/census_api/request.rb
CHANGED
@@ -11,6 +11,19 @@ module CensusApi
|
|
11
11
|
attr_accessor :response
|
12
12
|
|
13
13
|
def initialize(vintage, source, options)
|
14
|
+
api_changes = [
|
15
|
+
{source: 'acs1', from: 2012, to: 2015, new_endpoint: 'acs/acs1'},
|
16
|
+
#{source: 'acs3', from: 2012, to: 2013, new_endpoint: 'acs/acs3'},
|
17
|
+
{source: 'acs5', from: 2010, to: 2015, new_endpoint: 'acs/acs5'},
|
18
|
+
{source: 'acsse', from: 2014, to: 2015, new_endpoint: 'acs/acsse'},
|
19
|
+
{source: 'sf1', from: 2010, to: 2010, new_endpoint: 'dec/sf1'}
|
20
|
+
]
|
21
|
+
route = api_changes.detect do |a|
|
22
|
+
a[:source] == source && a[:from] <= vintage.to_i && a[:to] >= vintage.to_i
|
23
|
+
end
|
24
|
+
if route
|
25
|
+
source = route[:new_endpoint]
|
26
|
+
end
|
14
27
|
uri = "/data/#{vintage}/#{source}?#{to_params(options)}"
|
15
28
|
@response = $census_connection.get(uri.to_s)
|
16
29
|
@response.flush
|
@@ -20,12 +33,13 @@ module CensusApi
|
|
20
33
|
fields = options[:fields]
|
21
34
|
fields = fields.split(',').push('NAME').join(',') if fields.is_a? String
|
22
35
|
fields = fields.push('NAME').join(',') if fields.is_a? Array
|
23
|
-
level = format(options[:level]
|
24
|
-
params = {
|
25
|
-
unless
|
26
|
-
params.merge!(in: format(options[:within]
|
36
|
+
level = format(options[:level])
|
37
|
+
params = { get: fields, for: level }
|
38
|
+
unless options[:within].nil? || (options[:within].is_a?(Array) && options[:within].empty?)
|
39
|
+
params.merge!(in: format(options[:within].join("+")))
|
27
40
|
end
|
28
41
|
options.merge!(vintage: 2010) unless options[:vintage]
|
42
|
+
params.merge!(key: options[:key]) if !!(options[:key])
|
29
43
|
request = new(options[:vintage], source, params)
|
30
44
|
request.parse_response
|
31
45
|
end
|
@@ -61,22 +75,18 @@ module CensusApi
|
|
61
75
|
}
|
62
76
|
end
|
63
77
|
|
64
|
-
def self.format(str
|
65
|
-
|
78
|
+
def self.format(str)
|
79
|
+
str.split("+").map do |s|
|
66
80
|
s = s.match(':') ? s.split(':') : [s, '*']
|
67
|
-
|
68
|
-
name
|
69
|
-
|
70
|
-
s.unshift(s.shift.split('/')[0]) if !s[0].scan('home+land').empty? && truncate
|
71
|
-
s.join(':')
|
72
|
-
end
|
73
|
-
result.join('+')
|
81
|
+
name = (shapes[s[0]]['attribute'] rescue s[0]).gsub(/\s/, '%20')
|
82
|
+
s.shift && s.unshift(name) && s.join(':')
|
83
|
+
end.join("%20")
|
74
84
|
end
|
75
85
|
|
76
86
|
def self.shapes
|
77
87
|
return @@census_shapes if defined?(@@census_shapes)
|
78
88
|
@@census_shapes = {}
|
79
|
-
path = "#{File.dirname(__FILE__)}/../
|
89
|
+
path = "#{File.dirname(__FILE__)}/../data/census_shapes.yml"
|
80
90
|
YAML.load_file(path).each { |k, v| @@census_shapes[k] = v }
|
81
91
|
@@census_shapes
|
82
92
|
end
|