safer_bus_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1deaf4c103576f67cc498b9c7a786b4ac93a765
4
+ data.tar.gz: bfb84476d5245c2da30f3faef1fae0c3973d92ae
5
+ SHA512:
6
+ metadata.gz: 6119b904f8d31b489970d942da3a8e44ddf93b5b3b2cd2dbda19a84711b4348d624ae5860704b001d5e153e4b6353fa8bbdeff628081432579e5ff13c1ae35e7
7
+ data.tar.gz: eda7bc88a59b871d46e9987f83f71228d5d32748143aca7b248ee3a2e06f7783a9fc4adf51d9fee7626704fd7feab24c0b6fd59941362af75d24127a2f1f896e
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Bustr, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Overview
2
+
3
+ The Department of Transportation maintains the SaferBusAPI to provide safety information pertaining to transporation companies. Information related to this API and instructions for access the API can be found here: [https://mobile.fmcsa.dot.gov/developer/apidescription.page?cid=561](https://mobile.fmcsa.dot.gov/developer/apidescription.page?cid=561)
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+ ```ruby
10
+ gem 'safer_bus_api'
11
+ ```
12
+
13
+ Then run:
14
+ ```
15
+ bundle install
16
+ ```
17
+
18
+ ### Configuration
19
+
20
+ Set your api_token obtained from registering at [https://mobile.fmcsa.dot.gov/developer/UserAccountCreate.page](https://mobile.fmcsa.dot.gov/developer/UserAccountCreate.page)
21
+
22
+ Note: Once registered you will be emailed a registration token which you can then use to complete your registration and obtain an api token for your application
23
+
24
+
25
+ ```ruby
26
+ SaferBusApi.configure do |config|
27
+ config.api_token = 'your-token-here'
28
+ end
29
+ ```
30
+
31
+ ## Usage
32
+
33
+
34
+
35
+ ## Author
36
+ [Nathan Bertram](https://github.com/nathanbertram)
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Ensure tests are passing with `rspec`
43
+ 4. Commit your changes (`git commit -am 'Added some feature'`)
44
+ 5. Push to the branch (`git push origin my-new-feature`)
45
+ 6. Create new Pull Request
46
+ 7. You da man!
@@ -0,0 +1,43 @@
1
+ require "safer_bus_api/version"
2
+ require 'duly_noted/configuration'
3
+
4
+ module SaferBusApi
5
+ BASE_URL = 'https://mobile.fmcsa.dot.gov/saferbus/resource/v1/'
6
+
7
+ def configure
8
+ yield SaferBusApi::Configuration
9
+ end
10
+
11
+ def initialize(opts={})
12
+ @dot_number = opts[:dot_number]
13
+ @response = nil
14
+ end
15
+
16
+ def perform
17
+ raise 'Cannot perform SaferBusApi api-request with empty dot_number' if @dot_number.blank?
18
+ @response = SaferBusApi.query_by_dot_number(@dot_number)
19
+ end
20
+
21
+ def response
22
+ @response
23
+ end
24
+
25
+ def self.query_by_company_name(company_name)
26
+ fetch_data("carriers/#{company_name}")
27
+ end
28
+
29
+ def self.query_by_dot_number(dot_number)
30
+ fetch_data("carrier/#{dot_number}")
31
+ end
32
+
33
+ def self.query_by_mc_number(mc_number)
34
+ fetch_data("carrier/#{mc_number}")
35
+ end
36
+
37
+ def self.fetch_data(url_suffix)
38
+ url = "#{BASE_URL}#{url_suffix}.json?start=1&size=10&webKey=#{SaferBusApi::Configuration.api_token}"
39
+ response = Typhoeus.get(url)
40
+ return JSON.parse(response.body)
41
+ end
42
+
43
+ end
@@ -0,0 +1,32 @@
1
+ module SaferBusApi
2
+ module Configuration
3
+ module_function
4
+ @data = {:api_token => ''}
5
+
6
+ def update!(data)
7
+ data.each do |key, value|
8
+ self[key] = value
9
+ end
10
+ end
11
+
12
+ def [](key)
13
+ @data[key.to_sym]
14
+ end
15
+
16
+ def []=(key, value)
17
+ if value.class == Hash
18
+ @data[key.to_sym] = Config.new(value)
19
+ else
20
+ @data[key.to_sym] = value
21
+ end
22
+ end
23
+
24
+ def method_missing(sym, *args)
25
+ if sym.to_s =~ /(.+)=$/
26
+ self[$1] = args.first
27
+ else
28
+ self[sym]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ class SaferBusApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/safer_bus_api/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Nathan Bertram"]
6
+ gem.email = ["nbertram@gmail.com"]
7
+ gem.description = %q{The Department of Transportation maintains the SaferBusAPI to provide safety information pertaining to transporation companies.}
8
+ gem.summary = %q{A simple wrapper for the SaferBusAPI}
9
+ gem.homepage = "http://github.com/TanookiSuitLabs/safer_bus_api"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "safer_bus_api"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = SaferBusApi::VERSION
17
+ gem.license = 'MIT'
18
+
19
+ gem.add_development_dependency('rspec')
20
+ gem.add_dependency('typhoeus')
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: safer_bus_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Bertram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: typhoeus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: The Department of Transportation maintains the SaferBusAPI to provide
42
+ safety information pertaining to transporation companies.
43
+ email:
44
+ - nbertram@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - lib/safer_base_api.rb
52
+ - lib/safer_bus_api/configuration.rb
53
+ - lib/safer_bus_api/version.rb
54
+ - safer_bus_api.gemspec
55
+ homepage: http://github.com/TanookiSuitLabs/safer_bus_api
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.1.11
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: A simple wrapper for the SaferBusAPI
79
+ test_files: []