Module: RockautoApi::Endpoints::Vehicles

Included in:
Client
Defined in:
lib/rockauto_api/endpoints/vehicles.rb

Constant Summary collapse

BASE_CATALOG_URL =
"https://www.rockauto.com/en/catalog/"

Instance Method Summary collapse

Instance Method Details

#get_engines_for_vehicle(make, year, model) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rockauto_api/endpoints/vehicles.rb', line 59

def get_engines_for_vehicle(make, year, model)
  path = "/en/catalog/#{make},#{year},#{model}"
  html = get(path)
  doc = Nokogiri::HTML(html)

  engines = doc.css('a[href*="carcode"]').map { |a|
    href = a["href"]
    next nil unless href
    match = href.match(/carcode=(\d+)/)
    next nil unless match
    Models::Engine.new(
      description: a.text.strip,
      carcode: match[1],
      href: Parsers::HtmlHelpers.make_absolute_url(href)
    )
  }.compact

  Models::VehicleEngines.new(
    make: make,
    year: year,
    model: model,
    engines: engines,
    count: engines.size
  )
end

#get_makesObject



8
9
10
11
12
# File 'lib/rockauto_api/endpoints/vehicles.rb', line 8

def get_makes
  html = get("/en/catalog/")
  results = Models::VehicleMakes.from_html(html)
  results
end

#get_models_for_make_year(make, year) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rockauto_api/endpoints/vehicles.rb', line 35

def get_models_for_make_year(make, year)
  simulate_navigation_context(make: make, year: year.to_s)

  path = "/en/catalog/#{make},#{year}"
  html = get(path)
  doc = Nokogiri::HTML(html)

  models = doc.css('a[href*="catalog"]').map { |a|
    href = a["href"]
    next nil if href.nil?
    match = href.match(/#{Regexp.escape(make)},#{year},(.+)/i)
    next nil unless match
    model = match[1].split(",").first
    model&.strip
  }.compact.uniq

  Models::VehicleModels.new(
    make: make,
    year: year,
    models: models,
    count: models.size
  )
end

#get_years_for_make(make) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rockauto_api/endpoints/vehicles.rb', line 14

def get_years_for_make(make)
  simulate_navigation_context(make: make)

  path = "/en/catalog/#{make}"
  html = get(path)
  doc = Nokogiri::HTML(html)

  years = doc.css('a[href*="catalog"]').map { |a|
    href = a["href"]
    next nil if href.nil?
    match = href.match(/#{Regexp.escape(make)},(\d{4})/i)
    match ? match[1].to_i : nil
  }.compact.uniq.sort

  Models::VehicleYears.new(
    make: make,
    years: years,
    count: years.size
  )
end