module Carquery

Constants

API_URL
CarModel
Make
Trim
VERSION

Public Class Methods

get_makes(params={}) click to toggle source

Returns auto makes Optional params:

@year       [optional] - all makes which produced a model in the specified year
@sold_in_us [optional] - setting it to “1″ will restrict results to models sold in the USA.

Usage:

Carquery.get_makes year: 2009 => [#<struct Carquery::Make code="abarth", title="Abarth", is_common=false, country="Italy">, ...]
# File lib/carquery/dsl/get_makes.rb, line 9
def self.get_makes params={}
  response = request 'getMakes', params
  response['Makes'].map {|make| Make.build make }
end
get_models(make_code, params={}) click to toggle source

Returns car models by the manufacturer Input: auto make code Optional params:

@year       [optional]  - omitting it will retrieve all model names ever produced by the manufacturer.
@sold_in_us [optional]  - setting it to “1″ will restrict results to models sold in the USA.
@body       [optional]  - including it will restrict results to models of the specified body type (SUV, Sedan, etc)

Usage:

Carquery.get_models_for 'volvo', year: 2010 => [#<struct Carquery::CarModel title="120">, ...]
# File lib/carquery/dsl/get_models.rb, line 13
def get_models make_code, params={}
  params.merge! make: make_code
  response = request 'getModels', params
  response['Models'].map {|make| CarModel.build make }
end
Also aliased as: get_models_for
get_models_for(make_code, params={})
Alias for: get_models
get_trim(id) click to toggle source

Returns car model trim by specified id Input: auto make code Optional params: none Usage:

Carquery.get_trim 12343 => #<struct Carquery::Trim id=12343, title="Tempra", make_code="fiat", trim="1.6", ...>
# File lib/carquery/dsl/get_trim.rb, line 10
def get_trim id
  response = request 'getModel', model: id
  Trim.build response
end
get_trims(params={}) click to toggle source

Returns trim data for models meeting specified criteria. Optional params:

@make             - Make code
@model            - Model Name
@body             - Coupe, Sedan, SUV, Pickup, Crossover, Minivan, etc.
@doors            - number of doors
@drive            - Front, Rear, AWD, 4WD, etc
@engine_position  - Front, Middle, Rear
@engine_type      - V, in-line, etc
@fuel_type        - Gasoline, Diesel, etc
@full_results     - 1 by default. Set to 0 to include only basic year / make /model / trim data (improves load times)
@keyword          - Keyword search. Searches year, make, model, and trim values
@min_cylinders    - Minimum Number of cylinders
@min_lkm_hwy      - Maximum fuel efficiency (highway, l/100km)
@min_power        - Minimum engine power (PS)
@min_top_speed    - Minimum Top Speed (km/h)
@min_torque       - Minimum Torque (nm)
@min_weight       - Minimum Weight (kg)
@min_year         - Earliest Model Year
@max_cylinders    - Maximum Number of cylinders
@max_lkm_hwy      - Minimum fuel efficiency (highway, l/100km)
@max_power        - Minimum engine power (HP)
@max_top_speed    - Maximum Top Speed (km/h)
@max_torque       - Maximum Torque (nm)
@max_weight       - Maximum Weight (kg)
@max_year         - Latest Model Year
@seats            - Number of Seats
@sold_in_us       - 1(sold in US), 0(not sold in US)
@year             - Model Year

Usage:

Carquery.get_trims 'volvo', year: 2010 => [#<struct Carquery::Trim id=12343, title="Tempra", make_code="fiat", ...>, ...]

Notes:

Results are sorted by year, make, model, and trim. Results are limited to 500 records.
# File lib/carquery/dsl/get_trims.rb, line 38
def get_trims params={}
  response = request 'getTrims', params
  response['Trims'].map {|make| Trim.build make }
end
get_years_range() click to toggle source

Returns range of available years from the CarQuery database. Input: none Usage:

Carquery.get_years_range => 1941..2012
# File lib/carquery/dsl/get_years_range.rb, line 9
def get_years_range
  response = request 'getYears'
  min = response["Years"]["min_year"].to_i
  max = response["Years"]["max_year"].to_i
  min..max
end

Protected Class Methods

_build_url(params={}) click to toggle source
# File lib/carquery/request.rb, line 23
def _build_url params={}
  uri = Addressable::URI.parse API_URL
  uri.query_values = params
  uri.to_s
end
request(cmd, params={}) click to toggle source
# File lib/carquery/request.rb, line 10
def request cmd, params={}
  params.merge! cmd: cmd
  response = HTTParty.get _build_url(params)

  if cmd == 'getModel'
    raise RequestError, "Not found" unless response.first.has_key? "model_id"
    response.parsed_response.first
  else
    raise RequestError, response["error"] if response.has_key? "error"
    response.parsed_response
  end
end