vindata 0.0.6 → 0.0.7

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: e4baf9d935e2302be92c84707413bdf67f48f57b
4
- data.tar.gz: 4b0ac627aaab1781c7b2762014b7cc93a84cc6d9
3
+ metadata.gz: 5d5cf7f52d834c03dde6460ad4ad64d0be20e0e4
4
+ data.tar.gz: cfe11414fc3e56963687796cba3fa1a67f8c54a1
5
5
  SHA512:
6
- metadata.gz: 8a56386f3f9a8d773f36e79212e566a0910b2a507adc58abf3f32c67b9df600cdac736f3f0d4e495af609cb547e659d5b52dedd2a976edd872b4d4d4c531c6bb
7
- data.tar.gz: a287bb246656511f2acfcf1587fcf8a0a96f8bbeeb8c85785786ef557475702d4927d6710bfa1051898976f7a51fbd88f176a8d7d49ae2eeee07eb8ffee23abe
6
+ metadata.gz: 75ddbb0a1f089cc9e7388a5bf0bb72fc855f71b0524c9636a7dd2010161984035b0ab22c561e697a14f86f2e36a24c45e7eaf6ddd3fb7a33ae5130b67ea3462b
7
+ data.tar.gz: ee404f9dc9938104044326ffc2ee0da4bc6413713b3c2c1e4d57908c47ec1a7e3c1a193fba280e1862f8acf25365b99c5647aead089bb13f744d86f2901b78b7
@@ -12,25 +12,60 @@ module VinData::Services
12
12
 
13
13
  def details_by_vin vin
14
14
  # Lookup vehicle make/model/year by VIN
15
- vinlookup = base_url + 'vins/'+vin
16
- begin
17
- response = JSON.parse(RestClient.get vinlookup, {:params => {
18
- fmt: 'json',
19
- api_key: configuration[:edmunds][:api_key]
20
- }})
15
+ vinlookup = "#{base_url}vins/#{vin}"
16
+ response = JSON.parse(RestClient.get vinlookup, {:params => {
17
+ fmt: 'json',
18
+ api_key: configuration[:edmunds][:api_key]
19
+ }})
21
20
 
22
- # TODO: Check data validity here
21
+ # TODO: Check data validity here
23
22
 
24
- return {
25
- make: response['make']['niceName'],
26
- model: response['model']['niceName'],
27
- year: response['years'][0]['year'],
28
- edmunds: response
29
- }
30
- # Indicates VIN request failed with Edmunds
31
- rescue RestClient::BadRequest => err
32
- return nil
33
- end
23
+ return {
24
+ make: response['make']['niceName'],
25
+ model: response['model']['niceName'],
26
+ year: response['years'][0]['year'],
27
+ edmunds: response
28
+ }
29
+ # Indicates VIN request failed with Edmunds
30
+ rescue RestClient::BadRequest => err
31
+ return nil
32
+ # Indicates VIN was not valid
33
+ rescue RestClient::ResourceNotFound => err
34
+ return nil
35
+ end
36
+
37
+ def recalls data
38
+ # return nil unless data[:style_id]
39
+ years_url = "https://api.edmunds.com/api/vehicle/v2/#{data[:make]}/#{data[:model]}"
40
+ response = JSON.parse(RestClient.get years_url, {:params => {
41
+ fmt: 'json',
42
+ api_key: configuration[:edmunds][:api_key]
43
+ }})
44
+ year_id = response['years'].select{ |x| x['year'] == data[:year] }.first['id']
45
+
46
+ recall_url = 'https://api.edmunds.com/v1/api/maintenance/recallrepository/findbymodelyearid'
47
+ response = JSON.parse(RestClient.get recall_url, {:params => {
48
+ modelyearid: year_id,
49
+ fmt: 'json',
50
+ api_key: configuration[:edmunds][:api_key]
51
+ }})
52
+
53
+ # TODO: Check data validity here
54
+
55
+ return {
56
+ edmunds: response
57
+ }
58
+ # Indicates VIN request failed with Edmunds
59
+ rescue RestClient::BadRequest => err
60
+ return nil
61
+ end
62
+
63
+ def style_data data
64
+ stylelookup = base_url + data[:make] + '/' + data[:model] + '/' + data[:year].to_s + '/styles'
65
+ JSON.parse(RestClient.get stylelookup, {:params => {
66
+ fmt: 'json',
67
+ api_key: configuration[:edmunds][:api_key]
68
+ }})
34
69
  end
35
70
 
36
71
  # Required Data:
@@ -48,11 +83,7 @@ module VinData::Services
48
83
  end
49
84
 
50
85
  # Get the style ID by vehicle make/model/year
51
- stylelookup = base_url + data[:make] + '/' + data[:model] + '/' + data[:year].to_s + '/styles'
52
- response = JSON.parse(RestClient.get stylelookup, {:params => {
53
- fmt: 'json',
54
- api_key: configuration[:edmunds][:api_key]
55
- }})
86
+ response = style_data data
56
87
 
57
88
  # TODO: Check data validity here
58
89
 
@@ -1,3 +1,3 @@
1
1
  module VinData
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/vindata.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # External gems
2
- require 'rest_client' if defined?(RestClient)
2
+ require 'rest_client'
3
3
 
4
4
  # Internal files
5
5
  require 'vindata/configuration'
@@ -15,4 +15,9 @@ module VinData
15
15
  service = Services.get service
16
16
  service.get_acv data
17
17
  end
18
+
19
+ def self.recalls data, service = config[:service]
20
+ service = Services.get service
21
+ service.recalls data
22
+ end
18
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vindata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roupen Mouradian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client