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
@@ -0,0 +1,61 @@
|
|
1
|
+
module Census2012AcsAcs1
|
2
|
+
EXAMPLES = [
|
3
|
+
["B00001_001E", "US:*"],
|
4
|
+
["B00001_001E", "US:1"],
|
5
|
+
["B00001_001E", "REGION:*"],
|
6
|
+
["B00001_001E", "REGION:1"],
|
7
|
+
["B00001_001E", "DIVISION:*"],
|
8
|
+
["B00001_001E", "DIVISION:1"],
|
9
|
+
["B00001_001E", "STATE:*"],
|
10
|
+
["B00001_001E", "STATE:01"],
|
11
|
+
["B00001_001E", "COUNTY:*", ["STATE:*"]],
|
12
|
+
["B00001_001E", "COUNTY:*", ["STATE:02"]],
|
13
|
+
["B00001_001E", "COUNTY:020", ["STATE:02"]],
|
14
|
+
["B00001_001E", "COUSUB:*", ["STATE:36", "COUNTY:029"]],
|
15
|
+
["B00001_001E", "COUSUB:02000", ["STATE:36", "COUNTY:029"]],
|
16
|
+
["B00001_001E", "PLACE:*", ["STATE:*"]],
|
17
|
+
["B00001_001E", "PLACE:*", ["STATE:01"]],
|
18
|
+
["B00001_001E", "PLACE:07000", ["STATE:01"]],
|
19
|
+
["B00001_001E", "ANRC:*", ["STATE:*"]],
|
20
|
+
["B00001_001E", "ANRC:*", ["STATE:02"]],
|
21
|
+
["B00001_001E", "ANRC:67940", ["STATE:02"]],
|
22
|
+
["B00001_001E", "AIANNH:*"],
|
23
|
+
["B00001_001E", "AIANNH:2430"],
|
24
|
+
["B00001_001E", "CBSA:*"],
|
25
|
+
["B00001_001E", "CBSA:10420"],
|
26
|
+
["B00001_001E", "CSA:*"],
|
27
|
+
["B00001_001E", "CSA:104"],
|
28
|
+
["B00001_001E", "NECTA:*"],
|
29
|
+
["B00001_001E", "NECTA:71650"],
|
30
|
+
["B00001_001E", "UAC:*"],
|
31
|
+
["B00001_001E", "UAC:27253"],
|
32
|
+
["B00001_001E", "CD:*", ["STATE:*"]],
|
33
|
+
["B00001_001E", "CD:*", ["STATE:01"]],
|
34
|
+
["B00001_001E", "CD:01", ["STATE:01"]],
|
35
|
+
["B00001_001E", "ELSD:*", ["STATE:*"]],
|
36
|
+
["B00001_001E", "ELSD:*", ["STATE:04"]],
|
37
|
+
["B00001_001E", "ELSD:00600", ["STATE:04"]],
|
38
|
+
["B00001_001E", "SCSD:*", ["STATE:*"]],
|
39
|
+
["B00001_001E", "SCSD:*", ["STATE:04"]],
|
40
|
+
["B00001_001E", "SCSD:00450", ["STATE:04"]],
|
41
|
+
["B00001_001E", "UNSD:*", ["STATE:*"]],
|
42
|
+
["B00001_001E", "UNSD:*", ["STATE:01"]],
|
43
|
+
["B00001_001E", "UNSD:00007", ["STATE:01"]],
|
44
|
+
["B00001_001E", "public%20use%20microdata%20area:*", ["STATE:*"]],
|
45
|
+
["B00001_001E", "public%20use%20microdata%20area:*", ["STATE:04"]],
|
46
|
+
["B00001_001E", "public%20use%20microdata%20area:00202", ["STATE:04"]],
|
47
|
+
["B00001_001E", "METDIV:*", ["CBSA:*"]],
|
48
|
+
["B00001_001E", "METDIV:*", ["CBSA:31100"]],
|
49
|
+
["B00001_001E", "METDIV:31084", ["CBSA:31100"]],
|
50
|
+
["B00001_001E", "CNECTA:*"],
|
51
|
+
["B00001_001E", "CNECTA:715"],
|
52
|
+
["B00001_001E", "principal%20city%20(or%20part):*", ["CBSA:*"]],
|
53
|
+
["B00001_001E", "principal%20city%20(or%20part):*", ["CBSA:10740"]],
|
54
|
+
["B00001_001E", "principal%20city%20(or%20part):02000", ["CBSA:10740"]],
|
55
|
+
["B00001_001E", "PCITY:*", ["NECTA:*"]],
|
56
|
+
["B00001_001E", "PCITY:*", ["NECTA:71950"]],
|
57
|
+
["B00001_001E", "PCITY:73000", ["NECTA:71950"]],
|
58
|
+
["B00001_001E", "NECTADIV:*", ["NECTA:71650"]],
|
59
|
+
["B00001_001E", "NECTADIV:71654", ["NECTA:71650"]]
|
60
|
+
]
|
61
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
module Census2015AcsAcs5
|
2
|
+
EXAMPLES = [
|
3
|
+
["NAME", "US:*"],
|
4
|
+
["NAME", "US:1"],
|
5
|
+
["NAME", "REGION:*"],
|
6
|
+
["NAME", "REGION:1"],
|
7
|
+
["NAME", "DIVISION:*"],
|
8
|
+
["NAME", "DIVISION:1"],
|
9
|
+
["NAME", "STATE:*"],
|
10
|
+
["NAME", "STATE:01"],
|
11
|
+
["NAME", "COUNTY:*", ["STATE:*"]],
|
12
|
+
["NAME", "COUNTY:*", ["STATE:02"]],
|
13
|
+
["NAME", "COUNTY:013", ["STATE:02"]],
|
14
|
+
["NAME", "COUSUB:*", ["STATE:36", "COUNTY:*"]],
|
15
|
+
["NAME", "COUSUB:*", ["STATE:36", "COUNTY:029"]],
|
16
|
+
["NAME", "COUSUB:01099", ["STATE:36", "COUNTY:029"]],
|
17
|
+
["NAME", "TRACT:*", ["STATE:01", "COUNTY:*"]],
|
18
|
+
["NAME", "TRACT:*", ["STATE:01", "COUNTY:073"]],
|
19
|
+
["NAME", "TRACT:000100", ["STATE:01", "COUNTY:073"]],
|
20
|
+
["NAME", "PLACE:*", ["STATE:*"]],
|
21
|
+
["NAME", "PLACE:*", ["STATE:02"]],
|
22
|
+
["NAME", "PLACE:00065", ["STATE:02"]],
|
23
|
+
["NAME", "ANRC:*", ["STATE:*"]],
|
24
|
+
["NAME", "ANRC:*", ["STATE:02"]],
|
25
|
+
["NAME", "ANRC:41640", ["STATE:02"]],
|
26
|
+
["NAME", "AIANNH:*"],
|
27
|
+
["NAME", "AIANNH:0010"],
|
28
|
+
["NAME", "CBSA:*"],
|
29
|
+
["NAME", "CBSA:10100"],
|
30
|
+
["NAME", "CSA:*"],
|
31
|
+
["NAME", "CSA:104"],
|
32
|
+
["NAME", "NECTA:*"],
|
33
|
+
["NAME", "NECTA:70450"],
|
34
|
+
["NAME", "UAC:*"],
|
35
|
+
["NAME", "UAC:00037"],
|
36
|
+
["NAME", "CD:*", ["STATE:*"]],
|
37
|
+
["NAME", "CD:*", ["STATE:56"]],
|
38
|
+
["NAME", "CD:00", ["STATE:56"]],
|
39
|
+
["NAME", "ELSD:*", ["STATE:50"]],
|
40
|
+
["NAME", "ELSD:00001", ["STATE:50"]],
|
41
|
+
["NAME", "SCSD:*", ["STATE:50"]],
|
42
|
+
["NAME", "SCSD:00002", ["STATE:50"]],
|
43
|
+
["NAME", "UNSD:*", ["STATE:01"]],
|
44
|
+
["NAME", "UNSD:00001", ["STATE:01"]],
|
45
|
+
["NAME", "COUNTY:*", ["STATE:01", "PLACE:62328"]],
|
46
|
+
["NAME", "COUNTY:001", ["STATE:01", "PLACE:62328"]],
|
47
|
+
["NAME", "place%20remainder:*", ["STATE:01", "COUNTY:001", "COUSUB:92106"]],
|
48
|
+
["NAME", "place%20remainder:60264", ["STATE:01", "COUNTY:001", "COUSUB:92106"]],
|
49
|
+
["NAME", "BG:*", ["STATE:06", "COUNTY:061", "TRACT:*"]],
|
50
|
+
["NAME", "BG:*", ["STATE:06", "COUNTY:061", "TRACT:990000"]],
|
51
|
+
["NAME", "BG:0", ["STATE:06", "COUNTY:061", "TRACT:990000"]],
|
52
|
+
["NAME", "public%20use%20microdata%20area:*", ["STATE:*"]],
|
53
|
+
["NAME", "public%20use%20microdata%20area:*", ["STATE:36"]],
|
54
|
+
["NAME", "public%20use%20microdata%20area:00100", ["STATE:36"]],
|
55
|
+
["NAME", "ZCTA5:*"],
|
56
|
+
["NAME", "ZCTA5:00610"],
|
57
|
+
["NAME", "SLDU:*", ["STATE:12"]],
|
58
|
+
["NAME", "SLDU:001", ["STATE:12"]],
|
59
|
+
["NAME", "SLDL:*", ["STATE:01"]],
|
60
|
+
["NAME", "SLDL:001", ["STATE:01"]],
|
61
|
+
["NAME", "PCITY:*", ["CBSA:11500", "STATE:01"]],
|
62
|
+
["NAME", "PCITY:57576", ["CBSA:11500", "STATE:01"]],
|
63
|
+
["NAME", "METDIV:*", ["CBSA:14460"]],
|
64
|
+
["NAME", "METDIV:40484", ["CBSA:14460"]],
|
65
|
+
["NAME", "CBSA:*", ["STATE:46"]],
|
66
|
+
["NAME", "CBSA:10100", ["STATE:46"]],
|
67
|
+
["NAME", "principal%20city%20(or%20part):*", ["STATE:01", "CBSA:11500"]],
|
68
|
+
["NAME", "principal%20city%20(or%20part):57576", ["STATE:01", "CBSA:11500"]],
|
69
|
+
["NAME", "STATE:*", ["CBSA:10700"]],
|
70
|
+
["NAME", "STATE:01", ["CBSA:10700"]],
|
71
|
+
["NAME", "AIANNH:*", ["STATE:01"]],
|
72
|
+
["NAME", "AIANNH:9820", ["STATE:01"]],
|
73
|
+
["NAME", "CNECTA:*"],
|
74
|
+
["NAME", "CNECTA:775"],
|
75
|
+
["NAME", "CSA:*", ["STATE:41"]],
|
76
|
+
["NAME", "CSA:140", ["STATE:41"]],
|
77
|
+
["NAME", "CNECTA:*", ["STATE:09"]],
|
78
|
+
["NAME", "CNECTA:715", ["STATE:09"]],
|
79
|
+
["NAME", "NECTA:*", ["STATE:09"]],
|
80
|
+
["NAME", "NECTA:76450", ["STATE:09"]],
|
81
|
+
["NAME", "STATE:*", ["urban%20growth%20area:02791"]],
|
82
|
+
["NAME", "STATE:01", ["urban%20growth%20area:02791"]],
|
83
|
+
["NAME", "COUNTY:*", ["urban%20growth%20area:68482", "STATE:01"]],
|
84
|
+
["NAME", "COUNTY:003", ["urban%20growth%20area:68482", "STATE:01"]],
|
85
|
+
["NAME", "COUNTY:*", ["STATE:01", "SLDU:030"]],
|
86
|
+
["NAME", "COUNTY:001", ["STATE:01", "SLDU:030"]],
|
87
|
+
["NAME", "COUNTY:*", ["STATE:01", "SLDL:096"]],
|
88
|
+
["NAME", "COUNTY:003", ["STATE:01", "SLDL:096"]],
|
89
|
+
["NAME", "STATE:*", ["NECTA:71950"]],
|
90
|
+
["NAME", "STATE:09", ["NECTA:71950"]],
|
91
|
+
["NAME", "principal%20city%20(or%20part):*", ["NECTA:70450", "STATE:*"]],
|
92
|
+
["NAME", "principal%20city%20(or%20part):*", ["NECTA:70450", "STATE:25"]],
|
93
|
+
["NAME", "principal%20city%20(or%20part):02515", ["NECTA:70450", "STATE:25"]],
|
94
|
+
["NAME", "county%20(or%20part):*", ["NECTA:70450", "STATE:*"]],
|
95
|
+
["NAME", "county%20(or%20part):*", ["NECTA:70450", "STATE:25"]],
|
96
|
+
["NAME", "county%20(or%20part):011", ["NECTA:70450", "STATE:25"]],
|
97
|
+
["NAME", "county%20subdivision%20(or%20part):*", ["NECTA:70450", "STATE:25", "COUNTY:*"]],
|
98
|
+
["NAME", "county%20subdivision%20(or%20part):*", ["NECTA:70450", "STATE:25", "COUNTY:011"]],
|
99
|
+
["NAME", "county%20subdivision%20(or%20part):51265", ["NECTA:70450", "STATE:25", "COUNTY:011"]],
|
100
|
+
["NAME", "NECTADIV:*", ["NECTA:71650"]],
|
101
|
+
["NAME", "NECTADIV:74204", ["NECTA:71650"]],
|
102
|
+
["NAME", "STATE:*", ["NECTA:71650", "NECTADIV:71654"]],
|
103
|
+
["NAME", "STATE:25", ["NECTA:71650", "NECTADIV:71654"]],
|
104
|
+
["NAME", "county%20(or%20part):*", ["NECTA:71650", "NECTADIV:71654", "STATE:25"]],
|
105
|
+
["NAME", "county%20(or%20part):005", ["NECTA:71650", "NECTADIV:71654", "STATE:25"]],
|
106
|
+
["NAME", "county%20subdivision%20(or%20part):*", ["NECTA:71650", "NECTADIV:71654", "STATE:25", "COUNTY:005"]],
|
107
|
+
["NAME", "county%20subdivision%20(or%20part):38225", ["NECTA:71650", "NECTADIV:71654", "STATE:25", "COUNTY:005"]],
|
108
|
+
["NAME", "PCITY:*", ["STATE:09", "NECTA:71950"]],
|
109
|
+
["NAME", "PCITY:74260", ["STATE:09", "NECTA:71950"]],
|
110
|
+
["NAME", "COUNTY:*", ["STATE:09", "NECTA:71950"]],
|
111
|
+
["NAME", "COUNTY:001", ["STATE:09", "NECTA:71950"]],
|
112
|
+
["NAME", "COUSUB:*", ["STATE:09", "NECTA:71950", "COUNTY:001"]],
|
113
|
+
["NAME", "COUSUB:33620", ["STATE:09", "NECTA:71950", "COUNTY:001"]],
|
114
|
+
["NAME", "NECTADIV:*", ["STATE:25", "NECTA:71650"]],
|
115
|
+
["NAME", "NECTADIV:74204", ["STATE:25", "NECTA:71650"]],
|
116
|
+
["NAME", "COUNTY:*", ["STATE:25", "NECTA:71650", "NECTADIV:73604"]],
|
117
|
+
["NAME", "COUNTY:009", ["STATE:25", "NECTA:71650", "NECTADIV:73604"]],
|
118
|
+
["NAME", "COUSUB:*", ["STATE:25", "NECTA:71650", "NECTADIV:71654", "COUNTY:009"]],
|
119
|
+
["NAME", "COUSUB:07420", ["STATE:25", "NECTA:71650", "NECTADIV:71654", "COUNTY:009"]],
|
120
|
+
["NAME", "COUNTY:*", ["STATE:01", "CD:06"]],
|
121
|
+
["NAME", "COUNTY:007", ["STATE:01", "CD:06"]],
|
122
|
+
["NAME", "AIANNH:*", ["STATE:01", "CD:02"]],
|
123
|
+
["NAME", "AIANNH:2865", ["STATE:01", "CD:02"]],
|
124
|
+
["NAME", "county%20(or%20part):*", ["CBSA:10100", "STATE:46"]],
|
125
|
+
["NAME", "county%20(or%20part):013", ["CBSA:10100", "STATE:46"]],
|
126
|
+
["NAME", "STATE:*", ["CBSA:31080", "METDIV:31084"]],
|
127
|
+
["NAME", "STATE:06", ["CBSA:31080", "METDIV:31084"]],
|
128
|
+
["NAME", "county%20(or%20part):*", ["CBSA:14460", "METDIV:14454", "STATE:25"]],
|
129
|
+
["NAME", "county%20(or%20part):021", ["CBSA:14460", "METDIV:14454", "STATE:25"]],
|
130
|
+
["NAME", "COUNTY:*", ["STATE:01", "CBSA:13820"]],
|
131
|
+
["NAME", "COUNTY:009", ["STATE:01", "CBSA:13820"]],
|
132
|
+
["NAME", "METDIV:*", ["STATE:06", "CBSA:41860"]],
|
133
|
+
["NAME", "METDIV:42034", ["STATE:06", "CBSA:41860"]],
|
134
|
+
["NAME", "COUNTY:*", ["STATE:06", "CBSA:41860", "METDIV:36084"]],
|
135
|
+
["NAME", "COUNTY:001", ["STATE:06", "CBSA:41860", "METDIV:36084"]],
|
136
|
+
["NAME", "STATE:*", ["CSA:308"]],
|
137
|
+
["NAME", "STATE:05", ["CSA:308"]],
|
138
|
+
["NAME", "CBSA:*", ["CSA:364"]],
|
139
|
+
["NAME", "CBSA:41900", ["CSA:364"]],
|
140
|
+
["NAME", "STATE:*", ["CSA:142", "CBSA:45180"]],
|
141
|
+
["NAME", "STATE:01", ["CSA:142", "CBSA:45180"]],
|
142
|
+
["NAME", "STATE:*", ["CNECTA:715"]],
|
143
|
+
["NAME", "STATE:09", ["CNECTA:715"]],
|
144
|
+
["NAME", "NECTA:*", ["CNECTA:710"]],
|
145
|
+
["NAME", "NECTA:78850", ["CNECTA:710"]],
|
146
|
+
["NAME", "STATE:*", ["CNECTA:720", "NECTA:78700"]],
|
147
|
+
["NAME", "STATE:09", ["CNECTA:720", "NECTA:78700"]],
|
148
|
+
["NAME", "metropolitan%20statistical%20area/micropolitan%20statistical%20area%20(or%20part):*", ["STATE:01", "CSA:142"]],
|
149
|
+
["NAME", "metropolitan%20statistical%20area/micropolitan%20statistical%20area%20(or%20part):45180", ["STATE:01", "CSA:142"]],
|
150
|
+
["NAME", "NECTA:*", ["STATE:09", "CNECTA:720"]],
|
151
|
+
["NAME", "NECTA:78700", ["STATE:09", "CNECTA:720"]],
|
152
|
+
["NAME", "CONCITY:*", ["STATE:*"]],
|
153
|
+
["NAME", "CONCITY:*", ["STATE:09"]],
|
154
|
+
["NAME", "CONCITY:47500", ["STATE:09"]],
|
155
|
+
["NAME", "PLACE:*", ["STATE:13", "CONCITY:03436"]],
|
156
|
+
["NAME", "PLACE:03440", ["STATE:13", "CONCITY:03436"]],
|
157
|
+
["NAME", "american%20indian%20tribal%20subdivision/remainder:*", ["AIANNH:*"]],
|
158
|
+
["NAME", "american%20indian%20tribal%20subdivision/remainder:*", ["AIANNH:0605"]],
|
159
|
+
["NAME", "american%20indian%20tribal%20subdivision/remainder:600", ["AIANNH:0605"]],
|
160
|
+
["NAME", "AIAANA:*"],
|
161
|
+
["NAME", "AIAANA:0155"],
|
162
|
+
["NAME", "AIAHHL:*"],
|
163
|
+
["NAME", "AIAHHL:0305"],
|
164
|
+
["NAME", "TTRACT:*", ["AIANNH:0020"]],
|
165
|
+
["NAME", "TTRACT:T00900", ["AIANNH:0020"]],
|
166
|
+
["NAME", "TBG:*", ["AIANNH:0020", "TTRACT:T00400"]],
|
167
|
+
["NAME", "TBG:B", ["AIANNH:0020", "TTRACT:T00400"]],
|
168
|
+
["NAME", "STATE:*", ["AIANNH:6070"]],
|
169
|
+
["NAME", "STATE:02", ["AIANNH:6070"]],
|
170
|
+
["NAME", "place%20remainder:*", ["AIANNH:9550", "STATE:01"]],
|
171
|
+
["NAME", "place%20remainder:80376", ["AIANNH:9550", "STATE:01"]],
|
172
|
+
["NAME", "COUNTY:*", ["AIANNH:2865", "STATE:01"]],
|
173
|
+
["NAME", "COUNTY:053", ["AIANNH:2865", "STATE:01"]],
|
174
|
+
["NAME", "AIAANA:*", ["STATE:01"]],
|
175
|
+
["NAME", "AIAANA:9820", ["STATE:01"]],
|
176
|
+
["NAME", "AIAHHL:*", ["STATE:04"]],
|
177
|
+
["NAME", "AIAHHL:4200", ["STATE:04"]],
|
178
|
+
["NAME", "STATE:*", ["AIANNH:1310", "american%20indian%20tribal%20subdivision/remainder:700"]],
|
179
|
+
["NAME", "STATE:04", ["AIANNH:1310", "american%20indian%20tribal%20subdivision/remainder:700"]],
|
180
|
+
["NAME", "TTRACT:*", ["american%20indian%20area%20reservation%20only:0020"]],
|
181
|
+
["NAME", "TTRACT:T00900", ["american%20indian%20area%20reservation%20only:0020"]],
|
182
|
+
["NAME", "TTRACT:*", ["AIAHHL:0010"]],
|
183
|
+
["NAME", "TTRACT:T00100", ["AIAHHL:0010"]],
|
184
|
+
["NAME", "TBG:*", ["american%20indian%20area%20reservation%20only:0010", "TTRACT:T00100"]],
|
185
|
+
["NAME", "TBG:C", ["american%20indian%20area%20reservation%20only:0010", "TTRACT:T00100"]],
|
186
|
+
["NAME", "TBG:*", ["AIAHHL:0020", "TTRACT:T00800"]],
|
187
|
+
["NAME", "TBG:C", ["AIAHHL:0020", "TTRACT:T00800"]],
|
188
|
+
["NAME", "SUBMCD:*", ["STATE:72", "COUNTY:005", "COUSUB:00788"]],
|
189
|
+
["NAME", "SUBMCD:81675", ["STATE:72", "COUNTY:005", "COUSUB:00788"]]
|
190
|
+
]
|
191
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
def self.shapes
|
6
|
+
census_shapes = {}
|
7
|
+
path = "#{File.dirname(__FILE__)}/../../lib/data/census_shapes.yml"
|
8
|
+
YAML.load_file(path).each { |k, v| census_shapes[v['attribute']] = k }
|
9
|
+
census_shapes
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.name(string)
|
13
|
+
n = (shapes[string] || string).gsub(/\s/, '%20')
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.request(url)
|
17
|
+
begin
|
18
|
+
f = RestClient.get url
|
19
|
+
JSON.parse(f.body)
|
20
|
+
rescue => e
|
21
|
+
raise e
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.read(opts=[])
|
26
|
+
open("../support/data/#{opts.join("_")}.rb").read
|
27
|
+
end
|
28
|
+
|
29
|
+
# Generate test examples from a vintage and dataset
|
30
|
+
# generate("census_2010_dec_sf1", "https://api.census.gov/data/2010/dec/sf1/examples.json")
|
31
|
+
# generate("census_2015_acs_acs5", "https://api.census.gov/data/2015/acs/acs5/examples.json")
|
32
|
+
|
33
|
+
def self.generate(opts=[])
|
34
|
+
url = "https://api.census.gov/data/#{opts.join("/")}/examples.json"
|
35
|
+
filename = opts.join("_")
|
36
|
+
request = request(url)
|
37
|
+
fields = request['get'].shift
|
38
|
+
h = {}
|
39
|
+
tests = []
|
40
|
+
request['fips'].each_with_index do |ex, i|
|
41
|
+
if ex['in']
|
42
|
+
ex['in'].each do |ex_in|
|
43
|
+
if ex_in['wildcard']
|
44
|
+
tests.push [fields, "#{name(ex['name'])}:*", ex['in'].map{|x| "#{name(x['name'])}:#{
|
45
|
+
x['name'] == ex_in['name'] ? '*' : x['exampleValue']
|
46
|
+
}"}]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
path = ex['in'].map{|x| "#{name(x['name'])}:#{x['exampleValue']}"}
|
50
|
+
tests.push [fields, "#{name(ex['name'])}:*", path]
|
51
|
+
tests.push [fields, "#{name(ex['name'])}:#{ex['exampleValue']}", path]
|
52
|
+
else
|
53
|
+
tests.push [fields, "#{name(ex['name'])}:*"]
|
54
|
+
if ex['exampleValue']
|
55
|
+
tests.push [fields, "#{name(ex['name'])}:#{ex['exampleValue']}"]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
File.open("#{File.dirname(__FILE__)}/data/census_#{filename}.rb", 'w') do |file|
|
60
|
+
file.write("module Census#{filename.split("_").map(&:capitalize).join}\n EXAMPLES = [\n")
|
61
|
+
file.write(tests.map{ |t| " #{t}" }.join(",\n"))
|
62
|
+
file.write("\n ]\nend\n")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/spec/vcr_setup.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: census_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ty Rauber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rspec
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,18 +70,32 @@ dependencies:
|
|
42
70
|
name: webmock
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- - "
|
73
|
+
- - ">="
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
75
|
+
version: 3.4.2
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- - "
|
80
|
+
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
82
|
+
version: 3.4.2
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
101
|
- - ">="
|
@@ -67,7 +109,7 @@ dependencies:
|
|
67
109
|
- !ruby/object:Gem::Version
|
68
110
|
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
112
|
+
name: rest-client
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
115
|
- - ">="
|
@@ -88,6 +130,7 @@ extensions: []
|
|
88
130
|
extra_rdoc_files: []
|
89
131
|
files:
|
90
132
|
- ".gitignore"
|
133
|
+
- ".travis.yml"
|
91
134
|
- Gemfile
|
92
135
|
- LICENSE.txt
|
93
136
|
- README.md
|
@@ -97,13 +140,16 @@ files:
|
|
97
140
|
- lib/census_api/client.rb
|
98
141
|
- lib/census_api/request.rb
|
99
142
|
- lib/census_api/version.rb
|
100
|
-
- lib/
|
101
|
-
-
|
143
|
+
- lib/data/census_shapes.yml
|
144
|
+
- lib/data/geography.json
|
102
145
|
- spec/census_api/client_spec.rb
|
103
|
-
- spec/census_api/
|
146
|
+
- spec/census_api/examples_spec.rb
|
104
147
|
- spec/census_api/request_spec.rb
|
105
148
|
- spec/spec_helper.rb
|
106
|
-
- spec/support/
|
149
|
+
- spec/support/data/census_2010_dec_sf1.rb
|
150
|
+
- spec/support/data/census_2012_acs_acs1.rb
|
151
|
+
- spec/support/data/census_2015_acs_acs5.rb
|
152
|
+
- spec/support/examples.rb
|
107
153
|
- spec/vcr_setup.rb
|
108
154
|
homepage: https://github.com/tyrauber/census_api.git
|
109
155
|
licenses:
|
@@ -125,16 +171,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
171
|
version: '0'
|
126
172
|
requirements: []
|
127
173
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.6.14
|
129
175
|
signing_key:
|
130
176
|
specification_version: 4
|
131
177
|
summary: A Ruby Wrapper for the US Census Bureau API, providing the ability to query
|
132
178
|
both the SF1 and ACS5 datasets.
|
133
179
|
test_files:
|
134
|
-
- spec/api_key.sample.rb
|
135
180
|
- spec/census_api/client_spec.rb
|
136
|
-
- spec/census_api/
|
181
|
+
- spec/census_api/examples_spec.rb
|
137
182
|
- spec/census_api/request_spec.rb
|
138
183
|
- spec/spec_helper.rb
|
139
|
-
- spec/support/
|
184
|
+
- spec/support/data/census_2010_dec_sf1.rb
|
185
|
+
- spec/support/data/census_2012_acs_acs1.rb
|
186
|
+
- spec/support/data/census_2015_acs_acs5.rb
|
187
|
+
- spec/support/examples.rb
|
140
188
|
- spec/vcr_setup.rb
|