Class: Carquery::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/carquery/client.rb,
lib/carquery/client/version.rb

Constant Summary collapse

API_VERSION =
'0.3'.freeze
BASE_URL =
'https://www.carqueryapi.com'.freeze
VERSION =
"0.1.2"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/carquery/client.rb', line 10

def initialize(options = {})
  @connection = Faraday::Connection.new(
    BASE_URL,
    headers: {
      'Content-Type' => 'application/json'
    },
    ssl: {
      ca_path: options.fetch(:ca_path, default_config[:ca_path])
    },
  ) do |f|
    f.response :json
  end
end

Instance Method Details

#makes_for_year(year, us_only = 1) ⇒ Object



28
29
30
# File 'lib/carquery/client.rb', line 28

def makes_for_year(year, us_only = 1)
  request(cmd: 'getMakes', year: year, sold_in_us: us_only)['Makes']
end

#models_for_year_and_make(year, make, us_only = 1) ⇒ Object



32
33
34
# File 'lib/carquery/client.rb', line 32

def models_for_year_and_make(year, make, us_only = 1)
  request(cmd: 'getModels', year: year, make: make, sold_in_us: us_only)['Models']
end

#trims_for_model(year, make, model) ⇒ Object



36
37
38
# File 'lib/carquery/client.rb', line 36

def trims_for_model(year, make, model)
  request(cmd: 'getTrims', year: year, make: make, model: model)['Trims']
end

#yearsObject



24
25
26
# File 'lib/carquery/client.rb', line 24

def years
  request(cmd: 'getYears')['Years']
end