black_book 0.0.2 → 0.0.3

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: 04cdab15a4cfd41ea1f1383ab293ad3d66066f3b
4
- data.tar.gz: 12b9b06d5fd558aec24fe7530d25691c376c0ca1
3
+ metadata.gz: 46be316110f2e73d8fe95206b4ad38c5a2a74524
4
+ data.tar.gz: e546837e012a178a55fe8b870dcf28720884acb1
5
5
  SHA512:
6
- metadata.gz: f5143fd3198438654d84270eb5f57d99c099108b9cd83c5b32168c3c314adcacb8132975354545803a37aa912e3b3ddf903a0193b46db93fcd99f218782fece5
7
- data.tar.gz: 1c9dc6c4018efb69a97f295624cbacc0af639713f6af388c4ca7f70b8e4bafd017ccb3627fc55092b25c9f5facf79be66007f3e20409a883fe3245c0a91c053c
6
+ metadata.gz: a06ba8a599fc5c39b9a3b5fb0aacc83546dc6817e6ec8d6114ed9ab45e942b48c79e4b8d0936d40feb6998593eb2b65f71c191ba88b83193203086d567edbd70
7
+ data.tar.gz: e8884128aa51213cdc57cbd8feb4e45d4f4c2e83454295ff92f378fefe9cb1696a666c4c96e8eb6b9124d8ed38e4e33e70c575f1e75447207346bfbd7922ae99
@@ -1,4 +1,8 @@
1
1
  module BlackBook
2
2
  class BlackBookError < StandardError; end
3
3
  class VinNotFound < BlackBookError; end
4
+ class MakesNotFound < BlackBookError; end
5
+ class ModelsNotFound < BlackBookError; end
6
+ class SeriesNotFound < BlackBookError; end
7
+ class StylesNotFound < BlackBookError; end
4
8
  end
@@ -5,10 +5,10 @@ module BlackBook
5
5
  "https://www.blackbookws.com/UsedCarWSX.asmx?WSDL"
6
6
  end
7
7
 
