vinquery 0.3.9 → 0.4.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.
- data/lib/vinquery.rb +16 -6
 - data/lib/vinquery/version.rb +1 -1
 - metadata +2 -2
 
    
        data/lib/vinquery.rb
    CHANGED
    
    | 
         @@ -1,30 +1,38 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'net/http'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'nokogiri'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'Logger'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            class Vinquery
         
     | 
| 
       5 
6 
     | 
    
         
             
              attr_reader :attributes, :errors, :result
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
              def self.get(vin, options={})
         
     | 
| 
       8 
     | 
    
         
            -
                request = Vinquery.new(options[:url], options[:access_code], options[:report_type])
         
     | 
| 
      
 9 
     | 
    
         
            +
                request = Vinquery.new(options[:url], options[:access_code], options[:report_type], options[:logger])
         
     | 
| 
       9 
10 
     | 
    
         
             
                doc = request.fetch vin
         
     | 
| 
       10 
11 
     | 
    
         
             
                result = request.parse doc
         
     | 
| 
       11 
12 
     | 
    
         
             
                request
         
     | 
| 
       12 
13 
     | 
    
         
             
              end
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              def initialize(url, access_code, report_type)
         
     | 
| 
      
 15 
     | 
    
         
            +
              def initialize(url, access_code, report_type, log = Logger.new(nil))
         
     | 
| 
       15 
16 
     | 
    
         
             
                @url = url
         
     | 
| 
       16 
17 
     | 
    
         
             
                @access_code = access_code
         
     | 
| 
       17 
18 
     | 
    
         
             
                @report_type = report_type
         
     | 
| 
      
 19 
     | 
    
         
            +
                @log = log
         
     | 
| 
       18 
20 
     | 
    
         
             
              end
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
       20 
22 
     | 
    
         
             
              def fetch(vin)
         
     | 
| 
       21 
23 
     | 
    
         
             
                # use reducable=FALSE to get additional fields like fuel_type
         
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
      
 24 
     | 
    
         
            +
                # use vt=true to get vehicle_type
         
     | 
| 
      
 25 
     | 
    
         
            +
                # http://www.vinquery.com/ws_POQCXTYNO1D/xml_v100_QA7RTS8Y.aspx?accessCode=6958785b-ac0a-4303-8b28-40e14aa836ce&vin=YourVINToDecode&reportType=0&vt=true&gvwr=true
         
     | 
| 
      
 26 
     | 
    
         
            +
                @uri ||= "#{@url}?accessCode=#{@access_code}&reportType=#{@report_type}&reducable=FALSE&vt=TRUE&gvwr=TRUE"
         
     | 
| 
       23 
27 
     | 
    
         
             
                url_s = @uri + "&vin=#{vin}"
         
     | 
| 
      
 28 
     | 
    
         
            +
                @log.info{"Vinquery#fetch - uri: #{url_s}"}
         
     | 
| 
       24 
29 
     | 
    
         
             
                url = URI.parse(url_s)
         
     | 
| 
       25 
30 
     | 
    
         
             
                begin
         
     | 
| 
       26 
31 
     | 
    
         
             
                  @result = Net::HTTP.get url
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @log.debug{"Vinquery#fetch - result: #{@result}"}
         
     | 
| 
       27 
33 
     | 
    
         
             
                rescue Exception => e
         
     | 
| 
      
 34 
     | 
    
         
            +
                  @log.error{"ERROR - #{e.message}"}
         
     | 
| 
      
 35 
     | 
    
         
            +
                  @log.error{"ERROR - #{e.backtrace[0]}"}
         
     | 
| 
       28 
36 
     | 
    
         
             
                  xml = Nokogiri::XML::Builder.new do |doc|
         
     | 
| 
       29 
37 
     | 
    
         
             
                    doc.vin(:number => vin,:status => "FAILED") {
         
     | 
| 
       30 
38 
     | 
    
         
             
                      doc.message(:Key => "VinQuery unavailable", :Value => "Oops, it looks like our VIN decoder is unavailable at the moment. Please try again later.")
         
     | 
| 
         @@ -46,9 +54,10 @@ class Vinquery 
     | 
|
| 
       46 
54 
     | 
    
         
             
                doc.xpath('//vehicle[1]/item').each do |item|
         
     | 
| 
       47 
55 
     | 
    
         
             
                  attributes[item.attributes['key'].value.downcase.gsub('.', '').gsub(/ /, '_').to_sym] = item.attributes['value'].value
         
     | 
| 
       48 
56 
     | 
    
         
             
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
                @log.info{"Vinquery#set_attributes - number of attributes parsed: #{attributes.size}"}
         
     | 
| 
       49 
58 
     | 
    
         
             
                if attributes.size > 0
         
     | 
| 
       50 
     | 
    
         
            -
                   
     | 
| 
       51 
     | 
    
         
            -
                  attributes[:vin_key] = make_vin_key( 
     | 
| 
      
 59 
     | 
    
         
            +
                  vin = doc.css('vin').first.attributes['number'].value
         
     | 
| 
      
 60 
     | 
    
         
            +
                  attributes[:vin_key] = make_vin_key(vin)
         
     | 
| 
       52 
61 
     | 
    
         
             
                  attributes[:vendor_result] = doc.to_xml 
         
     | 
| 
       53 
62 
     | 
    
         
             
                end
         
     | 
| 
       54 
63 
     | 
    
         
             
                @attributes = attributes
         
     | 
| 
         @@ -57,7 +66,8 @@ class Vinquery 
     | 
|
| 
       57 
66 
     | 
    
         
             
              def set_errors_hash(doc)
         
     | 
| 
       58 
67 
     | 
    
         
             
                @errors = []
         
     | 
| 
       59 
68 
     | 
    
         
             
                @valid = doc.css('vin').first.attributes['status'].value == "SUCCESS"
         
     | 
| 
       60 
     | 
    
         
            -
                doc.css('message').each{|msg| @errors << {msg.attributes['key'].value => msg.attributes['value'].value} } unless  
     | 
| 
      
 69 
     | 
    
         
            +
                doc.css('message').each{|msg| @errors << {msg.attributes['key'].value => msg.attributes['value'].value} } unless valid?
         
     | 
| 
      
 70 
     | 
    
         
            +
                @errors.each{|msg| @log.error{"Vinquery#set_errors_hash - error: #{msg.to_s}"}} unless @errors.empty
         
     | 
| 
       61 
71 
     | 
    
         
             
              end
         
     | 
| 
       62 
72 
     | 
    
         | 
| 
       63 
73 
     | 
    
         
             
              def valid?
         
     | 
    
        data/lib/vinquery/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: vinquery
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.4.0
         
     | 
| 
       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-08- 
     | 
| 
      
 14 
     | 
    
         
            +
            date: 2011-08-04 00:00:00 Z
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       17 
17 
     | 
    
         
             
              name: nokogiri
         
     |