vin_query 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64d3c8bae2cabbbfdab43496ded9b926c8fdd66d
4
- data.tar.gz: 01c4cfaab126e3059daa3535623573cfe9460f17
3
+ metadata.gz: e009eb9349dbfd08405cb85579c97ecd30bc0e07
4
+ data.tar.gz: 2ac76344b14f533acfa5bf73762580d8e8a056cf
5
5
  SHA512:
6
- metadata.gz: 077cf12d76ba87dc062d4e48d1354f132de7d5cd6289848ca71c6e4b22ff2ca389af0ca953e9b9d36e68dfb3d571f46bd785a2adfaf48e15b3eda00a2b438985
7
- data.tar.gz: 7c7cd37b3b7cb3253dc677c9af0243faad5825b188a7753a0002bf9b8e32f6ed452504eebddebee724bb4d9a31664d1a2b9c51c1140a58091f03534dfc0ba6f5
6
+ metadata.gz: 19a2ab043fce4cd50b2239d2892297c00d3cb18986d82da20cbf3d05c42aaec258d6a3f2f61c3cb3b4fe9a7c937cbca719e9a4c963c2b89232b7873cafd8b9cd
7
+ data.tar.gz: 83761294c6cd620c739a6262eaf7769feb10ed2aaafacb9cb7551e79b0c34fb27420dce2e1c47b7766ab4b005cb30e631dd2fed8786220ba718cb0e226cdb5ba
data/.travis.yml CHANGED
@@ -1,11 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 1.9.3
5
- - 1.9.2
6
- - jruby-18mode
7
- - jruby-19mode
8
- - rbx-18mode
9
- - rbx-19mode
10
- - 1.8.7
11
- - ree
3
+ - 2.0.0-p648
4
+ - 2.1.10
5
+ - 2.2.6
6
+ - 2.3.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v1.1.0 (2016-12-12)
2
+
3
+ - Add configuration block pattern
4
+ - Dropped testing support for rbx, jruby and MRI 1.9
5
+
1
6
  ## v1.0.2 (2013-03-15)
2
7
 
3
8
  - Tested against Ruby 2.0
data/Gemfile CHANGED
@@ -1,5 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
2
  gemspec
4
-
5
- gem 'rake'
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Jonathan Underwood
1
+ Copyright (c) 2014 Jonathan Underwood
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -26,17 +26,35 @@ Or install it yourself as:
26
26
 
27
27
  Pass in the URL and access code provided by vinquery.com as well as the report type you want (defaults to report type '2' -- the extended report type).
28
28
 
29
- Note, A VinQuery::Query class has an array of trim levels. This is due to the VinQuery service returning a array of possible trim levels for certain makes/models.
29
+ Note, A `VinQuery::Query` class has an array of trim levels. This is due to the VinQuery service returning a array of possible trim levels for certain makes/models.
30
30
 
31
31
  ```ruby
32
- query = VinQuery.get('1C3CC4FB8AN236750', {
33
- :url => 'vinquery-url-here',
34
- :access_code => 'access-code-here',
35
- :report_type => 'report-type-here' })
32
+ query = VinQuery.get('1C3CC4FB8AN236750',
33
+ url: 'vinquery-url-here',
34
+ access_code: 'access-code-here',
35
+ report_type: 'report-type-here')
36
36
 
37
- query.valid? # => true
37
+ query.valid? # => true
38
+ ```
39
+
40
+ ### Configuration
41
+
42
+ It also accepts a configuration block to streamline gets.
43
+
44
+ ```ruby
45
+ VinQuery.configure do |config|
46
+ config.url = 'vinquery-url-here'
47
+ config.access_code = 'access-code-here'
48
+ config.report_type = 2
49
+ end
50
+
51
+ query = VinQuery.get('1C3CC4FB8AN236750')
52
+ query.valid? # => true
53
+ ```
38
54
 
