class MotoRecall::Client::Volvo
Public Class Methods
url(vin = nil)
click to toggle source
# File lib/moto_recall/client/volvo.rb, line 6 def self.url(vin = nil) "https://volvornt.harte-hanks.com/forms/VolvoRecallSearch.aspx" end
Public Instance Methods
fetch(vin)
click to toggle source
# 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
format(recall)
click to toggle source
# 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)
click to toggle source
# File lib/moto_recall/client/volvo.rb, line 38 def process(response) doc = Nokogiri::HTML(response) if doc.css("#RecallDiv").empty? return [] else # Note: this likely will not work if multiple recalls are present, # we are currently unable to find an example where this is true. 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