Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 309 lines (232 sloc) 13.109 kb
0008dfc @afeijoo Add deprecation note
afeijoo authored
1 Recalls API
fabf663 @eigenpath Initial commit
eigenpath authored
2 ==============
3
808a1a6 @afeijoo Update README.md
afeijoo authored
4 **Note:** The endpoint for our Recalls API was deprecated on March 27, 2015. The source code will remain here on Github, if you'd like to clone or fork it.
61cc658 @afeijoo Update README.md
afeijoo authored
5
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
6 ## Ruby
fabf663 @eigenpath Initial commit
eigenpath authored
7
14a1898 @loren [#61293244] Upgrade Ruby due to vulnerability when parsing JSON on v…
loren authored
8 This code is currently tested against [Ruby 2.1](http://www.ruby-lang.org/en/downloads/).
fabf663 @eigenpath Initial commit
eigenpath authored
9
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
10 ## Gems
fabf663 @eigenpath Initial commit
eigenpath authored
11
5908258 @afeijoo Update README.md
afeijoo authored
12 We use bundler to manage gems. You can install bundler and other required gems like this:
fabf663 @eigenpath Initial commit
eigenpath authored
13
14 gem install bundler
15 bundle install
16
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
17 ## Solr
fabf663 @eigenpath Initial commit
eigenpath authored
18
5eaa985 @afeijoo Update README.md
afeijoo authored
19 We're using [Solr](http://lucene.apache.org/solr/) for fulltext search. You can start/stop/reindex Solr like this:
fabf663 @eigenpath Initial commit
eigenpath authored
20
21 bundle exec rake sunspot:solr:start
22 bundle exec rake sunspot:solr:stop
23 bundle exec rake sunspot:solr:run
24 bundle exec rake sunspot:solr:reindex
25
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
26 ## Database
fabf663 @eigenpath Initial commit
eigenpath authored
27
61cc658 @afeijoo Update README.md
afeijoo authored
28 `database.yml` assumes you have a local database server up and running (preferably [MySQL](http://www.mysql.com/) >= 5.1.65), accessible from user 'root' with no password.
fabf663 @eigenpath Initial commit
eigenpath authored
29
30 Create and setup your development and test databases:
31
32 bundle exec rake db:setup
33 bundle exec rake db:setup RAILS_ENV=test
34
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
35 ## Seed data
fabf663 @eigenpath Initial commit
eigenpath authored
36
37 Populate recall data for your development database:
38
39 bundle exec rake usagov:recalls:import_cdc_data
40 bundle exec rake usagov:recalls:import_cpsc_data
41 bundle exec rake usagov:recalls:import_nhtsa_data
42
43 You need to run these tasks daily to receive the latest recalls data.
44
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
45 ## Running it
fabf663 @eigenpath Initial commit
eigenpath authored
46
47 Fire up a server and try it all out:
48
49 bundle exec rails s
50
51 <http://127.0.0.1:3000/search.json?query=stroller>
52
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
53 ## Parameters
61cc658 @afeijoo Update README.md
afeijoo authored
54
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
55 Seven generic parameters are accepted.
5908258 @afeijoo Update README.md
afeijoo authored
56
b2b77eb @afeijoo Add detailed parameters
afeijoo authored
57 1. query
58 1. organization
59 1. start_date
60 1. end_date
61 1. page
62 1. per_page
63 1. sort
64
65 There are additional parameters that are specific to food, product, and car safety recalls. None are required.
66
67 ### query
68
69 Attempts to extract as much "signal" as possible from the input text. Handles word variants, so a search on "choke" will find a recall categorized as a "choking" hazard.
70
71 ### organization
72
73 Specifies which agency issued the recall. Possible values are `CPSC`, `FDA`, `NHTSA`, or `USDA`.
74
75 Example (one agency): <http://127.0.0.1:3000/recalls/search.json?organization=nhtsa>
76
77 Example (multiple agencies): <http://127.0.0.1:3000/recalls/search.json?organization=fda+usda>
78
79 ### start_date
80
81 Specifies the start date of the recall.
82
83 Example: <http://127.0.0.1:3000/recalls/search.json?start_date=2012-01-01>
84
85 ### end_date
86
87 Specifies the end date of the recall.
88
89 Example: <http://127.0.0.1:3000/recalls/search.json?end_date=2012-12-31>
90
91 ### page
92
93 Specifies the pagination of search results. Possible values are `1` to `20`.
94
95 Example: <http://127.0.0.1:3000/recalls/search.json?page=3>
96
97 ### per_page
98
99 Specifies the number of search results for each page. Possible values are `1` to `50`.
100
101 Example: <http://127.0.0.1:3000/recalls/search.json?per_page=10>
102
103 ### sort
104
105 Results are sorted by relevance by default. Possible values are `rel` or `date`. Use 'sort=date' to sort results by date with the most recent listed first.
106
107 Example: <http://127.0.0.1:3000/recalls/search.json?sort=date>
108
109 ### food_type
110 Only for drug and food safety recalls. Possible values are `food` or `drug`.
111
112 Example: <http://127.0.0.1:3000/recalls/search.json?food_type=drug>
113
114 ### upc
115
116 Only for CPSC recalls. Specifies the UPC code when available. Not all products have UPC codes.
117
118 Example: <http://127.0.0.1:3000/recalls/search.json?upc=042666601627>
119
120 ### make, model, year, and code (only for NHTSA recalls)
121
122 * `make` specifies the make of the vehicle or equipment. Example: <http://127.0.0.1:3000/recalls/search?make=winnebago>
123 * `model` specifies the model of the vehicle or equipment. Example: <http://127.0.0.1:3000/recalls/search?model=ellipse>
124 * `year` specifies the year of the vehicle or equipment. Example: <http://127.0.0.1:3000/recalls/search?year=2010>
125 * `code` specifies the NHTSA code. Possible values are `E`, `V` [for vehicles], `I`, `T`, `C`, or `X`. Example: <http://127.0.0.1:3000/recalls/search?code=v>
126
127 <a name="data-sources"></a>
128
129 ## Data Sources
130
131 Data are normalized across (1) drug and food safety recalls from the [FDA](http://www.fda.gov), [UDSA FSIS](http://www.fsis.usda.gov/wps/portal/fsis/home), and [FoodSafety.gov](http://www.FoodSafety.gov); (2) car safety recalls from the [NHTSA](http://www.nhtsa.gov); and (3) product safety recalls from the [CPSC](http://www.cpsc.gov).
132
133 We encourage you to use the five original data sources directly or via [Recalls.gov](http://www.recalls.gov).
134
135 1. [FDA recalls, market withdrawals, and safety alerts](http://www.fda.gov/Safety/Recalls/default.htm)
136 2. [USDA FSIS recalls and public health alerts](http://www.fsis.usda.gov/wps/portal/fsis/topics/recalls-and-public-health-alerts)
137 3. [FoodSafety.gov recalls and alerts](http://www.foodsafety.gov/recalls)
138 4. [NHTSA recalls and defects](http://www.nhtsa.gov/Vehicle+Safety/Recalls+&+Defects)
139 5. [CPSC recalls](http://www.cpsc.gov/Recalls/)
140
141 <a name="what-it-returns"></a>
142
143 ## What it Returns
144
145 Below are three sample JSON responses for food, product, and car safety recalls.
146
147 ### Food Recalls
148
149 {
150 success: {
151 total: 82,
152 results: [
153 {
154 organization: "USDA",
155 recall_number: "1df0a5440b",
156 recall_date: "2011-05-14",
157 recall_url: "http://www.fsis.usda.gov/News_&_Events/Recall_037_2011_Release/index.asp",
158 description: "Rose & Shore Meat Co., a Vernon, Calif., establishment, is recalling approximately 15,900 pounds of ready-to-eat deli meat products that may be contaminated with Listeria monocytogenes.",
159 summary: "California Firm Recalls Deli Meat Products for Possible Listeria Contamination"
160 },
161 {
162 organization: "FDA",
163 recall_number: "51d9096a25",
164 recall_date: "2010-06-21",
165 recall_url: "http://www.fda.gov/Safety/Recalls/ucm216371.htm",
166 description: "Portland Shellfish Company, Inc. is expanding this voluntarily recall to include the Meat Without Feet private label food service (2 Lb bags), pack of ready to eat frozen lobster claw and knuckle meat. Lot 13310, as recent tests show the product has the potential to be contaminated with Listeria monocytogenes, an organism which can cause serious and sometimes fatal infections in young children, frail or elderly people, and others with weakened immune systems",
167 summary: "Portland Shellfish Company Expands Recall to Include Meat Without Feet Label, Lobster Claw and Knuckle Meat, because of Possible Health Risk"
168 }
169 ]
170 }}
171
172 ### Product Recalls
173
174 {"success":{
175 "total":2,
176 "results":[
177 {
178 "organization":"CPSC",
179 "recall_number":"12080",
180 "recall_date":"2012-01-05",
181 "recall_url":"http://www.cpsc.gov/cpscpub/prerel/prhtml12/12080.html",
182 "manufacturers":["Target"],
183 "product_types":["Lights & Accessories"],
184 "descriptions":["Target 6-pc. LED Flashlight Sets"],
185 "upcs":["490021010049"],
186 "hazards":["Fire & Fire-Related Burn"],
187 "countries":["China"]
188 },
189 {
190 "organization":"CPSC",
191 "recall_number":"12710",
192 "recall_date":"2012-01-05",
193 "recall_url":"http://www.cpsc.gov/cpscpub/prerel/prhtml12/12710.html",
194 "manufacturers":["Sterno"],
195 "product_types":["Candles & Candle Holders"],
196 "descriptions":["Sterno Bulk Pack 5 Hour Tea Lights"],
197 "upcs":null,
198 "hazards":["Fire & Fire-Related Burn"],
199 "countries":["Thailand"]
200 }
201 ]
202 }}
203
204 ### Car Recalls
205
206 {"success":{
207 "total":2,
208 "results":[
209 {
210 "organization":"NHTSA",
211 "recall_number":"12V579000",
212 "recall_date":"2012-12-18",
213 "recall_url":"http://www-odi.nhtsa.dot.gov/recalls/recallresults.cfm?start=1&SearchType=QuickSearch&rcl_ID=12V579000&summary=true&PrintVersion=YES",
214 "records":[
215 {
216 "component_description":"VISIBILITY/WIPER",
217 "make":"SPARTAN",
218 "manufacturer":"Spartan Chassis, Inc.",
219 "manufacturing_begin_date":"2012-10-01",
220 "manufacturing_end_date":"2012-10-31",
221 "model":"GLADIATOR",
222 "recalled_component_id":"000051813001317776000001349",
223 "year":2012
224 },
225 {
226 "component_description":"VISIBILITY/WIPER",
227 "make":"SPARTAN",
228 "manufacturer":"Spartan Chassis, Inc.",
229 "manufacturing_begin_date":"2012-10-01",
230 "manufacturing_end_date":"2012-10-31",
231 "model":"METROSTAR",
232 "recalled_component_id":"000051813001317777000001349",
233 "year":2012
234 }
235 ],
236 "manufacturer_campaign_number":"12016",
237 "component_description":"VISIBILITY/WIPER",
238 "manufacturer":"Spartan Chassis, Inc.",
239 "code":"V",
240 "potential_units_affected":"36",
241 "initiator":"MFR",
242 "report_date":"20121210",
243 "defect_summary":"Spartan Motors Chassis is recalling certain model year 2012-2013 Gladiator, Metro Star, Metro Star-X, and Force emergency rescue chassis cabs built between October 1, 2012, through October 31, 2012. The wiper motor shaft and the wiper arm shaft have diff",
244 "consequence_summary":"If the windshield wipers become inoperative, the driver could have reduced visibility, which may increase the risk of a crash. ",
245 "corrective_summary":"The remedy for this recall campaign is still under development. The manufacturer has not yet provided a notification schedule. Owners may contact Spartan at 1-800-543-5008.",
246 "notes":"Spartan's recall campaign number is 12016.Owners may also contact the National Highway Traffic Safety Administration Vehicle Safety Hotline at 1-888-327-4236 (TTY 1-800-424-9153), or go to www.safercar.gov.",
247 "recall_subject":"Windshield Wipers may become Inoperative"
248 },
249 {
250 "organization":"NHTSA",
251 "recall_number":"12V571000",
252 "recall_date":"2012-12-18",
253 "recall_url":"http://www-odi.nhtsa.dot.gov/recalls/recallresults.cfm?start=1&SearchType=QuickSearch&rcl_ID=12V571000&summary=true&PrintVersion=YES",
254 "records":[
255 {
256 "component_description":"FUEL SYSTEM, GASOLINE:DELIVERY:FUEL PUMP",
257 "make":"JAGUAR",
258 "manufacturer":"JAGUAR CARS LTD",
259 "manufacturing_begin_date":"2012-10-03",
260 "manufacturing_end_date":"2012-10-12",
261 "model":"XF",
262 "recalled_component_id":"000051654001723816000000152",
263 "year":2013
264 },
265 {
266 "component_description":"ELECTRICAL SYSTEM",
267 "make":"JAGUAR",
268 "manufacturer":"JAGUAR CARS LTD",
269 "manufacturing_begin_date":"2012-10-03",
270 "manufacturing_end_date":"2012-10-12",
271 "model":"XF",
272 "recalled_component_id":"000051654001723816000000200",
273 "year":2013
274 }
275 ],
276 "manufacturer_campaign_number":"J028",
277 "component_description":"ELECTRICAL SYSTEM",
278 "manufacturer":"Jaguar Land Rover North America, LLC",
279 "code":"V",
280 "potential_units_affected":"13",
281 "initiator":"MFR",
282 "report_date":"20121207",
283 "defect_summary":"Jaguar Land Rover is recalling certain model year 2013 XF vehicles manufactured October 3, 2012, through October 12, 2012 and equipped with a gasoline engine.",
284 "consequence_summary":"An engine stall without warning while driving may lead to a loss of motive power, a loss of power-assisted braking and a loss of power-assisted steering.",
285 "corrective_summary":"Jaguar Land Rover will notify owners, and dealers will install an additional wiring harness to the in-tank fuel pump, free of charge.",
286 "notes":"Jaguar's campaign recall number is J028.Owners may also contact the National Highway Traffic Safety Administration Vehicle Safety Hotline at 1-888-327-4236 (TTY 1-800-424-9153), or go to www.safercar.gov.",
287 "recall_subject":"Fuel Starvation may cause Vehicle Stall"
288 }
289 ]
290 }}
fabf663 @eigenpath Initial commit
eigenpath authored
291
5908258 @afeijoo Update README.md
afeijoo authored
292 ## Tests
fabf663 @eigenpath Initial commit
eigenpath authored
293
5908258 @afeijoo Update README.md
afeijoo authored
294 Tests require a Solr server to be spun up.
fabf663 @eigenpath Initial commit
eigenpath authored
295
296 bundle exec rake sunspot:solr:start RAILS_ENV=test
297
298 Make sure the tests run:
299
300 bundle exec rake spec
301
5908258 @afeijoo Update README.md
afeijoo authored
302 ## Code Coverage
fabf663 @eigenpath Initial commit
eigenpath authored
303
0008dfc @afeijoo Add deprecation note
afeijoo authored
304 Track test coverage of the codebase over time to help identify areas where better tests could be written and to see when poorly tested code got introduced.
fabf663 @eigenpath Initial commit
eigenpath authored
305
5908258 @afeijoo Update README.md
afeijoo authored
306 After running your tests, view the report by opening `coverage/rcov/index.html` in your browser.
fabf663 @eigenpath Initial commit
eigenpath authored
307
5908258 @afeijoo Update README.md
afeijoo authored
308 Click around on the files that have < 100% coverage to see what lines weren't exercised.
Something went wrong with that request. Please try again.