Class: FipeApi::Brand
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#table ⇒ Object
Returns the value of attribute table.
-
#vehicle ⇒ Object
Returns the value of attribute vehicle.
Instance Method Summary collapse
- #get_models(table = nil) ⇒ Object
-
#initialize(id, name, table, vehicle) ⇒ Brand
constructor
A new instance of Brand.
Constructor Details
#initialize(id, name, table, vehicle) ⇒ Brand
Returns a new instance of Brand.
8 9 10 11 12 13 |
# File 'lib/fipe_api/resources/brand.rb', line 8 def initialize(id, name, table, vehicle) self.id = id self.name = name self.table = table self.vehicle = vehicle end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/fipe_api/resources/brand.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/fipe_api/resources/brand.rb', line 4 def name @name end |
#table ⇒ Object
Returns the value of attribute table.
6 7 8 |
# File 'lib/fipe_api/resources/brand.rb', line 6 def table @table end |
#vehicle ⇒ Object
Returns the value of attribute vehicle.
5 6 7 |
# File 'lib/fipe_api/resources/brand.rb', line 5 def vehicle @vehicle end |
Instance Method Details
#get_models(table = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fipe_api/resources/brand.rb', line 15 def get_models(table = nil) if table.nil? table = Table.latest(self.vehicle) end response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarModelos", headers: HEADERS, params: { codigoTabelaReferencia: table.id, codigoTipoVeiculo: self.vehicle.id, codigoMarca: self.id }, body: {}.to_json).to_s models_hash = JSON.parse(response) models_result = [] models_hash["Modelos"].each do |model| models_result << Model.new(model["Value"], model["Label"], self) end models_result end |