class FipeApi::Model

Attributes

brand[RW]
id[RW]
name[RW]

Public Class Methods

new(id, name, brand) click to toggle source
# File lib/fipe_api/resources/model.rb, line 7
def initialize(id, name, brand)
  self.id = id
  self.name = name
  self.brand = brand
end

Public Instance Methods

get_years(table = nil) click to toggle source
# 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