vehicle_data 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+
5
+ script:
6
+ - RAILS_ENV=test bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ ruby "1.9.3"
3
+ # Specify your gem's dependencies in vehicle_data.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jonathan Ballard
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ {<img src="https://travis-ci.org/iCreateJB/vehicle_data.png" />}[https://travis-ci.org/iCreateJB/vehicle_data]
2
+
3
+ # VehicleData
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'vehicle_data'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vehicle_data
18
+
19
+ ## Usage
20
+
21
+ VehicleData::Service.get_support_functions
22
+
23
+ {
24
+ "version"=>"0.2",
25
+ "functions"=>[
26
+ "makes.getAll",
27
+ "makes.getInfo",
28
+ "service.getSupportedFunctions",
29
+ "vehicles.getMakes",
30
+ "vehicles.getModels",
31
+ "vehicles.getTrims",
32
+ "vehicles.getStyleTrims",
33
+ "vehicles.getTransmissions",
34
+ "vin.decode"
35
+ ]
36
+ }
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,63 @@
1
+ require 'vehicle_data/version'
2
+ require 'typhoeus'
3
+ require 'cgi'
4
+ require 'base64'
5
+ require 'openssl'
6
+ require 'uri'
7
+ require 'json'
8
+
9
+
10
+ module VehicleData
11
+ class << self
12
+ attr_accessor :configuration
13
+ end
14
+
15
+ def self.configure
16
+ self.configuration ||= Configuration.new
17
+ yield(configuration)
18
+ end
19
+
20
+ class Base
21
+
22
+ attr_accessor :app_key, :secret, :data, :response, :request, :options
23
+
24
+ def initialize(options={})
25
+ @app_key = VehicleData.configuration.app_key
26
+ @secret = VehicleData.configuration.secret
27
+ @data = options.merge!({ :app => @app_key, :v => 0.2, :t => Time.now.to_i })
28
+ end
29
+
30
+ def send_request
31
+ response = Typhoeus.get("#{base_uri}/?#{build_params(@data)}&hash=#{calculate_signature}")
32
+ JSON.parse(response.body)
33
+ end
34
+
35
+ private
36
+ def calculate_signature
37
+ signature = Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), @secret, build_params(@data)))
38
+ URI.encode(signature)
39
+ end
40
+
41
+ def base_uri
42
+ "http://api.vehicledata.co"
43
+ end
44
+
45
+ def build_params(params)
46
+ params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
47
+ end
48
+ end
49
+
50
+ class Configuration
51
+ attr_accessor :app_key, :secret
52
+
53
+ def initialize
54
+ @app_key
55
+ @secret
56
+ end
57
+ end
58
+ end
59
+
60
+ require 'vehicle_data/makes'
61
+ require 'vehicle_data/service'
62
+ require 'vehicle_data/vehicles'
63
+ require 'vehicle_data/vin'
@@ -0,0 +1,13 @@
1
+ module VehicleData
2
+ class Makes < VehicleData::Base
3
+ class << self
4
+ def get_all
5
+ self.new({:f => 'makes.getAll'}).send_request
6
+ end
7
+
8
+ def get_info(make)
9
+ self.new({:f => 'makes.getInfo', :make => make}).send_request
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module VehicleData
2
+ class Service < VehicleData::Base
3
+
4
+ class << self
5
+ def get_support_functions()
6
+ self.new({:f => 'service.getSupportedFunctions'}).send_request
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module VehicleData
2
+ class Vehicles < VehicleData::Base
3
+ class << self
4
+ def get_makes(year)
5
+ self.new({:f => 'vehicles.getMakes', :year => year}).send_request
6
+ end
7
+
8
+ def get_models(year, make)
9
+ self.new({:f => 'vehicles.getModels', :year => year, :make => make}).send_request
10
+ end
11
+
12
+ def get_trims(year, make, model)
13
+ self.new({:f => 'vehicles.getTrims', :year => year, :make => make, :model => model}).send_request
14
+ end
15
+
16
+ def get_style_trims(options={})
17
+ options.merge({:f => 'vehicles.getStyleTrims'})
18
+ self.new(options).send_request
19
+ end
20
+
21
+ def get_transmissions(options={})
22
+ options.merge({:f => 'vehicles.getStyleTrims'})
23
+ self.new(options).send_request
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module VehicleData
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,9 @@
1
+ module VehicleData
2
+ class Vin < VehicleData::Base
3
+ class << self
4
+ def decode(vin)
5
+ self.new({:method => 'vin.decode'}).send_request
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe VehicleData::Makes do
4
+ let(:make){ "Mazda" }
5
+ subject{ VehicleData::Makes }
6
+
7
+ it { subject.should respond_to(:get_all) }
8
+ it { subject.should respond_to(:get_info) }
9
+
10
+ before(:each) do
11
+ api = stub("Typhoeus")
12
+ Typhoeus.stub(:get).and_return(api)
13
+ end
14
+
15
+ context ".get_all" do
16
+ it "should send a request to get all available makes" do
17
+ VehicleData::Makes.get_all
18
+ end
19
+ end
20
+
21
+ context ".get_info" do
22
+ it "should send a request to get a specific make info" do
23
+ VehicleData::Makes.get_info(make)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe VehicleData::Service do
4
+ subject{ VehicleData::Service }
5
+
6
+ it { subject.should respond_to(:get_support_functions) }
7
+
8
+ context ".get_support_functions" do
9
+ before(:each) do
10
+ api = stub("Typhoeus")
11
+ Typhoeus.stub(:get).and_return(api)
12
+ end
13
+
14
+ it "should return the available service functions" do
15
+ VehicleData::Service.get_support_functions
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe VehicleData::Vehicles do
4
+ let(:options){
5
+ {
6
+ :year => '',
7
+ :make => '',
8
+ :model => ''
9
+ }
10
+ }
11
+ subject{ VehicleData::Vehicles }
12
+
13
+ it { subject.should respond_to(:get_makes) }
14
+ it { subject.should respond_to(:get_models) }
15
+ it { subject.should respond_to(:get_trims) }
16
+ it { subject.should respond_to(:get_style_trims) }
17
+ it { subject.should respond_to(:get_transmissions) }
18
+
19
+ before(:each) do
20
+ api = stub("Typhoeus")
21
+ Typhoeus.stub(:get).and_return(api)
22
+ end
23
+
24
+ context ".get_makes" do
25
+ it "return all makes for a year" do
26
+ expect{ VehicleData::Vehicles.get_makes(options[:year]) }.to_not raise_error
27
+ end
28
+ end
29
+
30
+ context ".get_models" do
31
+ it "should return all models for a vehicle" do
32
+ expect{ VehicleData::Vehicles.get_models(options[:year], options[:model]) }.to_not raise_error
33
+ end
34
+ end
35
+
36
+ context ".get_trims" do
37
+ it "should return all trims for a vehicle" do
38
+ expect{ VehicleData::Vehicles.get_trims(options[:year], options[:make], options[:model]) }.to_not raise_error
39
+ end
40
+ end
41
+
42
+ context ".get_style_trims" do
43
+ it "should return all styles for a vehicle" do
44
+ expect{ VehicleData::Vehicles.get_style_trims(options) }.to_not raise_error
45
+ end
46
+ end
47
+
48
+ context ".get_transmissions" do
49
+ it "should return all transmissions for a vehicle" do
50
+ expect{ VehicleData::Vehicles.get_transmissions(options) }.to_not raise_error
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe VehicleData::Vin do
4
+ let(:vin){ SecureRandom.hex(10) }
5
+ subject{ VehicleData::Vin }
6
+
7
+ it { subject.should respond_to(:decode) }
8
+
9
+ context ".decode" do
10
+ before(:each) do
11
+ api = stub("Typhoeus")
12
+ Typhoeus.stub(:get).and_return(api)
13
+ end
14
+
15
+ it "should send a request to decode the vin" do
16
+ VehicleData::Vin.decode(vin)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'securerandom'
4
+ require 'vehicle_data' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ config.order = "random"
8
+ end
9
+
10
+ # Stub configuration ( This will naturally be held in a configuration file )
11
+ VehicleData.configure do |config|
12
+ config.app_key = "#{SecureRandom.hex(10)}"
13
+ config.secret = "#{SecureRandom.hex(15)}"
14
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe VehicleData::Base do
4
+ let(:options){
5
+ {
6
+
7
+ }
8
+ }
9
+ subject { VehicleData::Base.new(options) }
10
+
11
+ it { should respond_to(:send_request) }
12
+
13
+ it { subject.app_key.should_not be_nil }
14
+ it { subject.secret.should_not be_nil }
15
+
16
+ it { subject.send(:base_uri).should == "http://api.vehicledata.co" }
17
+ it { subject.send(:build_params, { :app => 'test' }).should == { :app => 'test' }.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&') }
18
+
19
+ context ".data" do
20
+ it { subject.data.include?(:app).should be_true }
21
+ it { subject.data.include?(:v).should be_true }
22
+ it { subject.data.include?(:t).should be_true }
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vehicle_data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vehicle_data"
8
+ spec.version = VehicleData::VERSION
9
+ spec.authors = ["Jonathan Ballard"]
10
+ spec.email = ["jonathan.ballard@gmail.com"]
11
+ spec.description = %q{Ruby Client for VehicleData.co API}
12
+ spec.summary = %q{Coming Soon}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+
26
+ spec.add_dependency "typhoeus"
27
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vehicle_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonathan Ballard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: typhoeus
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Ruby Client for VehicleData.co API
95
+ email:
96
+ - jonathan.ballard@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .travis.yml
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.rdoc
106
+ - Rakefile
107
+ - lib/vehicle_data.rb
108
+ - lib/vehicle_data/makes.rb
109
+ - lib/vehicle_data/service.rb
110
+ - lib/vehicle_data/vehicles.rb
111
+ - lib/vehicle_data/version.rb
112
+ - lib/vehicle_data/vin.rb
113
+ - spec/lib/vehicle_data/makes_spec.rb
114
+ - spec/lib/vehicle_data/service_spec.rb
115
+ - spec/lib/vehicle_data/vehicles_spec.rb
116
+ - spec/lib/vehicle_data/vin_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/vehicle_data_spec.rb
119
+ - vehicle_data.gemspec
120
+ homepage: ''
121
+ licenses:
122
+ - MIT
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.25
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Coming Soon
145
+ test_files:
146
+ - spec/lib/vehicle_data/makes_spec.rb
147
+ - spec/lib/vehicle_data/service_spec.rb
148
+ - spec/lib/vehicle_data/vehicles_spec.rb
149
+ - spec/lib/vehicle_data/vin_spec.rb
150
+ - spec/spec_helper.rb
151
+ - spec/vehicle_data_spec.rb