vindata 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: 5caaa6383d01ad194da2c36aaefbf6b46b04baa2
4
+ data.tar.gz: 25715bbbc39875b5ffb01e4cc0fd3c8277d5798b
5
+ SHA512:
6
+ metadata.gz: 17c2cbc787a1f06dfdca2a7cce43b01bb53ebd7415ff1aeb713945fb71d529c26c0dfcb72fa71225b649ac91397968639a1cd0d0d514d11a66f93f9e715f3f7f
7
+ data.tar.gz: f2916cb3732ebac11d3e52b2efbbb63708e1d4b7d57ea7f92f3a8803e66b8be62c40cfc4efa23925a8c67399d82b69be2eb00795b5f76f8e59103b4aa78d240c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .env*
16
+ .gs
17
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gem 'rest-client', '>= 1.7.2'
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ vindata
2
+ =======
data/lib/vindata.rb ADDED
@@ -0,0 +1,18 @@
1
+ # External gems
2
+ require 'rest_client'
3
+
4
+ # Internal files
5
+ require 'vindata/configuration'
6
+ require 'vindata/services'
7
+
8
+ module VinData
9
+ def self.details_by_vin vin
10
+ service = Services.get config[:service]
11
+ service.details_by_vin vin
12
+ end
13
+
14
+ def self.get_acv data
15
+ service = Services.get config[:service]
16
+ service.get_acv data
17
+ end
18
+ end
@@ -0,0 +1,74 @@
1
+ module VinData
2
+ def self.configure(options = nil, &block)
3
+ if !options.nil?
4
+ Configuration.instance.configure(options)
5
+ end
6
+ end
7
+
8
+ def self.config
9
+ Configuration.instance.data
10
+ end
11
+
12
+ class Configuration
13
+ include Singleton
14
+
15
+ OPTIONS = [
16
+ :service,
17
+ :api_key
18
+ ]
19
+
20
+ attr_accessor :data
21
+
22
+ def self.set_defaults
23
+ instance.set_defaults
24
+ end
25
+
26
+ OPTIONS.each do |o|
27
+ define_method o do
28
+ @data[o]
29
+ end
30
+ define_method "#{o}=" do |value|
31
+ @data[o] = value
32
+ end
33
+ end
34
+
35
+ def configure(options)
36
+ @data.rmerge!(options)
37
+ end
38
+
39
+ def initialize # :nodoc
40
+ @data = VinData::ConfigurationHash.new
41
+ set_defaults
42
+ end
43
+
44
+ def set_defaults
45
+
46
+ # geocoding options
47
+ @data[:service] = :edmunds # Default service to look up vins with
48
+ @data[:api_key] = nil # API key for geocoding service
49
+
50
+ end
51
+
52
+ instance_eval(OPTIONS.map do |option|
53
+ o = option.to_s
54
+ <<-EOS
55
+ def #{o}
56
+ instance.data[:#{o}]
57
+ end
58
+
59
+ def #{o}=(value)
60
+ instance.data[:#{o}] = value
61
+ end
62
+ EOS
63
+ end.join("\n\n"))
64
+
65
+ end
66
+
67
+ class ConfigurationHash < Hash
68
+ include HashRecursiveMerge
69
+
70
+ def method_missing(meth, *args, &block)
71
+ has_key?(meth) ? self[meth] : super
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,48 @@
1
+ module VinData
2
+ module Services
3
+ extend self
4
+
5
+ # Supported service list
6
+ def service_list
7
+ [
8
+ :edmunds
9
+ ]
10
+ end
11
+
12
+ def get(name)
13
+ @services = {} unless defined?(@services)
14
+ @services[name] = spawn(name) unless @services.include?(name)
15
+ @services[name]
16
+ end
17
+
18
+ def configuration
19
+ VinData.config
20
+ end
21
+
22
+ private # -----------------------------------------------------------------
23
+
24
+ ##
25
+ # Spawn a Lookup of the given name.
26
+ #
27
+ def spawn(name)
28
+ if service_list.include?(name)
29
+ VinData::Services.const_get(classify_name(name)).new
30
+ else
31
+ valids = service_list.map(&:inspect).join(", ")
32
+ raise ConfigurationError, "Please specify a valid service for VinData " +
33
+ "(#{name.inspect} is not one of: #{valids})."
34
+ end
35
+ end
36
+
37
+ ##
38
+ # Convert an "underscore" version of a name into a "class" version.
39
+ #
40
+ def classify_name(filename)
41
+ filename.to_s.split("_").map{ |i| i[0...1].upcase + i[1..-1] }.join
42
+ end
43
+ end
44
+ end
45
+
46
+ VinData::Services.service_list.each do |name|
47
+ require "vindata/services/#{name}"
48
+ end
@@ -0,0 +1,27 @@
1
+ module VinData
2
+ module Services
3
+ class Base
4
+ def initialize
5
+ @cache = nil
6
+ end
7
+
8
+ # Human readable name of this service
9
+ def name
10
+ fail
11
+ end
12
+
13
+ # Base URL of the API to query
14
+ def base_url(query)
15
+ fail
16
+ end
17
+
18
+ def details_by_vin vin
19
+ fail
20
+ end
21
+
22
+ def configuration
23
+ VinData.config
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,67 @@
1
+ require 'vindata/services/base'
2
+
3
+ module VinData::Services
4
+ class Edmunds < Base
5
+ def name
6
+ 'Edmunds'
7
+ end
8
+
9
+ def base_url
10
+ 'https://api.edmunds.com/api/vehicle/v2/'
11
+ end
12
+
13
+ def details_by_vin vin
14
+ # Lookup vehicle make/model/year by VIN
15
+ vinlookup = base_url + 'vins/'+vin
16
+ response = JSON.parse(RestClient.get vinlookup, {:params => {
17
+ fmt: 'json',
18
+ api_key: configuration[:api_key]
19
+ }})
20
+
21
+ # TODO: Check data validity here
22
+
23
+ return {
24
+ make: response['make']['niceName'],
25
+ model: response['model']['niceName'],
26
+ year: response['years'][0]['year']
27
+ }
28
+ end
29
+
30
+ # Required Data:
31
+ # :make
32
+ # :model
33
+ # :year
34
+ # :mileage
35
+ # :zip
36
+ def get_acv data
37
+ # TODO: Make sure all proper data was passed
38
+
39
+ # Get the style ID by vehicle make/model/year
40
+ stylelookup = base_url + data[:make] + '/' + data[:model] + '/' + data[:year].to_s + '/styles'
41
+ response = JSON.parse(RestClient.get stylelookup, {:params => {
42
+ fmt: 'json',
43
+ api_key: configuration[:api_key]
44
+ }})
45
+
46
+ # TODO: Check data validity here
47
+
48
+ acvlookup = 'https://api.edmunds.com/v1/api/tmv/tmvservice/calculateusedtmv'
49
+ response = JSON.parse(RestClient.get acvlookup, {:params => {
50
+ styleid: response['styles'][0]['id'],
51
+ condition: 'Clean',
52
+ mileage: data[:mileage],
53
+ zip: data[:zip],
54
+ fmt: 'json',
55
+ api_key: configuration[:api_key]
56
+ }})
57
+
58
+ # TODO: Check data validity here
59
+
60
+ return {
61
+ retail: response['tmv']['nationalBasePrice']['usedTmvRetail'],
62
+ private_party: response['tmv']['nationalBasePrice']['usedPrivateParty'],
63
+ trade_in: response['tmv']['nationalBasePrice']['usedTradeIn']
64
+ }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module VinData
2
+ VERSION = "0.0.1"
3
+ end
data/vindata.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'date'
3
+ require 'vindata/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'vindata'
7
+ s.version = VinData::VERSION
8
+ s.date = Date.today.to_s
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = %q{Query popular VIN databases to get vehicle information.}
11
+ s.description = %q{Library which queries vehicle databases such as Edmunds for publicly available vehicle information using VIN number}
12
+ s.authors = ["Roupen Mouradian"]
13
+ s.email = 'roupen@acdcorp.com'
14
+ s.files = `git ls-files`.split("\n")
15
+ s.homepage = 'https://github.com/orgs/acdcorp/'
16
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vindata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roupen Mouradian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Library which queries vehicle databases such as Edmunds for publicly
14
+ available vehicle information using VIN number
15
+ email: roupen@acdcorp.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - README.md
23
+ - lib/vindata.rb
24
+ - lib/vindata/configuration.rb
25
+ - lib/vindata/services.rb
26
+ - lib/vindata/services/base.rb
27
+ - lib/vindata/services/edmunds.rb
28
+ - lib/vindata/version.rb
29
+ - vindata.gemspec
30
+ homepage: https://github.com/orgs/acdcorp/
31
+ licenses: []
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.2.2
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Query popular VIN databases to get vehicle information.
53
+ test_files: []