Class: MotoRecall::Client::Volvo
Class Method Summary
collapse
Instance Method Summary
collapse
#find, #initialize, #url
Class Method Details
.url(vin = nil) ⇒ Object
6
7
8
|
# File 'lib/moto_recall/client/volvo.rb', line 6
def self.url(vin = nil)
"https://volvornt.harte-hanks.com/forms/VolvoRecallSearch.aspx"
end
|
Instance Method Details
#fetch(vin) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/moto_recall/client/volvo.rb', line 10
def fetch(vin)
agent = Mechanize.new
agent.user_agent_alias = "Windows Chrome"
agent.ssl_version = "TLSv1"
page = agent.get(url)
view_state = page.at("input[name='__VIEWSTATE']")["value"]
view_state_generator = page.at("input[name='__VIEWSTATEGENERATOR']")["value"]
event_validation = page.at("input[name='__EVENTVALIDATION']")["value"]
event_argument = page.at("input[name='__EVENTARGUMENT']")["value"]
data = {
"ctl00$MainContent$tbVIN" => vin,
"ctl00$ScriptManager1" => "ctl00$MainContent$updatePnl|ctl00$MainContent$btnFormSubmit",
"__ASYNCPOST" => "true",
"__EVENTTARGET" => "ctl00$MainContent$btnFormSubmit",
"__VIEWSTATE" => view_state,
"__VIEWSTATEGENERATOR" => view_state_generator,
"__EVENTVALIDATION" => event_validation,
"__EVENTARGUMENT" => event_argument
}
response = agent.post(url, data)
response.body
end
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/moto_recall/client/volvo.rb', line 63
def format(recall)
{
type: nil,
nhtsa_number: recall["nhtsa_recall_number"],
oem_number: nil,
date: recall["date"],
title: nil,
description: recall["recall_info"],
safety_risk: recall["safety_risk"],
remedy: recall["remedy"],
status: recall["recall_status"],
notes: recall["manufacturer_notes"]
}
end
|
#process(response) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/moto_recall/client/volvo.rb', line 38
def process(response)
doc = Nokogiri::HTML(response)
if doc.css("#RecallDiv").empty?
return []
else
content = doc.css("#RecallDiv")
data = content.css("span").reduce({}) do |memo, span|
first_child = span.children.first
if first_child.name == "text"
key = first_child.text.parameterize("_")
value = span.children[1].text
memo[key] = value
end
memo
end
data["pdf_url"] = content.to_s.match(/<a.+?href="(.+?)".+?>Download this PDF<\/a>/)[1]
return [data]
end
end
|