fipe_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/fipe_api.gemspec +28 -0
- data/lib/fipe_api/base.rb +9 -0
- data/lib/fipe_api/resources/brand.rb +36 -0
- data/lib/fipe_api/resources/fipe_result.rb +26 -0
- data/lib/fipe_api/resources/model.rb +35 -0
- data/lib/fipe_api/resources/table.rb +58 -0
- data/lib/fipe_api/resources/vehicle.rb +51 -0
- data/lib/fipe_api/resources/year.rb +46 -0
- data/lib/fipe_api/utils.rb +9 -0
- data/lib/fipe_api/version.rb +3 -0
- data/lib/fipe_api.rb +9 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e160a589c347a72ed80fe6d753242458d6205dd
|
4
|
+
data.tar.gz: 25fd85a2f331347ef407916802c47bfe0cf6f278
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18afdaf30a4175f67372151cdac6d04b40fe8032887bb5d81ca7d3e1620a75f006f9f89e6a3777de4c8d78e1bd95edb3c7774bbcafe1bd291eb25eb36f40e906
|
7
|
+
data.tar.gz: 6866cb4e774cbb6f8be4c0603b8707528e2a2820c78f8e21f0eb1e1bb33ffbcdee3082bf2308cd605ba57b41685cc656427c9b64cc37e84afac23ac6f3ffce1b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Caio Teixeira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# FipeApi
|
2
|
+
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/fipe_api.svg)][gem]
|
4
|
+
[![Build Status](http://img.shields.io/travis/caiofct/fipe_api.svg)][travis]
|
5
|
+
[![Dependency Status](http://img.shields.io/gemnasium/caiofct/fipe_api.svg)][gemnasium]
|
6
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/caiofct/fipe_api.svg)][codeclimate]
|
7
|
+
|
8
|
+
This application is a ruby client to the Tabela Fipe Api - http://www.fipe.org.br/pt-br/indices/veiculos/. It makes use the excellent http gem to make http requests and nokogiri to parse the response
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'fipe_api'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install fipe_api
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
The base class to use is a FipeApi::Vehicle. The Fipe data makes use of three Vehicles types wich are mapped to a FipeApi::Vehicle constant. The constants are:
|
29
|
+
|
30
|
+
FipeApi::Vehicle::CAR
|
31
|
+
FipeApi::Vehicle::MOTORCYCLE
|
32
|
+
FipeApi::Vehicle::TRUCK
|
33
|
+
|
34
|
+
You can get all Vehicles types with:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
vehicles = FipeApi::Vehicle.all
|
38
|
+
```
|
39
|
+
|
40
|
+
You can access the first vehicle like this:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
vehicles.first.id => 1
|
44
|
+
vehicles.first.name => Car
|
45
|
+
```
|
46
|
+
|
47
|
+
or you can initialize an specific Vehicle type, let`s say a CAR, with:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
vehicle = FipeApi::Vehicle.new(Vehicle::CAR, "Car")
|
51
|
+
```
|
52
|
+
|
53
|
+
Given a vehicle you can get all of its tables. A Table is generated each month with updated values for some vehicles. So, to get all tables you may do:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
tables = vehicle.get_tables
|
57
|
+
```
|
58
|
+
|
59
|
+
Frequently you will be using the latest table generated, i.e. that was generated for the current month and year, to get the vehicles data. It`s possible to
|
60
|
+
retrieve the latest table for an specific vehicle with:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
latest_table = Table.latest(vehicle)
|
64
|
+
```
|
65
|
+
|
66
|
+
or you can get a table for an specific month and year:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
table = Table.find_by_month_and_year(vehicle, 3, 2015) # Table from March/2015
|
70
|
+
```
|
71
|
+
|
72
|
+
Once you have a vehicle and a given table, you can get all of the vehicle`s Brands(Ford, Fiat, GM/Chevrolet, BMW, etc...), like so:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
brands = vehicle.get_brands(table) #If you don`t pass a table, it will use the latest table for the vehicle.
|
76
|
+
```
|
77
|
+
|
78
|
+
Now you can retrieve all Models for an specific brand. For the Ford brand we have as examples of models: Fiesta, Fusion, Taurus, etc. Use this syntax to get
|
79
|
+
all models:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
models = brand.get_models(table) #If you don`t pass a table, it will use the latest table for the vehicle.
|
83
|
+
```
|
84
|
+
|
85
|
+
Now, let`s get the years of a model. Examples of years, for a Ford Fusion Titanium 2.0 GTDI EcoBo. Awd Aut, are: Zero KM Gasolina, 2015 Gasolina, 2014 Gasolina, 2013 Gasolina.
|
86
|
+
You can get the years with:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
years = model.get_years(table) #If you don`t pass a table, it will use the latest table for the vehicle.
|
90
|
+
```
|
91
|
+
|
92
|
+
Finally, once you have an specific year for a vehicle, it`s possible to get its price like the following:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
result = year.get_result(table) #If you don`t pass a table, it will use the latest table for the vehicle.
|
96
|
+
|
97
|
+
# Result of type FipeApi::FipeResult
|
98
|
+
result.price # => R$ 124.638,00
|
99
|
+
result.authentication # => g1gj386ctbp
|
100
|
+
result.year # => FipeApi::Year(month: 7, year: 2015)
|
101
|
+
result.fuel # => Gasolina
|
102
|
+
result.query_time # => quinta-feira, 9 de julho de 2015 09:54:03
|
103
|
+
result.url #=> http://www.fipe.org.br/pt-br/indices/veiculos/carro/ford/7-2015/003376-6/32000/g/g1gj386ctbp
|
104
|
+
```
|
105
|
+
|
106
|
+
## Development
|
107
|
+
|
108
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
109
|
+
|
110
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
111
|
+
|
112
|
+
## Contributing
|
113
|
+
|
114
|
+
1. Fork it ( https://github.com/[my-github-username]/fipe_api/fork )
|
115
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
116
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
117
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
118
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fipe_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/fipe_api.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fipe_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fipe_api"
|
8
|
+
spec.version = FipeApi::VERSION
|
9
|
+
spec.authors = ["Caio Teixeira"]
|
10
|
+
spec.email = ["caiofct@ifce.edu.br"]
|
11
|
+
|
12
|
+
spec.summary = %q{A ruby client to consume Tabela Fipe api data - http://www.fipe.org.br/pt-br/indices/veiculos/}
|
13
|
+
spec.description = %q{This application is a ruby client to the Tabela Fipe Api - http://www.fipe.org.br/pt-br/indices/veiculos/. It makes use the excellent http gem to make http requests and nokogiri to parse the response.}
|
14
|
+
spec.homepage = "https://github.com/caiofct/fipe_api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
25
|
+
spec.add_development_dependency "nokogiri", "~> 1.6"
|
26
|
+
spec.add_development_dependency "http", "~> 0.8"
|
27
|
+
spec.add_development_dependency "byebug", "~> 5.0"
|
28
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FipeApi
|
2
|
+
class Brand < FipeApi::Base
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :vehicle
|
6
|
+
attr_accessor :table
|
7
|
+
|
8
|
+
def initialize(id, name, table, vehicle)
|
9
|
+
self.id = id
|
10
|
+
self.name = name
|
11
|
+
self.table = table
|
12
|
+
self.vehicle = vehicle
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_models(table = nil)
|
16
|
+
if table.nil?
|
17
|
+
table = Table.latest(self.vehicle)
|
18
|
+
end
|
19
|
+
|
20
|
+
response = HTTP.post("http://www.fipe.org.br/IndicesConsulta-ConsultarModelos",
|
21
|
+
params: {
|
22
|
+
codigoTabelaReferencia: table.id,
|
23
|
+
codigoTipoVeiculo: self.vehicle.id,
|
24
|
+
codigoMarca: self.id
|
25
|
+
},
|
26
|
+
body: {}.to_json).to_s
|
27
|
+
models_hash = JSON.parse(response)
|
28
|
+
models_result = []
|
29
|
+
models_hash["Modelos"].each do |model|
|
30
|
+
models_result << Model.new(model["Value"], model["Label"], self)
|
31
|
+
end
|
32
|
+
|
33
|
+
models_result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module FipeApi
|
2
|
+
class FipeResult < FipeApi::Base
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :authentication
|
5
|
+
attr_accessor :year
|
6
|
+
attr_accessor :fuel
|
7
|
+
attr_accessor :price
|
8
|
+
attr_accessor :query_time
|
9
|
+
|
10
|
+
def initialize(id, year, fuel, authentication, price, query_time)
|
11
|
+
self.id = id
|
12
|
+
self.authentication = authentication
|
13
|
+
self.year = year
|
14
|
+
self.fuel = fuel
|
15
|
+
self.price = price
|
16
|
+
self.query_time = query_time
|
17
|
+
end
|
18
|
+
|
19
|
+
#http://www.fipe.org.br/pt-br/indices/veiculos/carro/ford/7-2015/003376-6/32000/g/g1gj386ctbp
|
20
|
+
def url
|
21
|
+
"http://www.fipe.org.br/pt-br/indices/veiculos/#{year.model.brand.vehicle.name_id}/" +
|
22
|
+
"#{year.model.brand.name.downcase}/#{year.model.brand.table.month}-#{year.model.brand.table.year}/" +
|
23
|
+
"#{self.id}/#{self.year.id}/g/#{self.authentication}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module FipeApi
|
2
|
+
class Model < FipeApi::Base
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :brand
|
6
|
+
|
7
|
+
def initialize(id, name, brand)
|
8
|
+
self.id = id
|
9
|
+
self.name = name
|
10
|
+
self.brand = brand
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_years(table = nil)
|
14
|
+
if table.nil?
|
15
|
+
table = Table.latest(self.brand.vehicle)
|
16
|
+
end
|
17
|
+
|
18
|
+
response = HTTP.post("http://www.fipe.org.br/IndicesConsulta-ConsultarAnoModelo",
|
19
|
+
params: {
|
20
|
+
codigoTabelaReferencia: table.id,
|
21
|
+
codigoTipoVeiculo: self.brand.vehicle.id,
|
22
|
+
codigoMarca: self.brand.id,
|
23
|
+
codigoModelo: self.id,
|
24
|
+
},
|
25
|
+
body: {}.to_json).to_s
|
26
|
+
years_hash = JSON.parse(response)
|
27
|
+
years_result = []
|
28
|
+
years_hash.each do |year|
|
29
|
+
years_result << Year.new(year["Value"], year["Label"], self)
|
30
|
+
end
|
31
|
+
|
32
|
+
years_result
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module FipeApi
|
2
|
+
# Describes a Fipe Table whichi is generated each month with updated values for some vehicles
|
3
|
+
class Table < FipeApi::Base
|
4
|
+
attr_accessor :id
|
5
|
+
attr_accessor :month
|
6
|
+
attr_accessor :year
|
7
|
+
|
8
|
+
# Constructor
|
9
|
+
def initialize(id, month, year)
|
10
|
+
self.id = id
|
11
|
+
self.month = month
|
12
|
+
self.year = year
|
13
|
+
end
|
14
|
+
|
15
|
+
# Gets all tables for an specific vehicle
|
16
|
+
def self.all(vehicle)
|
17
|
+
return [] if vehicle.nil?
|
18
|
+
tables = []
|
19
|
+
doc = Nokogiri::HTML(HTTP.get("http://www.fipe.org.br/pt-br/indices/veiculos/").to_s)
|
20
|
+
doc.css("#selectTabelaReferencia#{vehicle.name_id} option").each do |option|
|
21
|
+
if option.text != ""
|
22
|
+
parts = option.text.strip.split("/")
|
23
|
+
tables << Table.new(option.attr('value'), Utils.month_name_to_int(parts[0]), parts[1].to_i)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
tables
|
28
|
+
end
|
29
|
+
|
30
|
+
# Gets the latest table, for current month and year, for an specific vehicle
|
31
|
+
def self.latest(vehicle)
|
32
|
+
return nil if vehicle.nil? || !vehicle.kind_of?(FipeApi::Vehicle)
|
33
|
+
table = nil
|
34
|
+
doc = Nokogiri::HTML(HTTP.get("http://www.fipe.org.br/pt-br/indices/veiculos/").to_s)
|
35
|
+
first_option = doc.css("#selectTabelaReferencia#{vehicle.name_id} option").first
|
36
|
+
if first_option.text != ""
|
37
|
+
parts = first_option.text.strip.split("/")
|
38
|
+
table = Table.new(first_option.attr('value'), Utils.month_name_to_int(parts[0]), parts[1].to_i)
|
39
|
+
end
|
40
|
+
table
|
41
|
+
end
|
42
|
+
|
43
|
+
# Gets a table for a certain month and year and for an specific vehicle
|
44
|
+
def self.find_by_month_and_year(vehicle, month, year)
|
45
|
+
return nil if vehicle.nil? || !vehicle.kind_of?(FipeApi::Vehicle)
|
46
|
+
result = nil
|
47
|
+
tables = self.all(vehicle)
|
48
|
+
tables.each do |table|
|
49
|
+
if table.month == month && table.year == year
|
50
|
+
result = table
|
51
|
+
break
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
result
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module FipeApi
|
2
|
+
class Vehicle < FipeApi::Base
|
3
|
+
CAR = 1
|
4
|
+
MOTORCYCLE = 2
|
5
|
+
TRUCK = 3
|
6
|
+
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :name
|
9
|
+
|
10
|
+
def initialize(id, name)
|
11
|
+
self.id = id
|
12
|
+
self.name = name
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.all
|
16
|
+
[Vehicle.new(CAR, "Car"),
|
17
|
+
Vehicle.new(MOTORCYCLE, "Motorcycle"),
|
18
|
+
Vehicle.new(TRUCK, "Truck")]
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_tables
|
22
|
+
Table.all(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_brands(table = nil)
|
26
|
+
if table.nil?
|
27
|
+
table = Table.latest(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
response = HTTP.post("http://www.fipe.org.br/IndicesConsulta-ConsultarMarcas", params: { codigoTabelaReferencia: table.id, codigoTipoVeiculo: self.id }, body: {}.to_json).to_s
|
31
|
+
brands_hash = JSON.parse(response)
|
32
|
+
brands_result = []
|
33
|
+
brands_hash.each do |brand|
|
34
|
+
brands_result << Brand.new(brand["Value"], brand["Label"], table, self)
|
35
|
+
end
|
36
|
+
|
37
|
+
brands_result
|
38
|
+
end
|
39
|
+
|
40
|
+
def name_id
|
41
|
+
case id
|
42
|
+
when CAR
|
43
|
+
return "carro"
|
44
|
+
when MOTORCYCLE
|
45
|
+
return "moto"
|
46
|
+
when TRUCK
|
47
|
+
return "caminhao"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module FipeApi
|
2
|
+
class Year < FipeApi::Base
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :model
|
6
|
+
attr_accessor :fuel
|
7
|
+
|
8
|
+
def initialize(id, name, model)
|
9
|
+
self.id = id.split("-")[0]
|
10
|
+
self.fuel = id.split("-")[1]
|
11
|
+
self.name = name
|
12
|
+
self.model = model
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_result(table = nil)
|
16
|
+
if table.nil?
|
17
|
+
table = Table.latest(self.model.brand.vehicle)
|
18
|
+
end
|
19
|
+
|
20
|
+
response = HTTP.post("http://www.fipe.org.br/IndicesConsulta-ConsultarValorComTodosParametros",
|
21
|
+
params: {
|
22
|
+
codigoTabelaReferencia: table.id,
|
23
|
+
codigoTipoVeiculo: self.model.brand.vehicle.id,
|
24
|
+
codigoMarca: self.model.brand.id,
|
25
|
+
codigoModelo: self.model.id,
|
26
|
+
anoModelo: self.id,
|
27
|
+
codigoTipoCombustivel: self.fuel,
|
28
|
+
tipoVeiculo: self.model.brand.vehicle.name_id,
|
29
|
+
tipoConsulta: "tradicional"
|
30
|
+
},
|
31
|
+
body: {}.to_json).to_s
|
32
|
+
result_json = JSON.parse(response)
|
33
|
+
fipe_result = nil
|
34
|
+
if !result_json.nil?
|
35
|
+
fipe_result = FipeResult.new(result_json["CodigoFipe"].strip,
|
36
|
+
self,
|
37
|
+
result_json["Combustivel"],
|
38
|
+
result_json["Autenticacao"],
|
39
|
+
result_json["Valor"],
|
40
|
+
result_json["DataConsulta"])
|
41
|
+
end
|
42
|
+
|
43
|
+
fipe_result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/fipe_api.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require "fipe_api/version"
|
2
|
+
require "fipe_api/base"
|
3
|
+
require "fipe_api/utils"
|
4
|
+
require "fipe_api/resources/vehicle"
|
5
|
+
require "fipe_api/resources/table"
|
6
|
+
require "fipe_api/resources/brand"
|
7
|
+
require "fipe_api/resources/model"
|
8
|
+
require "fipe_api/resources/year"
|
9
|
+
require "fipe_api/resources/fipe_result"
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fipe_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caio Teixeira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: http
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
description: This application is a ruby client to the Tabela Fipe Api - http://www.fipe.org.br/pt-br/indices/veiculos/.
|
98
|
+
It makes use the excellent http gem to make http requests and nokogiri to parse
|
99
|
+
the response.
|
100
|
+
email:
|
101
|
+
- caiofct@ifce.edu.br
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- fipe_api.gemspec
|
117
|
+
- lib/fipe_api.rb
|
118
|
+
- lib/fipe_api/base.rb
|
119
|
+
- lib/fipe_api/resources/brand.rb
|
120
|
+
- lib/fipe_api/resources/fipe_result.rb
|
121
|
+
- lib/fipe_api/resources/model.rb
|
122
|
+
- lib/fipe_api/resources/table.rb
|
123
|
+
- lib/fipe_api/resources/vehicle.rb
|
124
|
+
- lib/fipe_api/resources/year.rb
|
125
|
+
- lib/fipe_api/utils.rb
|
126
|
+
- lib/fipe_api/version.rb
|
127
|
+
homepage: https://github.com/caiofct/fipe_api
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.4.6
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: A ruby client to consume Tabela Fipe api data - http://www.fipe.org.br/pt-br/indices/veiculos/
|
151
|
+
test_files: []
|