Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit fabf663ad67db5a827a2bc930db3cbdced95d7e7 David Pranata committed Feb 7, 2013
Showing with 5,022 additions and 0 deletions.
  1. +24 −0 .gitignore
  2. +2 −0 .rspec
  3. +1 −0 .rvmrc
  4. +5 −0 .simplecov
  5. +4 −0 Capfile
  6. +22 −0 Gemfile
  7. +162 −0 Gemfile.lock
  8. +16 −0 LICENSE.md
  9. +100 −0 README.md
  10. +7 −0 Rakefile
  11. +39 −0 app/controllers/api/v1/recalls_controller.rb
  12. +2 −0 app/controllers/application_controller.rb
  13. 0 app/mailers/.gitkeep
  14. 0 app/models/.gitkeep
  15. +11 −0 app/models/auto_recall.rb
  16. +5 −0 app/models/food_recall.rb
  17. +301 −0 app/models/recall.rb
  18. +5 −0 app/models/recall_detail.rb
  19. +19 −0 app/views/api/v1/recalls/index.rss.builder
  20. +4 −0 config.ru
  21. +1 −0 config/airbrake.yml
  22. +69 −0 config/application.rb
  23. +6 −0 config/boot.rb
  24. +31 −0 config/database.yml
  25. +46 −0 config/deploy.rb
  26. +2 −0 config/deploy/production.rb
  27. +7 −0 config/environment.rb
  28. +37 −0 config/environments/development.rb
  29. +67 −0 config/environments/production.rb
  30. +37 −0 config/environments/test.rb
  31. +4 −0 config/initializers/airbrake.rb
  32. +7 −0 config/initializers/backtrace_silencers.rb
  33. +15 −0 config/initializers/inflections.rb
  34. +16 −0 config/initializers/log_subscriber.rb
  35. +5 −0 config/initializers/mime_types.rb
  36. +10 −0 config/initializers/rack/utils.rb
  37. +7 −0 config/initializers/secret_token.rb
  38. +8 −0 config/initializers/session_store.rb
  39. +13 −0 config/initializers/wrap_parameters.rb
  40. +5 −0 config/locales/en.yml
  41. +227 −0 config/newrelic.yml
  42. +15 −0 config/routes.rb
  43. +20 −0 config/sunspot.yml
  44. +13 −0 db/migrate/20121124051046_create_recalls.rb
  45. +12 −0 db/migrate/20121124051521_create_recall_details.rb
  46. +18 −0 db/migrate/20121124052232_create_auto_recalls.rb
  47. +14 −0 db/migrate/20121124052409_create_food_recalls.rb
  48. +65 −0 db/schema.rb
  49. +7 −0 db/seeds.rb
  50. 0 lib/assets/.gitkeep
  51. +10 −0 lib/constraints/api_constraint.rb
  52. +24 −0 lib/importers/cdc_data.rb
  53. +42 −0 lib/importers/cpsc_data.rb
  54. +50 −0 lib/importers/nhtsa_data.rb
  55. +5 −0 lib/query_preprocessor.rb
  56. +34 −0 lib/recall_search.rb
  57. 0 lib/tasks/.gitkeep
  58. +25 −0 lib/tasks/recalls.rake
  59. +26 −0 public/404.html
  60. +26 −0 public/422.html
  61. +25 −0 public/500.html
  62. 0 public/favicon.ico
  63. +5 −0 public/robots.txt
  64. +6 −0 script/rails
  65. +31 −0 solr/conf/admin-extra.html
  66. +36 −0 solr/conf/elevate.xml
  67. +246 −0 solr/conf/mapping-ISOLatin1Accent.txt
  68. +21 −0 solr/conf/protwords.txt
  69. +252 −0 solr/conf/schema.xml
  70. +24 −0 solr/conf/scripts.conf
  71. +934 −0 solr/conf/solrconfig.xml
  72. +2 −0 solr/conf/spellings.txt
  73. +58 −0 solr/conf/stopwords.txt
  74. +31 −0 solr/conf/synonyms.txt
  75. +681 −0 spec/api/v1/recalls_spec.rb
  76. +82 −0 spec/controllers/api/v1/recalls_controller_spec.rb
  77. +39 −0 spec/fixtures/rss/food_recalls.rss
  78. +4 −0 spec/fixtures/txt/nhtsa_recalls.txt
  79. +96 −0 spec/fixtures/xml/blah.xml
  80. +8 −0 spec/fixtures/xml/cpsc.xml
  81. +62 −0 spec/lib/importers/cdc_data_spec.rb
  82. +73 −0 spec/lib/importers/cpsc_data_spec.rb
  83. +90 −0 spec/lib/importers/nhtsa_data_spec.rb
  84. +19 −0 spec/lib/recall_search_spec.rb
  85. +50 −0 spec/models/auto_recall_spec.rb
  86. +26 −0 spec/models/food_recall_spec.rb
  87. +8 −0 spec/models/recall_detail_spec.rb
  88. +315 −0 spec/models/recall_spec.rb
  89. +43 −0 spec/spec_helper.rb
