Class: FipeApi::Year
Constant Summary
Constants inherited from Base
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.
-
#year ⇒ Object
Returns the value of attribute year.
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.
9 10 11 12 13 14 15 |
# File 'lib/fipe_api/resources/year.rb', line 9 def initialize(id, name, model) self.id = id.split("-")[0] self.year = self.id == '32000' ? Date.current.year : self.id self.fuel = id.split("-")[1] self.name = name self.model = model end |
Instance Attribute Details
#fuel ⇒ Object
Returns the value of attribute fuel.
7 8 9 |
# File 'lib/fipe_api/resources/year.rb', line 7 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.
6 7 8 |
# File 'lib/fipe_api/resources/year.rb', line 6 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/fipe_api/resources/year.rb', line 5 def name @name end |
#year ⇒ Object
Returns the value of attribute year.
4 5 6 |
# File 'lib/fipe_api/resources/year.rb', line 4 def year @year end |
Instance Method Details
#get_result(table = nil) ⇒ Object
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 45 46 47 |
# File 'lib/fipe_api/resources/year.rb', line 17 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", headers: HEADERS, 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 |