vinquery 0.3.0 → 0.3.5
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.
- data/Gemfile.lock +5 -5
- data/lib/vinquery.rb +10 -6
- data/lib/vinquery/version.rb +1 -1
- data/lib/vinquery/vin_exploder/adapter.rb +7 -1
- data/spec/vinquery_spec.rb +6 -4
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vinquery (0.
|
4
|
+
vinquery (0.3.5)
|
5
5
|
nokogiri (>= 1.4.4)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,18 +10,18 @@ GEM
|
|
10
10
|
addressable (2.2.6)
|
11
11
|
crack (0.1.8)
|
12
12
|
diff-lcs (1.1.2)
|
13
|
-
nokogiri (1.4.
|
13
|
+
nokogiri (1.4.6)
|
14
14
|
rspec (2.6.0)
|
15
15
|
rspec-core (~> 2.6.0)
|
16
16
|
rspec-expectations (~> 2.6.0)
|
17
17
|
rspec-mocks (~> 2.6.0)
|
18
|
-
rspec-core (2.6.
|
18
|
+
rspec-core (2.6.4)
|
19
19
|
rspec-expectations (2.6.0)
|
20
20
|
diff-lcs (~> 1.1.2)
|
21
21
|
rspec-mocks (2.6.0)
|
22
|
-
vin_exploder (0.
|
22
|
+
vin_exploder (0.3.0)
|
23
23
|
webmock (1.6.4)
|
24
|
-
addressable (
|
24
|
+
addressable (> 2.2.5, ~> 2.2)
|
25
25
|
crack (>= 0.1.7)
|
26
26
|
|
27
27
|
PLATFORMS
|
data/lib/vinquery.rb
CHANGED
@@ -5,7 +5,7 @@ class Vinquery
|
|
5
5
|
attr_reader :attributes, :errors, :result
|
6
6
|
|
7
7
|
def self.get(vin, options={})
|
8
|
-
request = Vinquery.new
|
8
|
+
request = Vinquery.new(options[:url], options[:access_code], options[:report_type])
|
9
9
|
doc = request.fetch vin
|
10
10
|
result = request.parse doc
|
11
11
|
request
|
@@ -19,8 +19,9 @@ class Vinquery
|
|
19
19
|
|
20
20
|
def fetch(vin)
|
21
21
|
# use reducable=FALSE to get additional fields like fuel_type
|
22
|
-
|
23
|
-
|
22
|
+
@uri ||= "#{@url}?accessCode=#{@access_code}&reportType=#{@report_type}&reducable=FALSE"
|
23
|
+
url_s = @uri + "&vin=#{vin}"
|
24
|
+
url = URI.parse(url_s)
|
24
25
|
begin
|
25
26
|
@result = Net::HTTP.get url
|
26
27
|
rescue Exception => e
|
@@ -41,11 +42,14 @@ class Vinquery
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def set_attributes(doc)
|
44
|
-
attributes = {
|
45
|
+
attributes = {}
|
45
46
|
doc.xpath('//vehicle[1]/item').each do |item|
|
46
|
-
attributes[item.attributes['key'].value.downcase.gsub(/ /, '_').
|
47
|
+
attributes[item.attributes['key'].value.downcase.gsub('.', '').gsub(/ /, '_').to_sym] = item.attributes['value'].value
|
48
|
+
end
|
49
|
+
if attributes.size > 0
|
50
|
+
attributes[:vin] = doc.css('vin').first.attributes['number'].value
|
51
|
+
attributes[:vendor_result] = doc.to_xml
|
47
52
|
end
|
48
|
-
|
49
53
|
@attributes = attributes
|
50
54
|
end
|
51
55
|
|
data/lib/vinquery/version.rb
CHANGED
@@ -8,6 +8,10 @@ module VinExploder
|
|
8
8
|
|
9
9
|
class VinqueryAdapter < AbstractAdapter
|
10
10
|
|
11
|
+
# Create new vinquery adapter
|
12
|
+
#
|
13
|
+
# == Parameters
|
14
|
+
# options:: access_code, report_type, url
|
11
15
|
def initialize(options)
|
12
16
|
super
|
13
17
|
end
|
@@ -26,7 +30,9 @@ module VinExploder
|
|
26
30
|
|
27
31
|
def normalize(vq_hash)
|
28
32
|
# fuel_type = vq_hash[:engine_type].match(/(GAS|DIESEL|HYBRID)/)[0]
|
29
|
-
|
33
|
+
# driveline_type = vq_hash[:driveline].match(/(FWD|4WD|2WD)/)[0]
|
34
|
+
door_number = vq_hash[:body_style].match(/(\d)-DR/)[1] unless vq_hash.empty?
|
35
|
+
{:year => vq_hash.delete(:model_year), :number_of_doors => door_number}.merge(vq_hash)
|
30
36
|
end
|
31
37
|
|
32
38
|
end
|
data/spec/vinquery_spec.rb
CHANGED
@@ -22,10 +22,10 @@ describe Vinquery do
|
|
22
22
|
@query.set_attributes(doc)
|
23
23
|
# @query.attributes.each_pair{|k,v| puts "#{k} - #{v}"}
|
24
24
|
@query.attributes[:body_style].should == "CREW CAB PICKUP 4-DR"
|
25
|
-
@query.attributes.count.should ==
|
25
|
+
@query.attributes.count.should == 171
|
26
26
|
end
|
27
27
|
|
28
|
-
it 'should recover from poorly or unexpected xml document' do
|
28
|
+
it 'should recover from poorly formatted or unexpected xml document' do
|
29
29
|
xml_s = '<?xml version="1.0"?>\\n<blah status="FAILED" number="vin"\\n'
|
30
30
|
doc = Nokogiri::HTML(xml_s)
|
31
31
|
@query.set_attributes(doc).should == {}
|
@@ -55,7 +55,7 @@ describe Vinquery do
|
|
55
55
|
doc = @query.fetch('')
|
56
56
|
doc.css('vin').first.attributes['status'].value.should == "FAILED"
|
57
57
|
doc.css('message').first.attributes['key'].value.should == "VinQuery unavailable"
|
58
|
-
doc.css('message').first.attributes['value'].value.should == "Oops, it looks like our VIN
|
58
|
+
doc.css('message').first.attributes['value'].value.should == "Oops, it looks like our VIN decoder is unavailable at the moment. Please try again later."
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -78,13 +78,15 @@ describe Vinquery do
|
|
78
78
|
query.valid?.should == true
|
79
79
|
query.errors.empty?.should == true
|
80
80
|
query.attributes.class.should equal(Hash)
|
81
|
+
query.attributes[:make].should == 'Dodge'
|
81
82
|
end
|
82
83
|
|
83
|
-
it 'should return an errors
|
84
|
+
it 'should return an errors array with an invalid vin number' do
|
84
85
|
res = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\r\n<VINquery Version="1.0.0" Report_Type="BASIC" Date="2/19/2011">\r\n <VIN Number="ABCDEFGHIJKLMNOPQ" Status="FAILED">\r\n <Message Key="5" Value="Invalid VIN number: This VIN number contains invalid letters: I,O or Q." />\r\n </VIN>\r\n</VINquery>'
|
85
86
|
stub_request(:any, /.*invalidvin.*/).to_return(:body => res, :status => 200, :headers => { 'Content-Length' => res.length})
|
86
87
|
results = Vinquery.get('BADVIN', {:url => 'http://www.invalidvin.com', :access_code => 'access_code', :report_type => 'report_type_2'})
|
87
88
|
results.valid?.should == false
|
89
|
+
results.errors.class.should == Array
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: vinquery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jake Mallory
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-06-
|
14
|
+
date: 2011-06-28 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: nokogiri
|