@@ -0,0 +1,24 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
+
+.DS_Store
+/.idea
+/coverage
+*.swp
+/log
+
+/solr/data
+/solr/pids
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--profile
1 .rvmrc
@@ -0,0 +1 @@
+rvm --create ruby-1.9.3-p327@recalls_api
@@ -0,0 +1,5 @@
+SimpleCov.start 'rails' do
+ add_filter '/vendor/'
+ add_filter '/.bundler/'
+ merge_timeout 1800
+end
@@ -0,0 +1,4 @@
+load 'deploy'
+# Uncomment if you are using Rails' asset pipeline
+ # load 'deploy/assets'
+load 'config/deploy' # remove this line to skip loading any of the default tasks
22 Gemfile
@@ -0,0 +1,22 @@
+source 'https://rubygems.org'
+
+gem 'rails', '3.2.11'
+gem 'rails-api'
+gem 'mysql2'
+gem 'thin'
+gem 'sunspot_rails'
+
+gem 'airbrake'
+gem 'newrelic_rpm'
+
+gem 'capistrano', group: :development
+
+group :development, :test do
+ gem 'rspec-rails'
+ gem 'sunspot_solr'
+end
+
+group :test do
+ gem 'shoulda-matchers'
+ gem 'simplecov', require: false
+end
@@ -0,0 +1,162 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (3.2.11)
+ actionpack (= 3.2.11)
+ mail (~> 2.4.4)
+ actionpack (3.2.11)
+ activemodel (= 3.2.11)
+ activesupport (= 3.2.11)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.4)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.2.1)
+ activemodel (3.2.11)
+ activesupport (= 3.2.11)
+ builder (~> 3.0.0)
+ activerecord (3.2.11)
+ activemodel (= 3.2.11)
+ activesupport (= 3.2.11)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.11)
+ activemodel (= 3.2.11)
+ activesupport (= 3.2.11)
+ activesupport (3.2.11)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ airbrake (3.1.7)
+ activesupport
+ builder
+ json
+ arel (3.0.2)
+ bourne (1.1.2)
+ mocha (= 0.10.5)
+ builder (3.0.4)
+ capistrano (2.14.1)
+ highline
+ net-scp (>= 1.0.0)
+ net-sftp (>= 2.0.0)
+ net-ssh (>= 2.0.14)
+ net-ssh-gateway (>= 1.1.0)
+ daemons (1.1.9)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ eventmachine (1.0.0)
+ highline (1.6.15)
+ hike (1.2.1)
+ i18n (0.6.1)
+ journey (1.0.4)
+ json (1.7.6)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ metaclass (0.0.1)
+ mime-types (1.20.1)
+ mocha (0.10.5)
+ metaclass (~> 0.0.1)
+ multi_json (1.5.0)
+ mysql2 (0.3.11)
+ net-scp (1.0.4)
+ net-ssh (>= 1.99.1)
+ net-sftp (2.0.5)
+ net-ssh (>= 2.0.9)
+ net-ssh (2.6.3)
+ net-ssh-gateway (1.1.0)
+ net-ssh (>= 1.99.1)
+ newrelic_rpm (3.5.6.46)
+ nokogiri (1.5.6)
+ polyglot (0.3.3)
+ pr_geohash (1.0.0)
+ rack (1.4.4)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.3)
+ rack
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ rails (3.2.11)
+ actionmailer (= 3.2.11)
+ actionpack (= 3.2.11)
+ activerecord (= 3.2.11)
+ activeresource (= 3.2.11)
+ activesupport (= 3.2.11)
+ bundler (~> 1.0)
+ railties (= 3.2.11)
+ rails-api (0.0.3)
+ actionpack (>= 3.2.6)
+ railties (>= 3.2.6)
+ tzinfo (~> 0.3.31)
+ railties (3.2.11)
+ actionpack (= 3.2.11)
+ activesupport (= 3.2.11)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (>= 0.14.6, < 2.0)
+ rake (10.0.3)
+ rdoc (3.12)
+ json (~> 1.4)
+ rsolr (1.0.8)
+ builder (>= 2.1.2)
+ rspec-core (2.12.2)
+ rspec-expectations (2.12.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.12.2)
+ rspec-rails (2.12.2)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 2.12.0)
+ rspec-expectations (~> 2.12.0)
+ rspec-mocks (~> 2.12.0)
+ shoulda-matchers (1.4.2)
+ activesupport (>= 3.0.0)
+ bourne (~> 1.1.2)
+ simplecov (0.7.1)
+ multi_json (~> 1.0)
+ simplecov-html (~> 0.7.1)
+ simplecov-html (0.7.1)
+ sprockets (2.2.2)
+ hike (~> 1.2)
+ multi_json (~> 1.0)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sunspot (1.3.3)
+ pr_geohash (~> 1.0)
+ rsolr (~> 1.0.7)
+ sunspot_rails (1.3.3)
+ nokogiri
+ sunspot (= 1.3.3)
+ sunspot_solr (1.3.3)
+ thin (1.5.0)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ thor (0.17.0)
+ tilt (1.3.3)
+ treetop (1.4.12)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.35)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ airbrake
+ capistrano
+ mysql2
+ newrelic_rpm
+ rails (= 3.2.11)
+ rails-api
+ rspec-rails
+ shoulda-matchers
+ simplecov
+ sunspot_rails
+ sunspot_solr
+ thin
@@ -0,0 +1,16 @@
+## License
+
+This project constitutes a work of the United States Government and is not subject to domestic copyright protection under 17 USC § 105.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
100 README.md
@@ -0,0 +1,100 @@
+Recalls API Server
+==============
+
+## Purpose
+
+The Recalls API Server provides access to searchable food, car, and product safety data and recalls. This data comes from three federal government sources: (1) food safety data from [FoodSafety.gov](http://www.foodsafety.gov); (2) car safety data from the [National Highway Traffic Safety Administration](http://www.nhtsa.gov/); and (3) product safety data from the [Consumer Product Safety Commission](http://www.cpsc.gov).
+
+You can see how this data is used when [searching for recalls on USA.gov](http://search.usa.gov/search/news?affiliate=usagov&channel=66).
+
+## Ruby
+
+You will need Ruby 1.9.3.
+
+## Gems
+
+We use bundler to manage gems.
+You can install bundler and other required gems like this:
+
+ gem install bundler
+ bundle install
+
+## Solr
+
+We're using Solr for fulltext search.
+
+You can start/stop/reindex Solr like this:
+
+ bundle exec rake sunspot:solr:start
+ bundle exec rake sunspot:solr:stop
+ bundle exec rake sunspot:solr:run
+ bundle exec rake sunspot:solr:reindex
+
+# Database
+
+The database.yml file assumes you have a local database server up and running (preferably MySQL >= 5.1.65), accessible from user 'root' with no password.
+
+Create and setup your development and test databases:
+
+ bundle exec rake db:setup
+ bundle exec rake db:setup RAILS_ENV=test
+
+# Seed data
+
+Populate recall data for your development database:
+
+ bundle exec rake usagov:recalls:import_cdc_data
+ bundle exec rake usagov:recalls:import_cpsc_data
+ bundle exec rake usagov:recalls:import_nhtsa_data
+
+You need to run these tasks daily to receive the latest recalls data.
+
+# Running it
+
+Fire up a server and try it all out:
+
+ bundle exec rails s
+
+<http://127.0.0.1:3000/search.json?query=stroller>
+
+For additional parameters, see <https://github.com/GSA-OCSIT/recalls_api/wiki/GET-search>
+
+For most recent recall in JSON, <http://127.0.0.1:3000/recent.json>
+
+For most recent recall in RSS, <http://127.0.0.1:3000/recent.rss>
+
+You can use browser extensions to view json data.
+
+For Chrome: <https://chrome.google.com/webstore/search/json?hl=en-US>
+
+For Firefox: <https://addons.mozilla.org/en-US/firefox/search/?q=json>
+
+# API Versioning
+
+We support API versioning with json format. The current version is v1.
+
+You can specify a a specific JSON version of recalls data like this:
+
+ curl -H 'Accept: application/vnd.usagov.recalls.v1' http://localhost:3000/search.json
+
+# Tests
+
+These require a Solr server to be spun up.
+
+ bundle exec rake sunspot:solr:start RAILS_ENV=test
+
+Make sure the tests run:
+
+ bundle exec rake spec
+
+# Code Coverage
+
+We track test coverage of the codebase over time, to help identify areas where we could write better tests and to see when poorly tested code got introduced.
+
+After running your tests, view the report by opening `coverage/rcov/index.html` in your favorite browser.
+
+You can click around on the files that have < 100% coverage to see what lines weren't exercised.
+
+#LICENSE
+
+This project is covered under the terms of the GNU General Public License, version 2 or later.
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+RecallsApi::Application.load_tasks
@@ -0,0 +1,39 @@
+class Api::V1::RecallsController < ApplicationController
+ include ActionController::MimeResponds
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
+
+ def index
+ @recalls = RecallSearch.recent(index_params)
+ respond_to do |format|
+ format.json { render json: @recalls }
+ format.rss { render rss: @recalls }
+ end
+ end
+
+ def search
+ respond_to do |format|
+ format.json { render json: RecallSearch.new(search_params) }
+ end
+ end
+
+ add_transaction_tracer :index
+ add_transaction_tracer :search
+
+ private
+
+ def index_params
+ params.slice(:page, :per_page)
+ end
+
+ def search_params
+ @search_params ||= params.slice(:query,
+ :organization,
+ :start_date, :end_date,
+ :food_type,
+ :upc,
+ :make, :model, :year, :code,
+ :page, :per_page,
+ :sort,
+ :hl)
+ end
+end
@@ -0,0 +1,2 @@
+class ApplicationController < ActionController::API
+end
No changes.
No changes.
Oops, something went wrong.

0 comments on commit fabf663

Please sign in to comment.