class FipeApi::Vehicle
Constants
- CAR
- MOTORCYCLE
- TRUCK
Attributes
id[RW]
name[RW]
Public Class Methods
all()
click to toggle source
# File lib/fipe_api/resources/vehicle.rb, line 15 def self.all [Vehicle.new(CAR, "Car"), Vehicle.new(MOTORCYCLE, "Motorcycle"), Vehicle.new(TRUCK, "Truck")] end
new(id, name)
click to toggle source
# File lib/fipe_api/resources/vehicle.rb, line 10 def initialize(id, name) self.id = id self.name = name end
Public Instance Methods
get_brands(table = nil)
click to toggle source
# File lib/fipe_api/resources/vehicle.rb, line 25 def get_brands(table = nil) if table.nil? table = Table.latest(self) end response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarMarcas", headers: HEADERS, params: { codigoTabelaReferencia: table.id, codigoTipoVeiculo: self.id }, body: {}.to_json).to_s brands_hash = JSON.parse(response) brands_result = [] brands_hash.each do |brand| brands_result << Brand.new(brand["Value"], brand["Label"], table, self) end brands_result end
get_tables()
click to toggle source
# File lib/fipe_api/resources/vehicle.rb, line 21 def get_tables Table.all(self) end
name_id()
click to toggle source
# File lib/fipe_api/resources/vehicle.rb, line 40 def name_id case id when CAR return "carro" when MOTORCYCLE return "moto" when TRUCK return "caminhao" end end