13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/fipe_api/resources/model.rb', line 13
def get_years(table = nil)
if table.nil?
table = Table.latest(self.brand.vehicle)
end
response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarAnoModelo",
headers: HEADERS,
params: {
codigoTabelaReferencia: table.id,
codigoTipoVeiculo: self.brand.vehicle.id,
codigoMarca: self.brand.id,
codigoModelo: self.id,
},
body: {}.to_json).to_s
years_hash = JSON.parse(response)
years_result = []
years_hash.each do |year|
years_result << Year.new(year["Value"], year["Label"], self)
end
years_result
end
|