Class: FipeApi::Year
Instance Attribute Summary collapse
-
#fuel ⇒ Object
Returns the value of attribute fuel.
-
#id ⇒ Object
Returns the value of attribute id.
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #get_result(table = nil) ⇒ Object
-
#initialize(id, name, model) ⇒ Year
constructor
A new instance of Year.
Constructor Details
#initialize(id, name, model) ⇒ Year
Returns a new instance of Year.
8 9 10 11 12 13 |
# File 'lib/fipe_api/resources/year.rb', line 8 def initialize(id, name, model) self.id = id.split("-")[0] self.fuel = id.split("-")[1] self.name = name self.model = model end |
Instance Attribute Details
#fuel ⇒ Object
Returns the value of attribute fuel.
6 7 8 |
# File 'lib/fipe_api/resources/year.rb', line 6 def fuel @fuel end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/fipe_api/resources/year.rb', line 3 def id @id end |
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/fipe_api/resources/year.rb', line 5 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/fipe_api/resources/year.rb', line 4 def name @name end |
Instance Method Details
#get_result(table = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fipe_api/resources/year.rb', line 15 def get_result(table = nil) if table.nil? table = Table.latest(self.model.brand.vehicle) end response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarValorComTodosParametros", params: { codigoTabelaReferencia: table.id, codigoTipoVeiculo: self.model.brand.vehicle.id, codigoMarca: self.model.brand.id, codigoModelo: self.model.id, anoModelo: self.id, codigoTipoCombustivel: self.fuel, tipoVeiculo: self.model.brand.vehicle.name_id, tipoConsulta: "tradicional" }, body: {}.to_json).to_s result_json = JSON.parse(response) fipe_result = nil if !result_json.nil? fipe_result = FipeResult.new(result_json["CodigoFipe"].strip, self, result_json["Combustivel"], result_json["Autenticacao"], result_json["Valor"], result_json["DataConsulta"]) end fipe_result end |