nhtsa 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c12fa1ee659dadc43e2595f2bcd1ead1b48c2735
4
+ data.tar.gz: 509f0e2c1e1cf3597dccd59ae2417ac8b488e1dc
5
+ SHA512:
6
+ metadata.gz: 6ba3d62940021e0c1db0c0e463e0453329da0592b6ac55c782e090f849ea2bd0423500b5d2e893ea34e149028dcd71372cbbbbd80aa1e8bdff112e94c202a271
7
+ data.tar.gz: a5c2619b111f4d240493d6d641b571534f8a6fe0d83dd724c79488f3f080e539ae6817ca1e3a2bda12622fe9c7462712b4ba97e3165aab5ca7fb02e5b2e0cd70
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nhtsa.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Mwaki Harri Magotswi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,115 @@
1
+ ## Safety Ratings ##
2
+
3
+ ### End Point ###
4
+ /SafetyRatings
5
+
6
+ ### Rating by Vehicle ID ###
7
+ /SafetyRatings/vehicleid/{VEHICLE_ID}
8
+
9
+ ### Verbose Methods ###
10
+ /SafetyRatings/modelyear/{MODEL_YR}
11
+ /SafetyRatings/modelyear/{MODEL_YR}/make/{MAKE}
12
+ /SafetyRatings/modelyear/{MODEL_YR}/make/{MAKE}/model/{MODEL}
13
+
14
+ ### Concise Methods ###
15
+ /SafetyRatings/{MODEL_YR}
16
+ /SafetyRatings/{MODEL_YR}/{MAKE}
17
+ /SafetyRatings/{MODEL_YR}/{MAKE}/{MODEL}
18
+
19
+
20
+ ## Recalls ##
21
+
22
+ ### End Point ###
23
+ /Recalls
24
+
25
+ ### Recalls by Brand ###
26
+ /Recalls/{PRODUCT_TYPE}/brand/{MAKE}
27
+ /Recalls/{PRODUCT_TYPE}/brand/{MAKE}/model/{MODEL}
28
+
29
+ ### Verbose Methods ###
30
+ /Recalls/{PRODUCT_TYPE}/modelyear/{MODEL_YR}
31
+ /Recalls/{PRODUCT_TYPE}/modelyear/{MODEL_YR}/make/{MAKE}
32
+ /Recalls/{PRODUCT_TYPE}/modelyear/{MODEL_YR}/make/{MAKE}/model/{MODEL}
33
+
34
+ ### Concise Methods ###
35
+ /Recalls/{PRODUCT_TYPE}
36
+ /Recalls/{PRODUCT_TYPE}/{MODEL_YR}
37
+ /Recalls/{PRODUCT_TYPE}/{MODEL_YR}/{MAKE}
38
+ /Recalls/{PRODUCT_TYPE}/{MODEL_YR}/{MAKE}/{MODEL}
39
+
40
+
41
+ ## Complaints ##
42
+
43
+ ### End Point ###
44
+ /Complaints
45
+
46
+ ### Complaints by Brand ###
47
+ /Complaints/{PRODUCT_TYPE}/brand/{MAKE}
48
+ /Complaints/{PRODUCT_TYPE}/brand/{MAKE}/model/{MODEL}
49
+
50
+ ### Verbose Methods ###
51
+ /Complaints/{PRODUCT_TYPE}/modelyear/{MODEL_YR}
52
+ /Complaints/{PRODUCT_TYPE}/modelyear/{MODEL_YR}/make/{MAKE}
53
+ /Complaints/{PRODUCT_TYPE}/modelyear/{MODEL_YR}/make/{MAKE}/model/{MODEL}
54
+
55
+ ### Concise Methods ###
56
+ /Complaints/{PRODUCT_TYPE}
57
+ /Complaints/{PRODUCT_TYPE}/{MODEL_YR}
58
+ /Complaints/{PRODUCT_TYPE}/{MODEL_YR}/{MAKE}
59
+ /Complaints/{PRODUCT_TYPE}/{MODEL_YR}/{MAKE}/{MODEL}
60
+
61
+
62
+ ## Civil Penalties ##
63
+
64
+ ### End Point ###
65
+ /CivilPenalties
66
+
67
+ ### Verbose Methods ###
68
+ /CivilPenalties/year/{FISCAL_YEAR}
69
+
70
+ ### Concise Methods ###
71
+ /CivilPenalties/{FISCAL_YEAR}
72
+
73
+
74
+ ## Child Seat Safety Inspection Station ##
75
+
76
+ ### End Point ###
77
+ /CSSIStation
78
+
79
+ ### CSSIS by State ###
80
+ /CSSIStation/state/{STATE}
81
+
82
+ /CSSIStation/state/{STATE}/page/{Page}
83
+
84
+ /CSSIStation/state/{STATE}/lang/{LANG}
85
+ /CSSIStation/state/{STATE}/lang/{LANG}/{SPECIALWEEK}
86
+ /CSSIStation/state/{STATE}/lang/{LANG}/page/{Page}
87
+ /CSSIStation/state/{STATE}/lang/{LANG}/{SPECIALWEEK}/page/{Page}
88
+
89
+ /CSSIStation/state/{STATE}/{SPECIALWEEK}
90
+ /CSSIStation/state/{STATE}/{SPECIALWEEK}/page/{Page}
91
+ /CSSIStation/state/{STATE}/{SPECIALWEEK}/lang/{LANG}
92
+ /CSSIStation/state/{STATE}/{SPECIALWEEK}/lang/{LANG}/page/{Page}
93
+
94
+ ### CSSIS by Zip Code ###
95
+ /CSSIStation/zip/{ZIP}
96
+ /CSSIStation/zip/{ZIP}/{CPSWEEK}
97
+ /CSSIStation/zip/{ZIP}/{CPSWEEK}/lang/{LANG}
98
+
99
+ /CSSIStation/zip/{ZIP}/lang/{LANG}
100
+ /CSSIStation/zip/{ZIP}/lang/{LANG}/{CPSWEEK}
101
+
102
+ /CSSIStation/zip/{ZIP}/miles/{MILES}
103
+ /CSSIStation/zip/{ZIP}/miles/{MILES}/{CPSWEEK}
104
+ /CSSIStation/zip/{ZIP}/miles/{MILES}/lang/{LANG}
105
+ /CSSIStation/zip/{ZIP}/miles/{MILES}/{CPSWEEK}/lang/{LANG}
106
+ /CSSIStation/zip/{ZIP}/miles/{MILES}/lang/{LANG}/{CPSWEEK}
107
+
108
+ ### CSSIS by Geo Location ###
109
+ /CSSIStation/geo/{LAT}/{LONG}
110
+ /CSSIStation/geo/{CPSWEEK}/lang/{LANG}/miles/{MILES}/{LAT}/{LONG}
111
+
112
+ /CSSIStation/geo/miles/{MILES}/{CPSWEEK}/{LAT}/{LONG}
113
+ /CSSIStation/geo/miles/{MILES}/lang/{LANG}/{LAT}/{LONG}
114
+
115
+ /CSSIStation/geo/lang/{LANG}/{CPSWEEK}/miles/{MILES}/{LAT}/{LONG}
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # NHTSA
2
+
3
+ This is a simple ruby gem to simply allow for easy access to The National Highway Traffic Safety Association dataset.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nhtsa'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nhtsa
20
+
21
+ ## Usage
22
+
23
+ Since the NHTSA generates several data sets....
24
+
25
+ ### New Car Assessment Program (NCAP) - 5 Star Safety Ratings
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nhtsa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nhtsa"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,74 @@
1
+ # NHTSA Child Safety Seat Inspection Station Locator
2
+ # http://webapi.nhtsa.gov/Default.aspx?CSSIStations/API/80
3
+
4
+ module Nhtsa
5
+ module ChildSafetySeatInspectionStationLocator
6
+
7
+ END_POINT = "/CSSIStation"
8
+ CPS_WEEK = "/cpsweek"
9
+ SPANISH = "/lang/spanish"
10
+
11
+ class GetByZipCode
12
+ def initialize(zip_code, filters = {:spanish => false, :cpsweek => false})
13
+ @zip_code = zip_code
14
+ @filters = filters
15
+ end
16
+
17
+ def url
18
+ if @filters[:spanish] && @filters[:cpsweek]
19
+ BASE_URI + END_POINT + "/zip/#{@zip_code}" + CPS_WEEK + SPANISH + DEFAULT_PARAMS
20
+ elsif @filters[:spanish]
21
+ BASE_URI + END_POINT + "/zip/#{@zip_code}" + SPANISH + DEFAULT_PARAMS
22
+ elsif @filters[:cpsweek]
23
+ BASE_URI + END_POINT + "/zip/#{@zip_code}" + CPS_WEEK + DEFAULT_PARAMS
24
+ else
25
+ BASE_URI + END_POINT + "/zip/#{@zip_code}" + DEFAULT_PARAMS
26
+ end
27
+ end
28
+
29
+ def inspection_stations
30
+ JSON.parse(open(url).read)["Results"]
31
+ end
32
+ end
33
+
34
+ class GetByState
35
+ def initialize(state_abbreviation, filters = {spanish: false, cpsweek: false})
36
+ @state_abbreviation = state_abbreviation
37
+ @filters = filters
38
+ end
39
+
40
+ def url
41
+ if @filters[:spanish] && @filters[:cpsweek]
42
+ BASE_URI + END_POINT + "/state/#{@state_abbreviation}" + CPS_WEEK + SPANISH + DEFAULT_PARAMS
43
+ elsif @filters[:spanish]
44
+ BASE_URI + END_POINT + "/state/#{@state_abbreviation}" + SPANISH + DEFAULT_PARAMS
45
+ elsif @filters[:cpsweek]
46
+ BASE_URI + END_POINT + "/state/#{@state_abbreviation}" + CPS_WEEK + DEFAULT_PARAMS
47
+ else
48
+ BASE_URI + END_POINT + "/state/#{@state_abbreviation}" + DEFAULT_PARAMS
49
+ end
50
+ end
51
+
52
+ def inspection_stations
53
+ JSON.parse(open(url).read)["Results"]
54
+ end
55
+ end
56
+
57
+ class GetByGeoLocation
58
+ def initialize(latitude, longitude, radius)
59
+ @latitude = latitude
60
+ @longitude = longitude
61
+ @radius = radius
62
+ end
63
+
64
+ def url
65
+ "http://webapi.nhtsa.gov/api/CSSIStation?lat=#{@latitude}&long=#{@longitude}&miles=#{@radius}&format=json"
66
+ end
67
+
68
+ def inspection_stations
69
+ JSON.parse(open(url).read)["Results"]
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,34 @@
1
+ # NHTSA Civil Penalty Payments
2
+ # http://webapi.nhtsa.gov/Default.aspx?CivilPenalties/API/251
3
+
4
+ module Nhtsa
5
+ module CivilPenalties
6
+
7
+ END_POINT = "/CivilPenalties"
8
+
9
+ class CivilPenalties
10
+ def url
11
+ BASE_URI + END_POINT + DEFAULT_PARAMS
12
+ end
13
+
14
+ def civil_penalties
15
+ JSON.parse(open(url).read)["Results"]
16
+ end
17
+ end
18
+
19
+ class CivilPenaltyByYear
20
+ def initialize(year)
21
+ @year = year
22
+ end
23
+
24
+ def url
25
+ BASE_URI + END_POINT + "/#{@year}" + DEFAULT_PARAMS
26
+ end
27
+
28
+ def civil_penalties_by_year
29
+ JSON.parse(open(url).read)["Results"]
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,79 @@
1
+ # http://webapi.nhtsa.gov/Default.aspx?Complaints/API/81
2
+ # NHTSA's Office of Defects Investigation (ODI) - Complaints
3
+
4
+ module Nhtsa
5
+ module Complaints
6
+
7
+ END_POINT = "/Complaints/vehicle"
8
+
9
+ class Years
10
+ def url
11
+ BASE_URI + END_POINT + DEFAULT_PARAMS
12
+ end
13
+
14
+ def years
15
+ JSON.parse(open(url).read)["Results"].collect{|year| year["ModelYear"]}
16
+ end
17
+ end
18
+
19
+ class Manufacturers
20
+ def initialize(year)
21
+ @year = year
22
+ end
23
+
24
+ def url
25
+ BASE_URI + END_POINT + "/#{@year}" + DEFAULT_PARAMS
26
+ end
27
+
28
+ def manufacturers
29
+ JSON.parse(open(url).read)["Results"].collect{|manufacturer| manufacturer["Make"]}
30
+ end
31
+ end
32
+
33
+ class Models
34
+ def initialize(year, manufacturer)
35
+ @year = year
36
+ @manufacturer = URI::encode(manufacturer)
37
+ end
38
+
39
+ def url
40
+ BASE_URI + END_POINT + "/#{@year}/#{@manufacturer}" + DEFAULT_PARAMS
41
+ end
42
+
43
+ def models
44
+ JSON.parse(open(url).read)["Results"].collect{|model| model["Model"]}
45
+ end
46
+ end
47
+
48
+ class Complaints
49
+ def initialize(year, manufacturer, model)
50
+ @year = year
51
+ @manufacturer = URI::encode(manufacturer)
52
+ @model = URI::encode(model)
53
+ end
54
+
55
+ def url
56
+ BASE_URI + END_POINT + "/#{@year}/#{@manufacturer}/#{@model}" + DEFAULT_PARAMS
57
+ end
58
+
59
+ def complaints
60
+ JSON.parse(open(url).read)["Results"]
61
+ end
62
+ end
63
+
64
+ class ComplaintsByOdiNumber
65
+ def initialize(odi_number)
66
+ @odi_number = odi_number
67
+ end
68
+
69
+ def url
70
+ BASE_URI + END_POINT + "/odinumber/#{@odi_number}" + DEFAULT_PARAMS
71
+ end
72
+
73
+ def complaints_by_odi_number
74
+ JSON.parse(open(url).read)["Results"]
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,78 @@
1
+ # http://webapi.nhtsa.gov/api/Recalls/vehicle?format=json
2
+
3
+ module Nhtsa
4
+ module Recalls
5
+
6
+ END_POINT = "/Recalls/vehicle"
7
+
8
+ class Years
9
+ def url
10
+ BASE_URI + END_POINT + DEFAULT_PARAMS
11
+ end
12
+
13
+ def years
14
+ JSON.parse(open(url).read)["Results"].collect{|year| year["ModelYear"]}
15
+ end
16
+ end
17
+
18
+ class Manufacturers
19
+ def initialize(year)
20
+ @year = year
21
+ end
22
+
23
+ def url
24
+ BASE_URI + END_POINT + "/#{@year}" + DEFAULT_PARAMS
25
+ end
26
+
27
+ def manufacturers
28
+ JSON.parse(open(url).read)["Results"].collect{|manufacturer| manufacturer["Make"]}
29
+ end
30
+ end
31
+
32
+ class Models
33
+ def initialize(year, manufacturer)
34
+ @year = year
35
+ @manufacturer = URI::encode(manufacturer)
36
+ end
37
+
38
+ def url
39
+ BASE_URI + END_POINT + "/#{@year}/#{@manufacturer}" + DEFAULT_PARAMS
40
+ end
41
+
42
+ def models
43
+ JSON.parse(open(url).read)["Results"].collect{|model| model["Model"]}
44
+ end
45
+ end
46
+
47
+ class Recalls
48
+ def initialize(year, manufacturer, model)
49
+ @year = year
50
+ @manufacturer = URI::encode(manufacturer)
51
+ @model = URI::encode(model)
52
+ end
53
+
54
+ def url
55
+ BASE_URI + END_POINT + "/#{@year}/#{@manufacturer}/#{@model}" + DEFAULT_PARAMS
56
+ end
57
+
58
+ def recalls
59
+ JSON.parse(open(url).read)["Results"]
60
+ end
61
+ end
62
+
63
+ class CampaignRecalls
64
+ def initialize(campaign_number)
65
+ @campaign_number = campaign_number
66
+ end
67
+
68
+ def url
69
+ BASE_URI + END_POINT + "/CampaignNumber/#{@campaign_number}" + DEFAULT_PARAMS
70
+ end
71
+
72
+ def campaign_recalls
73
+ JSON.parse(open(url).read)["Results"]
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,92 @@
1
+ # New Car Assessment Program (NCAP) - 5 Star Safety Ratings
2
+ # http://webapi.nhtsa.gov/Default.aspx?SafetyRatings/API/5
3
+
4
+ module Nhtsa
5
+ module SafetyRatings
6
+
7
+ END_POINT = "/SafetyRatings"
8
+
9
+ class Years
10
+ def url
11
+ BASE_URI + END_POINT + DEFAULT_PARAMS
12
+ end
13
+
14
+ def years
15
+ JSON.parse(open(url).read)["Results"].collect{|year| year["ModelYear"]}
16
+ end
17
+ end
18
+
19
+ class Manufacturers
20
+ def initialize(year)
21
+ @year = year
22
+ end
23
+
24
+ def url
25
+ BASE_URI + END_POINT + "/#{@year}" + DEFAULT_PARAMS
26
+ end
27
+
28
+ def manufacturers
29
+ JSON.parse(open(url).read)["Results"].collect{|manufacturer| manufacturer["Make"]}
30
+ end
31
+ end
32
+
33
+ class Models
34
+ def initialize(year, manufacturer)
35
+ @year = year
36
+ @manufacturer = URI::encode(manufacturer)
37
+ end
38
+
39
+ def url
40
+ BASE_URI + END_POINT + "/#{@year}/#{@manufacturer}" + DEFAULT_PARAMS
41
+ end
42
+
43
+ def models
44
+ JSON.parse(open(url).read)["Results"].collect{|model| model["Model"]}
45
+ end
46
+ end
47
+
48
+ class Trims
49
+ def initialize(year, manufacturer, model)
50
+ @year = year
51
+ @manufacturer = URI::encode(manufacturer)
52
+ @model = URI::encode(model)
53
+ end
54
+
55
+ def url
56
+ BASE_URI + END_POINT + "/#{@year}/#{@manufacturer}/#{@model}" + DEFAULT_PARAMS
57
+ end
58
+
59
+ def trims
60
+ JSON.parse(open(url).read)["Results"].collect do |trim|
61
+ {
62
+ :description => trim["VehicleDescription"],
63
+ :id => trim["VehicleId"]
64
+ }
65
+ end
66
+ end
67
+
68
+ def trim_descriptions
69
+ JSON.parse(open(url).read)["Results"].collect{|trim| trim["VehicleDescription"]}
70
+ end
71
+
72
+ def trim_ids
73
+ JSON.parse(open(url).read)["Results"].collect{|trim| trim["VehicleId"]}
74
+ end
75
+ end
76
+
77
+ class Ratings
78
+ def initialize(vehicle_id)
79
+ @vehicle_id = vehicle_id
80
+ end
81
+
82
+ def url
83
+ BASE_URI + END_POINT + "/VehicleId/#{@vehicle_id}" + DEFAULT_PARAMS
84
+ end
85
+
86
+ def ratings
87
+ JSON.parse(open(url).read)["Results"].first
88
+ end
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module Nhtsa
2
+ VERSION = "0.1.0"
3
+ end
data/lib/nhtsa.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "nhtsa/version"
2
+ require "nhtsa/safety_ratings"
3
+ require "nhtsa/recalls"
4
+ require "nhtsa/complaints"
5
+ require "nhtsa/civil_penalties"
6
+ require "nhtsa/child_safety_seat_inspection_station_locator"
7
+
8
+ module Nhtsa
9
+ require 'json'
10
+ require 'open-uri'
11
+
12
+ BASE_URI = "http://webapi.nhtsa.gov/api"
13
+ DEFAULT_PARAMS = "?format=json"
14
+ end
data/nhtsa.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nhtsa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nhtsa"
8
+ spec.version = Nhtsa::VERSION
9
+ spec.authors = ["Mwaki Harri Magotswi"]
10
+ spec.email = ["magotswi@gmail.com"]
11
+
12
+ spec.summary = %q{A simple ruby gem to access NHTSA data.}
13
+ spec.description = %q{NHTSA offers data on safety ratings, recalls, complaints, civil penalty payments, and child safety seat inspection station locations through their various web APIs. The main motivation for this gem is to access the NHTSA WebAPIs and make the data available to use for any ruby application.}
14
+ spec.homepage = "https://github.com/omundu/nhtsa"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "fakeweb"
26
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nhtsa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mwaki Harri Magotswi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakeweb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: NHTSA offers data on safety ratings, recalls, complaints, civil penalty
70
+ payments, and child safety seat inspection station locations through their various
71
+ web APIs. The main motivation for this gem is to access the NHTSA WebAPIs and make
72
+ the data available to use for any ruby application.
73
+ email:
74
+ - magotswi@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - NHTSA_API_Endpoints.md
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/nhtsa.rb
89
+ - lib/nhtsa/child_safety_seat_inspection_station_locator.rb
90
+ - lib/nhtsa/civil_penalties.rb
91
+ - lib/nhtsa/complaints.rb
92
+ - lib/nhtsa/recalls.rb
93
+ - lib/nhtsa/safety_ratings.rb
94
+ - lib/nhtsa/version.rb
95
+ - nhtsa.gemspec
96
+ homepage: https://github.com/omundu/nhtsa
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.8
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A simple ruby gem to access NHTSA data.
120
+ test_files: []