39
- # Note, trim_levels will always be an array. Empty, or otherwise.
55
+ _Note, `trim_levels` will always be an array. Empty, or otherwise._
56
+
57
+ ```
40
58
  vehicle = query.trim_levels.first
41
59
 
42
60
  vehicle.attributes[:make] # => Chrysler
data/lib/vin_query.rb CHANGED
@@ -1,6 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'vin_query/version'
3
2
 
3
+ require 'vin_query/configuration'
4
4
  require 'vin_query/exceptions'
5
5
  require 'vin_query/trim_level'
6
6
  require 'vin_query/query'
@@ -0,0 +1,28 @@
1
+ module VinQuery
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration)
9
+ end
10
+
11
+ def self.reset
12
+ self.configuration = Configuration.new
13
+ end
14
+
15
+ class Configuration
16
+ attr_accessor :url, :access_code, :report_type
17
+
18
+ def initialize
19
+ @report_type = 2
20
+ end
21
+
22
+ def merge_options(options={})
23
+ options.each do |k, v|
24
+ self.send("#{k}=", v)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  module VinQuery
4
2
  class Error < StandardError
5
3
  end
@@ -1,18 +1,15 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'net/http'
3
2
  require 'nokogiri'
4
3
 
5
4
  module VinQuery
6
5
  class Query
7
- attr_reader :url, :trim_levels
6
+ attr_reader :vin, :url, :trim_levels
8
7
 
9
8
  def initialize(vin, options={})
10
- url = options[:url]
11
- access_code = options[:access_code]
12
- report_type = 2 || options[:report_type]
13
-
9
+ VinQuery.configuration.merge_options(options)
10
+ @vin = vin
14
11
  @trim_levels = []
15
- @url = "#{url}?accessCode=#{access_code}&vin=#{vin}&reportType=#{report_type}"
12
+ build_url
16
13
  end
17
14
 
18
15
  def valid?
@@ -20,15 +17,11 @@ module VinQuery
20
17
  end
21
18
 
22
19
  def validate(xml)
23
- doc = Nokogiri::XML xml
24
-
25
- if doc.xpath('//VINquery/VIN').size == 0
26
- raise ValidationError
27
- end
20
+ doc = Nokogiri::XML(xml)
21
+ raise ValidationError if doc.xpath('//VINquery/VIN').size == 0
28
22
 
29
- vin = doc.xpath('//VINquery/VIN').first
30
-
31
- if vin.attributes['Status'].to_s == 'SUCCESS'
23
+ results_vin = doc.xpath('//VINquery/VIN').first
24
+ if results_vin.attributes['Status'].to_s == 'SUCCESS'
32
25
  @valid = true
33
26
  else
34
27
  @valid = false
@@ -36,13 +29,10 @@ module VinQuery
36
29
  end
37
30
 
38
31
  def parse(xml)
39
- doc = Nokogiri::XML xml
40
- vin = doc.xpath('//VINquery/VIN').first
41
-
42
- if doc.xpath('//VINquery/VIN/Vehicle').size == 0
43
- raise ParseError
44
- end
32
+ doc = Nokogiri::XML(xml)
33
+ raise ParseError if doc.xpath('//VINquery/VIN/Vehicle').size == 0
45
34
 
35
+ results_vin = doc.xpath('//VINquery/VIN').first
46
36
  doc.xpath('//VINquery/VIN/Vehicle').each do |v|
47
37
  vehicle = {}
48
38
 
@@ -62,20 +52,25 @@ module VinQuery
62
52
  end
63
53
  end
64
54
 
65
- @trim_levels.push(VinQuery::TrimLevel.new(vin.attributes['Number'].to_s, vehicle))
55
+ @trim_levels.push(VinQuery::TrimLevel.new(results_vin.attributes['Number'].to_s, vehicle))
66
56
  end
67
57
  end
68
58
 
69
59
  def get
70
- xml = fetch @url
71
-
72
- if validate xml
73
- parse xml
74
- end
60
+ xml = fetch(@url)
61
+ parse(xml) if validate(xml)
75
62
  end
76
63
 
77
64
  private
78
65
 
66
+ def build_url
67
+ url = VinQuery.configuration.url
68
+ access_code = VinQuery.configuration.access_code
69
+ report_type = VinQuery.configuration.report_type
70
+
71
+ @url = "#{url}?accessCode=#{access_code}&vin=#{vin}&reportType=#{report_type}"
72
+ end
73
+
79
74
  def fetch(url)
80
75
  Net::HTTP.get(URI.parse(url))
81
76
  end
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  module VinQuery
4
2
  class TrimLevel
5
3
  attr_reader :attributes, :trim_level, :vin
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  module VinQuery
4
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
5
3
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe VinQuery::Configuration do
4
+ before do
5
+ VinQuery.configure do |config|
6
+ config.url = 'http://www.vinquery.com/asdf/asdf.aspx'
7
+ config.access_code = 'asdf1234-asdf1234-asdf1234'
8
+ end
9
+ end
10
+
11
+ it 'respects set values in a config block' do
12
+ expect(VinQuery.configuration.url).to eq 'http://www.vinquery.com/asdf/asdf.aspx'
13
+ expect(VinQuery.configuration.access_code).to eq 'asdf1234-asdf1234-asdf1234'
14
+ end
15
+
16
+ it 'has a default report type' do
17
+ expect(VinQuery.configuration.report_type).to eq 2
18
+ end
19
+
20
+ context 'when manually given options' do
21
+ it 'overrides default configuration settings' do
22
+ VinQuery.configuration.merge_options(report_type: 3)
23
+ expect(VinQuery.configuration.report_type).to eq 3
24
+ end
25
+
26
+ it 'overrides previously set configuration settings' do
27
+ VinQuery.configuration.merge_options(access_code: '1234')
28
+ expect(VinQuery.configuration.access_code).to eq '1234'
29
+ end
30
+ end
31
+
32
+ after { VinQuery.reset }
33
+ end
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'spec_helper'
3
2
 
4
3
  describe VinQuery::Query do
@@ -39,7 +38,7 @@ describe VinQuery::Query do
39
38
 
40
39
  describe '#parse' do
41
40
  context 'when a single trim level is returned' do
42
- before(:each) { client.parse xml_single }
41
+ before { client.parse xml_single }
43
42
 
44
43
  it 'populates an array of trim levels with 1 trim level' do
45
44
  expect(client.trim_levels.size).to be 1
@@ -63,7 +62,7 @@ describe VinQuery::Query do
63
62
  end
64
63
 
65
64
  context 'when multiple trim levels are returned' do
66
- before(:each) { client.parse xml_multi }
65
+ before { client.parse xml_multi }
67
66
 
68
67
  it 'populates an array of trim levels with the number of trim levels' do
69
68
  expect(client.trim_levels.size).to be 4
@@ -95,8 +94,8 @@ describe VinQuery::Query do
95
94
 
96
95
  describe '#get' do
97
96
  context 'success response' do
98
- before(:each) do
99
- client.stub(:fetch).and_return xml_multi
97
+ before do
98
+ allow(client).to receive(:fetch).and_return(xml_multi)
100
99
  client.get
101
100
  end
102
101
 
@@ -110,8 +109,8 @@ describe VinQuery::Query do
110
109
  end
111
110
 
112
111
  context 'error response' do
113
- before(:each) do
114
- client.stub(:fetch).and_return xml_error
112
+ before do
113
+ allow(client).to receive(:fetch).and_return(xml_error)
115
114
  client.get
116
115
  end
117
116
 
@@ -125,7 +124,7 @@ describe VinQuery::Query do
125
124
  end
126
125
 
127
126
  context '404 response' do
128
- before(:each) { client.stub(:fetch).and_return '<html>404</html>' }
127
+ before { allow(client).to receive(:fetch).and_return('<html>404</html>') }
129
128
 
130
129
  it 'fetches xml and response cannot be validated' do
131
130
  expect{ client.get }.to raise_error VinQuery::ValidationError
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'spec_helper'
3
2
 
4
3
  describe VinQuery::TrimLevel do
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'vin_query'
data/vin_query.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require File.expand_path('../lib/vin_query/version', __FILE__)
3
2
 
4
3
  Gem::Specification.new do |gem|
@@ -18,7 +17,9 @@ Gem::Specification.new do |gem|
18
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
18
  gem.require_paths = ['lib']
20
19
 
21
- gem.add_dependency 'nokogiri', '~> 1.5.6'
20
+ gem.add_dependency 'nokogiri', '> 1.5'
22
21
 
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'bundler'
23
24
  gem.add_development_dependency 'rspec'
24
25
  end
metadata CHANGED
@@ -1,41 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vin_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-15 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.6
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.5.6
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rspec
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - '>='
59
+ - - ">="
32
60
  - !ruby/object:Gem::Version
33
61
  version: '0'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - '>='
66
+ - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  description: A ruby library for fetching and parsing VIN information from vinquery.com,
@@ -46,15 +74,16 @@ executables: []
46
74
  extensions: []
47
75
  extra_rdoc_files: []
48
76
  files:
49
- - .gitignore
50
- - .rspec
51
- - .travis.yml
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
52
80
  - CHANGELOG.md
53
81
  - Gemfile
54
82
  - LICENSE
55
83
  - README.md
56
84
  - Rakefile
57
85
  - lib/vin_query.rb
86
+ - lib/vin_query/configuration.rb
58
87
  - lib/vin_query/exceptions.rb
59
88
  - lib/vin_query/query.rb
60
89
  - lib/vin_query/trim_level.rb
@@ -62,6 +91,7 @@ files:
62
91
  - spec/fixtures/error.xml
63
92
  - spec/fixtures/success_multi.xml
64
93
  - spec/fixtures/success_single.xml
94
+ - spec/lib/vin_query/configuration_spec.rb
65
95
  - spec/lib/vin_query/query_spec.rb
66
96
  - spec/lib/vin_query/trim_level_spec.rb
67
97
  - spec/spec_helper.rb
@@ -75,17 +105,17 @@ require_paths:
75
105
  - lib
76
106
  required_ruby_version: !ruby/object:Gem::Requirement
77
107
  requirements:
78
- - - '>='
108
+ - - ">="
79
109
  - !ruby/object:Gem::Version
80
110
  version: '0'
81
111
  required_rubygems_version: !ruby/object:Gem::Requirement
82
112
  requirements:
83
- - - '>='
113
+ - - ">="
84
114
  - !ruby/object:Gem::Version
85
115
  version: '0'
86
116
  requirements: []
87
117
  rubyforge_project:
88
- rubygems_version: 2.0.3
118
+ rubygems_version: 2.5.1
89
119
  signing_key:
90
120
  specification_version: 4
91
121
  summary: A ruby library for accessing vinquery.com
@@ -93,6 +123,7 @@ test_files:
93
123
  - spec/fixtures/error.xml
94
124
  - spec/fixtures/success_multi.xml
95
125
  - spec/fixtures/success_single.xml
126
+ - spec/lib/vin_query/configuration_spec.rb
96
127
  - spec/lib/vin_query/query_spec.rb
97
128
  - spec/lib/vin_query/trim_level_spec.rb
98
129
  - spec/spec_helper.rb