8
- def current_valuation_for(vin, mileage, state, options={})
8
+ def current_valuation_from_vin(vin, mileage, state, options={})
9
9
  response = request(:get_current_vin_values, {
10
- "sCountryCode" => "U",
11
- "sFrequencyCode" => "W",
10
+ "sCountryCode" => (options[:country] || "U"),
11
+ "sFrequencyCode" => (options[:frequency] || "W"),
12
12
  "sVIN" => vin,
13
13
  "iMileage" => mileage,
14
14
  "sState" => state,
@@ -30,6 +30,120 @@ module BlackBook
30
30
  rescue Savon::SOAPFault => e
31
31
  raise BlackBookError.new e
32
32
  end
33
+
34
+ def current_valuation_from_data(year, make, model, series, style, mileage, state, options={})
35
+ response = request(:get_current_values, {
36
+ "sCountryCode" => (options[:country] || "U"),
37
+ "sFrequencyCode" => (options[:frequency] || "W"),
38
+ "sYear" => year,
39
+ "sMake" => make,
40
+ "sModel" => model,
41
+ "sSeries" => series,
42
+ "sStyle" => style,
43
+ "iMileage" => mileage,
44
+ "sState" => state,
45
+ "iExtraCleanAddDeductAdj" => (options[:extra_clean_adjustment] || 0),
46
+ "iCleanAddDeductAdj" => (options[:clean_adjustment] || 0),
47
+ "iAverageAddDeductAdj" => (options[:average_adjustment] || 0),
48
+ "iRoughAddDeductAdj" => (options[:rough_adjustment] || 0),
49
+ "bFillDrilldown" => "false",
50
+ "bReturnMileage" => "true",
51
+ "bReturnAddDeducts" => "true"
52
+ })
53
+
54
+ envelope = response.hash[:envelope]
55
+
56
+ raise VehicleNotFound if envelope[:header][:user_credentials][:returncode] == "20"
57
+ raise BlackBookError if envelope[:header][:user_credentials][:returncode] != "0"
58
+
59
+ envelope[:body][:current_values_response][:current_values_result]
60
+ rescue Savon::SOAPFault => e
61
+ raise BlackBookError.new e
62
+ end
63
+
64
+ def years(options={})
65
+ response = request(:get_years, {
66
+ "sCountryCode" => (options[:country] || "U")
67
+ })
68
+
69
+ envelope = response.hash[:envelope]
70
+
71
+ raise BlackBookError if envelope[:header][:user_credentials][:returncode] != "0"
72
+
73
+ envelope[:body][:years_response][:years_result][:years][:year]
74
+ rescue Savon::SOAPFault => e
75
+ raise BlackBookError.new e
76
+ end
77
+
78
+ def makes(year, options={})
79
+ response = request(:get_makes, {
80
+ "sCountryCode" => (options[:country] || "U"),
81
+ "sYear" => year
82
+ })
83
+
84
+ envelope = response.hash[:envelope]
85
+
86
+ raise BlackBookError if envelope[:header][:user_credentials][:returncode] != "0"
87
+ raise MakesNotFound if envelope[:body][:makes_response][:makes_result][:makes].nil?
88
+
89
+ envelope[:body][:makes_response][:makes_result][:makes][:make]
90
+ rescue Savon::SOAPFault => e
91
+ raise BlackBookError.new e
92
+ end
93
+
94
+ def models(year, make, options={})
95
+ response = request(:get_models, {
96
+ "sCountryCode" => (options[:country] || "U"),
97
+ "sYear" => year,
98
+ "sMake" => make
99
+ })
100
+
101
+ envelope = response.hash[:envelope]
102
+
103
+ raise BlackBookError if envelope[:header][:user_credentials][:returncode] != "0"
104
+ raise ModelsNotFound if envelope[:body][:models_response][:models_result][:models].nil?
105
+
106
+ envelope[:body][:models_response][:models_result][:models][:model]
107
+ rescue Savon::SOAPFault => e
108
+ raise BlackBookError.new e
109
+ end
110
+
111
+ def series(year, make, model, options={})
112
+ response = request(:get_series, {
113
+ "sCountryCode" => (options[:country] || "U"),
114
+ "sYear" => year,
115
+ "sMake" => make,
116
+ "sModel" => model
117
+ })
118
+
119
+ envelope = response.hash[:envelope]
120
+
121
+ raise BlackBookError if envelope[:header][:user_credentials][:returncode] != "0"
122
+ raise SeriesNotFound if envelope[:body][:series_response][:series_result][:series].nil?
123
+
124
+ envelope[:body][:series_response][:series_result][:series][:vehseries]
125
+ rescue Savon::SOAPFault => e
126
+ raise BlackBookError.new e
127
+ end
128
+
129
+ def styles(year, make, model, series, options={})
130
+ response = request(:get_styles, {
131
+ "sCountryCode" => (options[:country] || "U"),
132
+ "sYear" => year,
133
+ "sMake" => make,
134
+ "sModel" => model,
135
+ "sSeries" => series
136
+ })
137
+
138
+ envelope = response.hash[:envelope]
139
+
140
+ raise BlackBookError if envelope[:header][:user_credentials][:returncode] != "0"
141
+ raise StylesNotFound if envelope[:body][:body_styles_response][:body_styles_result][:styles].nil?
142
+
143
+ envelope[:body][:body_styles_response][:body_styles_result][:styles][:style]
144
+ rescue Savon::SOAPFault => e
145
+ raise BlackBookError.new e
146
+ end
33
147
  end
34
148
  end
35
149
  end
@@ -1,3 +1,3 @@
1
1
  module BlackBook
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,18 +1,18 @@
1
1
  require_relative "../minitest_helper"
2
2
 
3
3
  describe BlackBook::UsedCars do
4
+ before do
5
+ BlackBook.configure do |config|
6
+ config.user_id = "xxxxx"
7
+ config.password = "xxxxx"
8
+ end
9
+ end
10
+
4
11
  it "returns a proper WSDL URL" do
5
12
  BlackBook::UsedCars.wsdl_url.must_equal "https://www.blackbookws.com/UsedCarWSX.asmx?WSDL"
6
13
  end
7
14
 
8
15
  describe "current valuation for a given VIN, mileage and state" do
9
- before do
10
- BlackBook.configure do |config|
11
- config.user_id = "xxxx"
12
- config.password = "xxxx"
13
- end
14
- end
15
-
16
16
  it "should have a list of services" do
17
17
  VCR.use_cassette("wsdl") do
18
18
  BlackBook::UsedCars.operations.must_include :get_current_vin_values
@@ -22,7 +22,7 @@ describe BlackBook::UsedCars do
22
22
  it "should get the current values of a given VIN" do
23
23
  VCR.use_cassette("wsdl") do
24
24
  VCR.use_cassette("valid_request") do
25
- BlackBook::UsedCars.current_valuation_for("1D7HW22K45S177616", 50_000, "IL")[:value_array].must_include :bb_value
25
+ BlackBook::UsedCars.current_valuation_from_vin("1D7HW22K45S177616", 50_000, "IL")[:value_array].must_include :bb_value
26
26
  end
27
27
  end
28
28
  end
@@ -30,7 +30,7 @@ describe BlackBook::UsedCars do
30
30
  it "should raise an exception when a VIN is not found" do
31
31
  VCR.use_cassette("wsdl") do
32
32
  VCR.use_cassette("vin_not_found") do
33
- proc { BlackBook::UsedCars.current_valuation_for("NOT_FOUND", 50_000, "IL") }.must_raise BlackBook::VinNotFound
33
+ proc { BlackBook::UsedCars.current_valuation_from_vin("NOT_FOUND", 50_000, "IL") }.must_raise BlackBook::VinNotFound
34
34
  end
35
35
  end
36
36
  end
@@ -38,9 +38,185 @@ describe BlackBook::UsedCars do
38
38
  it "should raise an exception when passing bad request data" do
39
39
  VCR.use_cassette("wsdl") do
40
40
  VCR.use_cassette("savon_error") do
41
- proc { BlackBook::UsedCars.current_valuation_for("1D7HW22K45S177616", "", "") }.must_raise BlackBook::BlackBookError
41
+ proc { BlackBook::UsedCars.current_valuation_from_vin("1D7HW22K45S177616", "", "") }.must_raise BlackBook::BlackBookError
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "current valuation for make, model, series, and style" do
48
+ it "should have a list of services" do
49
+ VCR.use_cassette("wsdl") do
50
+ BlackBook::UsedCars.operations.must_include :get_current_values
51
+ end
52
+ end
53
+
54
+ it "should get the current values" do
55
+ VCR.use_cassette("wsdl") do
56
+ VCR.use_cassette("value_valid_request") do
57
+ BlackBook::UsedCars.current_valuation_from_data(2013, "Ford", "Fiesta", "SE", "4D Hatchback", 10_000, "IL")[:value_array].must_include :bb_value
58
+ end
59
+ end
60
+ end
61
+
62
+ it "should raise an exception when passing bad request data" do
63
+ VCR.use_cassette("wsdl") do
64
+ VCR.use_cassette("value_savon_error") do
65
+ proc { BlackBook::UsedCars.current_valuation_from_data(2013, "Ford", "Fiesta", "SE", "4D Hatchback", 10_000, "IL", { country: "INVALID" }) }.must_raise BlackBook::BlackBookError
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "years" do
72
+ it "should have a list of services" do
73
+ VCR.use_cassette("wsdl") do
74
+ BlackBook::UsedCars.operations.must_include :get_years
75
+ end
76
+ end
77
+
78
+ it "should get the current years" do
79
+ VCR.use_cassette("wsdl") do
80
+ VCR.use_cassette("years_valid_request") do
81
+ BlackBook::UsedCars.years.must_include "2013"
82
+ end
83
+ end
84
+ end
85
+
86
+ it "should raise an exception when passing bad request data" do
87
+ VCR.use_cassette("wsdl") do
88
+ VCR.use_cassette("years_savon_error") do
89
+ proc { BlackBook::UsedCars.years({ country: "INVALID" }) }.must_raise BlackBook::BlackBookError
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "makes" do
96
+ it "should have a list of services" do
97
+ VCR.use_cassette("wsdl") do
98
+ BlackBook::UsedCars.operations.must_include :get_makes
99
+ end
100
+ end
101
+
102
+ it "should get the current years" do
103
+ VCR.use_cassette("wsdl") do
104
+ VCR.use_cassette("makes_valid_request") do
105
+ BlackBook::UsedCars.makes(2013).must_include "Ford"
106
+ end
107
+ end
108
+ end
109
+
110
+ it "should raise an exception when passing bad request data" do
111
+ VCR.use_cassette("wsdl") do
112
+ VCR.use_cassette("make_savon_error") do
113
+ proc { BlackBook::UsedCars.makes(2013, { country: "INVALID" }) }.must_raise BlackBook::BlackBookError
114
+ end
115
+ end
116
+ end
117
+
118
+ it "should raise an exception when no vehicles are found" do
119
+ VCR.use_cassette("wsdl") do
120
+ VCR.use_cassette("makes_error") do
121
+ proc { BlackBook::UsedCars.makes(1864) }.must_raise BlackBook::MakesNotFound
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+ describe "models" do
128
+ it "should have a list of services" do
129
+ VCR.use_cassette("wsdl") do
130
+ BlackBook::UsedCars.operations.must_include :get_models
131
+ end
132
+ end
133
+
134
+ it "should get the current years" do
135
+ VCR.use_cassette("wsdl") do
136
+ VCR.use_cassette("models_valid_request") do
137
+ BlackBook::UsedCars.models(2013, "Ford").must_include "Fiesta"
138
+ end
139
+ end
140
+ end
141
+
142
+ it "should raise an exception when passing bad request data" do
143
+ VCR.use_cassette("wsdl") do
144
+ VCR.use_cassette("model_savon_error") do
145
+ proc { BlackBook::UsedCars.models(2013, "Ford", { country: "INVALID" }) }.must_raise BlackBook::BlackBookError
146
+ end
147
+ end
148
+ end
149
+
150
+ it "should raise an exception when no vehicles are found" do
151
+ VCR.use_cassette("wsdl") do
152
+ VCR.use_cassette("model_error") do
153
+ proc { BlackBook::UsedCars.models(1864, "Ford") }.must_raise BlackBook::ModelsNotFound
154
+ end
155
+ end
156
+ end
157
+ end
158
+
159
+ describe "series" do
160
+ it "should have a list of services" do
161
+ VCR.use_cassette("wsdl") do
162
+ BlackBook::UsedCars.operations.must_include :get_series
163
+ end
164
+ end
165
+
166
+ it "should get the current series" do
167
+ VCR.use_cassette("wsdl") do
168
+ VCR.use_cassette("series_valid_request") do
169
+ BlackBook::UsedCars.series(2013, "Ford", "Fiesta").must_include "SE"
170
+ end
171
+ end
172
+ end
173
+
174
+ it "should raise an exception when passing bad request data" do
175
+ VCR.use_cassette("wsdl") do
176
+ VCR.use_cassette("series_savon_error") do
177
+ proc { BlackBook::UsedCars.series(2013, "Ford", "Fiesta", { country: "INVALID" }) }.must_raise BlackBook::BlackBookError
178
+ end
179
+ end
180
+ end
181
+
182
+ it "should raise an exception when no vehicles are found" do
183
+ VCR.use_cassette("wsdl") do
184
+ VCR.use_cassette("series_error") do
185
+ proc { BlackBook::UsedCars.series(1864, "Ford", "Fiesta") }.must_raise BlackBook::SeriesNotFound
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ describe "styles" do
192
+ it "should have a list of services" do
193
+ VCR.use_cassette("wsdl") do
194
+ BlackBook::UsedCars.operations.must_include :get_styles
195
+ end
196
+ end
197
+
198
+ it "should get the current styles" do
199
+ VCR.use_cassette("wsdl") do
200
+ VCR.use_cassette("styles_valid_request") do
201
+ BlackBook::UsedCars.styles(2013, "Ford", "Fiesta", "SE").must_include "4D Hatchback"
202
+ end
203
+ end
204
+ end
205
+
206
+ it "should raise an exception when passing bad request data" do
207
+ VCR.use_cassette("wsdl") do
208
+ VCR.use_cassette("style_savon_error") do
209
+ proc { BlackBook::UsedCars.styles(2013, "Ford", "Fiesta", "SE", { country: "INVALID" }) }.must_raise BlackBook::BlackBookError
210
+ end
211
+ end
212
+ end
213
+
214
+ it "should raise an exception when no vehicles are found" do
215
+ VCR.use_cassette("wsdl") do
216
+ VCR.use_cassette("styles_error") do
217
+ proc { BlackBook::UsedCars.styles(1864, "Ford", "Fiesta", "SE") }.must_raise BlackBook::StylesNotFound
42
218
  end
43
219
  end
44
220
  end
45
221
  end
46
- end
222
+ end
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.blackbookws.com/UsedCarWSX.asmx
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?><env:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
9
+ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:tns=\"https://blackbookws.com/UsedCarWSX\"
10
+ xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"><env:Header><UserCredentials
11
+ xmlns=\"https://blackbookws.com/UsedCarWSX\">\n <userid>xxxxx</userid>\n
12
+ \ <password>xxxxx</password>\n <customer/>\n <producttype>W</producttype>\n
13
+ \ <returncode>0</returncode>\n <returnmessage/>\n </UserCredentials></env:Header><env:Body><tns:Makes><tns:sCountryCode>INVALID</tns:sCountryCode><tns:sYear>2013</tns:sYear></tns:Makes></env:Body></env:Envelope>"
14
+ headers:
15
+ Soapaction:
16
+ - ! '"https://blackbookws.com/UsedCarWSX/Makes"'
17
+ Content-Type:
18
+ - text/xml;charset=UTF-8
19
+ Content-Length:
20
+ - '705'
21
+ Accept:
22
+ - ! '*/*'
23
+ User-Agent:
24
+ - Ruby
25
+ response:
26
+ status:
27
+ code: 200
28
+ message: OK
29
+ headers:
30
+ Cache-Control:
31
+ - private, max-age=0
32
+ Content-Type:
33
+ - text/xml; charset=utf-8
34
+ Server:
35
+ - Microsoft-IIS/7.5
36
+ X-Aspnet-Version:
37
+ - 2.0.50727
38
+ X-Powered-By:
39
+ - ASP.NET
40
+ Date:
41
+ - Thu, 06 Jun 2013 17:34:34 GMT
42
+ Content-Length:
43
+ - '619'
44
+ body:
45
+ encoding: US-ASCII
46
+ string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
47
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><UserCredentials
48
+ xmlns="https://blackbookws.com/UsedCarWSX"><userid>xxxxx</userid><password>xxxxx</password><customer
49
+ /><producttype>W</producttype><returncode>31</returncode><returnmessage>Invalid
50
+ or missing country code</returnmessage></UserCredentials></soap:Header><soap:Body><MakesResponse
51
+ xmlns="https://blackbookws.com/UsedCarWSX"><MakesResult /></MakesResponse></soap:Body></soap:Envelope>
52
+ http_version:
53
+ recorded_at: Thu, 06 Jun 2013 17:34:34 GMT
54
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.blackbookws.com/UsedCarWSX.asmx
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?><env:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
9
+ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:tns=\"https://blackbookws.com/UsedCarWSX\"
10
+ xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"><env:Header><UserCredentials
11
+ xmlns=\"https://blackbookws.com/UsedCarWSX\">\n <userid>xxxxx</userid>\n
12
+ \ <password>xxxxx</password>\n <customer/>\n <producttype>W</producttype>\n
13
+ \ <returncode>0</returncode>\n <returnmessage/>\n </UserCredentials></env:Header><env:Body><tns:Makes><tns:sCountryCode>U</tns:sCountryCode><tns:sYear>1864</tns:sYear></tns:Makes></env:Body></env:Envelope>"
14
+ headers:
15
+ Soapaction:
16
+ - ! '"https://blackbookws.com/UsedCarWSX/Makes"'
17
+ Content-Type:
18
+ - text/xml;charset=UTF-8
19
+ Content-Length:
20
+ - '699'
21
+ Accept:
22
+ - ! '*/*'
23
+ User-Agent:
24
+ - Ruby
25
+ response:
26
+ status:
27
+ code: 200
28
+ message: OK
29
+ headers:
30
+ Cache-Control:
31
+ - private, max-age=0
32
+ Content-Type:
33
+ - text/xml; charset=utf-8
34
+ Server:
35
+ - Microsoft-IIS/7.5
36
+ X-Aspnet-Version:
37
+ - 2.0.50727
38
+ X-Powered-By:
39
+ - ASP.NET
40
+ Date:
41
+ - Thu, 06 Jun 2013 17:34:32 GMT
42
+ Content-Length:
43
+ - '625'
44
+ body:
45
+ encoding: US-ASCII
46
+ string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
47
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><UserCredentials
48
+ xmlns="https://blackbookws.com/UsedCarWSX"><userid>xxxxx</userid><password>xxxxx</password><customer
49
+ /><producttype>W</producttype><returncode>0</returncode><returnmessage>success
50
+ - (makes)</returnmessage></UserCredentials></soap:Header><soap:Body><MakesResponse
51
+ xmlns="https://blackbookws.com/UsedCarWSX"><MakesResult><makes /></MakesResult></MakesResponse></soap:Body></soap:Envelope>
52
+ http_version:
53
+ recorded_at: Thu, 06 Jun 2013 17:34:33 GMT
54
+ recorded_with: VCR 2.5.0