Class: MotoRecall::Client::Chrysler

Inherits:
GenericClient show all
Defined in:
lib/moto_recall/client/chrysler.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GenericClient

#fetch, #find, #initialize, #url

Constructor Details

This class inherits a constructor from MotoRecall::Client::GenericClient

Class Method Details

.url(vin) ⇒ Object



3
4
5
# File 'lib/moto_recall/client/chrysler.rb', line 3

def self.url(vin)
  "https://www.moparownerconnect.com/oc/us/en-us/sub/Pages/RecallsResults.aspx?Vin=#{vin}"
end

Instance Method Details

#format(recall) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/moto_recall/client/chrysler.rb', line 36

def format(recall)
  {
    type: nil,
    nhtsa_number: recall["NHTSA Recall #"],
    oem_number: recall["Chrysler Recall #"],
    date: recall["Recall Date"],
    title: nil,
    description: recall["Repair Description"],
    safety_risk: recall["Safety Defect/Non Compliance Description and Safety Risk"],
    remedy: nil,
    status: recall["Recall Status"],
    notes: nil
  }
end

#process(response) ⇒ Object



7
8
9
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
# File 'lib/moto_recall/client/chrysler.rb', line 7

def process(response)
  doc = Nokogiri::HTML(response)
  content = doc.css("#centerbodyContentWrp")
  recalls = []

  unless content.text.include?("No Outstanding Recalls or Customer Satisfaction Notifications Exist")
    # Chrysler's response has two tables, one for "Safety Recalls"
    # which is at this selector (`#divSafetyRecallsTable table`)
    # and one for "Campaigns" (`#divCampaignTable table`).
    # `2C4RC1BG9ER209216` shows an example of a "Safety Recall"
    # but I haven't yet seen an example of a "Campaign." We will
    # want to make sure that we return content from both tables.
    tables = doc.css("#divSafetyRecallsTable table, #divCampaignTable table")

    tables.each do |table|
      headers = table.css("tr:first-child th").map { |th| th.text }
      recalls << table.css("tr:not(:first-child)").map do |tr|
        recall = {}
        tr.css("td").each_with_index do |td, i|
          recall[headers[i]] = td.text.strip
        end
        recall
      end
    end
  end

  recalls.flatten
end