Class: VinData::Services::Edmunds
- Inherits:
-
Base
- Object
- Base
- VinData::Services::Edmunds
show all
- Defined in:
- lib/vindata/services/edmunds.rb
Instance Method Summary
collapse
Methods inherited from Base
#configuration, #initialize
Instance Method Details
#base_url ⇒ Object
9
10
11
|
# File 'lib/vindata/services/edmunds.rb', line 9
def base_url
'https://api.edmunds.com/api/vehicle/v2/'
end
|
#details_by_vin(vin) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/vindata/services/edmunds.rb', line 13
def details_by_vin vin
vinlookup = "#{base_url}vins/#{vin}"
response = JSON.parse(RestClient.get vinlookup, {:params => {
fmt: 'json',
api_key: configuration[:edmunds][:api_key]
}})
ret = {}
ret[:make] = response['make']['niceName']
if response['model']
ret[:model] = response['model']['niceName']
elsif response['years'].first['styles'].first['submodel']
ret[:model] = response['years'].first['styles'].first['submodel']['modelName']
end
ret[:year] = response['years'][0]['year']
ret[:edmunds] = response
return ret
rescue RestClient::BadRequest => err
return nil
rescue RestClient::ResourceNotFound => err
return nil
end
|
#get_acv(data) ⇒ Object
Required Data:
:make
:model
:year
:mileage
:zip
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/vindata/services/edmunds.rb', line 94
def get_acv data
info_is_present = data[:make] && data[:model] && data[:year]
vin_is_present = data[:vin].present?
condition_is_present = data[:condition].present?
location_is_present = data[:mileage] && data[:zip]
return nil unless (info_is_present || vin_is_present) &&
location_is_present &&
condition_is_present
if vin_is_present
car_details = details_by_vin data.delete(:vin)
return nil unless car_details
data.merge! car_details
end
response = style_data data
acvlookup = 'https://api.edmunds.com/v1/api/tmv/tmvservice/calculateusedtmv'
response = JSON.parse(RestClient.get acvlookup, {:params => {
styleid: response['styles'][0]['id'],
condition: data[:condition].to_s.capitalize,
mileage: data[:mileage],
zip: data[:zip],
fmt: 'json',
api_key: configuration[:edmunds][:api_key]
}})
if response == nil || response['tmv'] == nil
return nil
else
return {
common: {
retail: response['tmv']['totalWithOptions']['usedTmvRetail'],
private_party: response['tmv']['totalWithOptions']['usedPrivateParty'],
trade_in: response['tmv']['totalWithOptions']['usedTradeIn']
},
edmunds: response
}
end
end
|
#name ⇒ Object
5
6
7
|
# File 'lib/vindata/services/edmunds.rb', line 5
def name
'Edmunds'
end
|
#recalls(data) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/vindata/services/edmunds.rb', line 40
def recalls data
if data[:edmunds] && data[:edmunds]['years'][0]
year_id = data[:edmunds]['years'][0]['id']
else
years_url = "https://api.edmunds.com/api/vehicle/v2/#{data[:make]}/#{data[:model]}"
response = JSON.parse(RestClient.get years_url, {:params => {
fmt: 'json',
api_key: configuration[:edmunds][:api_key]
}})
year_id = response['years'].select{ |x| x['year'] == data[:year] }.first['id']
end
recall_url = 'https://api.edmunds.com/v1/api/maintenance/recallrepository/findbymodelyearid'
recall_response = JSON.parse(RestClient.get recall_url, {:params => {
modelyearid: year_id,
fmt: 'json',
api_key: configuration[:edmunds][:api_key]
}})
bulletin_url = 'https://api.edmunds.com/v1/api/maintenance/servicebulletinrepository/findbymodelyearid'
bulletin_response = JSON.parse(RestClient.get bulletin_url, {:params => {
modelyearid: year_id,
fmt: 'json',
api_key: configuration[:edmunds][:api_key]
}})
return {
edmunds: {
recalls: recall_response,
bulletins: bulletin_response
}
}
rescue RestClient::BadRequest => err
return nil
end
|
#style_data(data) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/vindata/services/edmunds.rb', line 80
def style_data data
stylelookup = base_url + data[:make] + '/' + data[:model] + '/' + data[:year].to_s + '/styles'
JSON.parse(RestClient.get stylelookup, {:params => {
fmt: 'json',
api_key: configuration[:edmunds][:api_key]
}})
end
|