fipeapi 0.1.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7972f7912481dbadd76f33d32f388325fa11b0ee
4
+ data.tar.gz: c51629c56ab54f75df8f1944f1981f6e9dc31db3
5
+ SHA512:
6
+ metadata.gz: 4cc26cea8f5abe36eacdeee5c15912374fe59b2fb4ace792154c4eeaed2ddf8c5fa70e666c26bea30d07745d5aa3139ff714f73b1bbe1cf2c7ff3475637a581a
7
+ data.tar.gz: b23a26c7099b1479c785e0fcc9902541769ba19c64b9c7c15fb264c3e6543ef4b9814aafbc21517794213446c0f85305b5959c9e407d328de9c9941608e20ae4
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at eusou@rafaelalmeida.net. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fipeapi.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Rafael da Silva Almeida
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.
@@ -0,0 +1,113 @@
1
+ # FipeApi
2
+
3
+ Bom, se você precisa consultar em tempo real a base da FIPE, esse é o projeto
4
+ que você quer usar.
5
+
6
+ Nós usamos a [fipeapi.appspot](http://fipeapi.appspot.com/), uma api para a
7
+ base da FIPE e devolvemos objetos para todos os requests.
8
+
9
+ OBS: *Não temos como garantir a disponibilidade da API, e nem nós, nem os
10
+ programadores responsáveis pela API nos responsabilizamos por danos gerados pela
11
+ instabilidade no serviço*
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'fipeapi'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install fipeapi
28
+
29
+ ## Usage
30
+
31
+
32
+ ```
33
+ [1] pry(main)> marca = FipeApi::Marca.todas.first
34
+ => #<FipeApi::Marca:0x0000000330ca20 @fipe_name="Audi", @id=6, @key="audi-6", @name="AUDI", @order=2, @tipo_do_veiculo="carros">
35
+ [2] pry(main)> veiculo = FipeApi::Veiculo.por_marca('carro', '21').first
36
+ => #<FipeApi::Veiculo:0x00000003534b68
37
+ @fipe_marca="Fiat",
38
+ @fipe_name="147 C/ CL",
39
+ @id="437",
40
+ @id_marca="21",
41
+ @key="147-437",
42
+ @marca="FIAT",
43
+ @name="147 C/ CL",
44
+ @tipo="carro">
45
+ [3] pry(main)> modelo = FipeApi::Modelo.por_marca_e_id_do_veiculo('carro', '21', '4828').first
46
+ => #<FipeApi::Modelo:0x00000001a92f30
47
+ @fipe_codigo="2014-1",
48
+ @fipe_marca="Fiat",
49
+ @id="2014-1",
50
+ @id_marca="21",
51
+ @id_veiculo="4828",
52
+ @key="2014-1",
53
+ @marca="FIAT",
54
+ @name="2014 Gasolina",
55
+ @tipo_do_veiculo="carro",
56
+ @veiculo="Palio 1.0 ECONOMY Fire Flex 8V 4p">
57
+ [4] pry(main)> preco = FipeApi::Preco.por_marca_codigo_do_veiculo_e_ano('carro', '21', '4828', '2014-1')
58
+ => #<FipeApi::Preco:0x00000003670db0
59
+ @ano_modelo="2014",
60
+ @combustivel="Gasolina",
61
+ @fipe_codigo="001267-0",
62
+ @id="2014",
63
+ @key="palio-2014",
64
+ @marca="Fiat",
65
+ @name="Palio 1.0 ECONOMY Fire Flex 8V 4p",
66
+ @preco="R$ 24.541,00",
67
+ @referencia="abril de 2016",
68
+ @time=0.0,
69
+ @veiculo="Palio 1.0 ECONOMY Fire Flex 8V 4p">
70
+ [5] pry(main)>
71
+ [6] pry(main)> marca = FipeApi::Marca.todas.first
72
+ => #<FipeApi::Marca:0x000000034f7470 @fipe_name="Audi", @id=6, @key="audi-6", @name="AUDI", @order=2, @tipo_do_veiculo="carros">
73
+ [7] pry(main)> veiculo = marca.veiculos.first
74
+ => #<FipeApi::Veiculo:0x000000031e3590
75
+ @fipe_marca="Audi",
76
+ @fipe_name="100 2.8 V6",
77
+ @id="43",
78
+ @id_marca=6,
79
+ @key="100-43",
80
+ @marca="AUDI",
81
+ @name="100 2.8 V6",
82
+ @tipo="carros">
83
+ [8] pry(main)> modelo = veiculo.modelos.first
84
+ => #<FipeApi::Modelo:0x000000030c2ad0
85
+ @fipe_codigo="1995-1",
86
+ @fipe_marca="Audi",
87
+ @id="1995-1",
88
+ @id_marca=6,
89
+ @id_veiculo="43",
90
+ @key="1995-1",
91
+ @marca="AUDI",
92
+ @name="1995 Gasolina",
93
+ @tipo_do_veiculo="carros",
94
+ @veiculo="100 2.8 V6">
95
+ [9] pry(main)> preco = modelo.preco
96
+ => #<FipeApi::Preco:0x000000030051b0
97
+ @ano_modelo="1995",
98
+ @combustivel="Gasolina",
99
+ @fipe_codigo="008030-6",
100
+ @id="1995",
101
+ @key="100-1995",
102
+ @marca="Audi",
103
+ @name="100 2.8 V6",
104
+ @preco="R$ 14.980,00",
105
+ @referencia="abril de 2016",
106
+ @time=0.009999999999990905,
107
+ @veiculo="100 2.8 V6">
108
+ ```
109
+
110
+ ## License
111
+
112
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
113
+
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fipeapi"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fipeapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fipeapi'
8
+ spec.version = FipeApi::VERSION
9
+ spec.authors = ['Rafael da Silva Almeida']
10
+ spec.email = ['eusou@rafaelalmeida.net']
11
+
12
+ spec.summary = %q{Consulte a FipeApi.}
13
+ spec.homepage = 'http://github.com/stupied4ever/fipeapi'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'httparty', '0.13'
22
+ spec.add_development_dependency 'bundler', '~> 1.11'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'fipeapi/version'
2
+ require 'httparty'
3
+ require_relative 'fipeapi/objeto_com_construtor'
4
+ require_relative 'fipeapi/marca'
5
+ require_relative 'fipeapi/veiculo'
6
+ require_relative 'fipeapi/modelo'
7
+ require_relative 'fipeapi/preco'
8
+
9
+ module FipeApi
10
+ API_URL = 'http://fipeapi.appspot.com/api/1'
11
+ CARRO = 'carros'
12
+ MOTO = 'motos'
13
+ CAMINHAO = 'caminhoes'
14
+ TIPOS_DE_VEICULOS = [CARRO, MOTO, CAMINHAO].freeze
15
+ end
@@ -0,0 +1,24 @@
1
+ module FipeApi
2
+ class Marca
3
+ include ObjetoComConstrutor
4
+
5
+ attr_accessor :key, :id, :fipe_name, :name, :tipo_do_veiculo, :order
6
+
7
+ def self.todas(tipo_do_veiculo=CARRO)
8
+ HTTParty
9
+ .get("#{API_URL}/#{tipo_do_veiculo}/marcas.json")
10
+ .parsed_response.map { |marca| Marca.new(tipo_do_veiculo, marca) }
11
+ end
12
+
13
+ def initialize(tipo_do_veiculo, opts = {})
14
+ self.tipo_do_veiculo = tipo_do_veiculo
15
+ self.id = tipo_do_veiculo
16
+
17
+ super(opts)
18
+ end
19
+
20
+ def veiculos
21
+ Veiculo.por_marca(tipo_do_veiculo, id)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ module FipeApi
2
+ class Modelo
3
+ include ObjetoComConstrutor
4
+
5
+ attr_accessor :fipe_marca, :fipe_codigo, :name, :marca, :key, :veiculo,
6
+ :id, :id_veiculo, :tipo_do_veiculo, :id_marca
7
+
8
+ def initialize(tipo_do_veiculo, id_marca, id_veiculo, opts = {})
9
+ self.tipo_do_veiculo = tipo_do_veiculo
10
+ self.id_marca = id_marca
11
+ self.id_veiculo = id_veiculo
12
+
13
+ super(opts)
14
+ end
15
+
16
+ def self.por_marca_e_id_do_veiculo(
17
+ tipo_do_veiculo,
18
+ id_marca,
19
+ codigo_veiculo
20
+ )
21
+ HTTParty
22
+ .get(endpoint(tipo_do_veiculo, id_marca, codigo_veiculo))
23
+ .parsed_response.map do |modelo|
24
+ Modelo.new(tipo_do_veiculo, id_marca, codigo_veiculo, modelo)
25
+ end
26
+ end
27
+
28
+ def preco
29
+ Preco.por_marca_codigo_do_veiculo_e_ano(
30
+ tipo_do_veiculo,
31
+ id_marca,
32
+ id_veiculo,
33
+ key
34
+ )
35
+ end
36
+
37
+ private
38
+
39
+ def self.endpoint(tipo_do_veiculo, id_marca, codigo_veiculo)
40
+ "#{FipeApi::API_URL}/#{tipo_do_veiculo}/veiculo/#{id_marca}/" \
41
+ "#{codigo_veiculo}.json"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ module FipeApi
2
+ module ObjetoComConstrutor
3
+ def initialize(opts = {})
4
+ opts.keys.each do |key|
5
+ self.send("#{key}=", opts[key])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ module FipeApi
2
+ class Preco
3
+ include ObjetoComConstrutor
4
+
5
+ attr_accessor :referencia, :fipe_codigo, :name, :combustivel, :marca,
6
+ :ano_modelo, :preco, :key, :time, :veiculo, :id
7
+
8
+ def self.por_marca_codigo_do_veiculo_e_ano(
9
+ tipo_do_veiculo,
10
+ id_marca,
11
+ id_veiculo,
12
+ key_preco
13
+ )
14
+ Preco.new(
15
+ HTTParty
16
+ .get(endpoint(tipo_do_veiculo, id_marca, id_veiculo, key_preco))
17
+ .parsed_response
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ def self.endpoint(tipo_do_veiculo, id_marca, id_veiculo, key_preco)
24
+ "#{FipeApi::API_URL}/#{tipo_do_veiculo}/veiculo/#{id_marca}/" \
25
+ "#{id_veiculo}/#{key_preco}.json"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module FipeApi
2
+ class Veiculo
3
+ include ObjetoComConstrutor
4
+
5
+ attr_accessor :fipe_marca, :marca, :key, :id, :fipe_name, :tipo, :id_marca,
6
+ :name
7
+
8
+ def self.por_marca(tipo_do_veiculo, id_marca)
9
+ HTTParty
10
+ .get("#{API_URL}/#{tipo_do_veiculo}/veiculos/#{id_marca}.json")
11
+ .parsed_response.map do |veiculo|
12
+ Veiculo.new(tipo_do_veiculo, id_marca, veiculo)
13
+ end
14
+ end
15
+
16
+ def initialize(tipo, id_marca, opts = {})
17
+ self.tipo = tipo
18
+ self.id_marca = id_marca
19
+ super(opts)
20
+ end
21
+
22
+ def modelos
23
+ Modelo.por_marca_e_id_do_veiculo(
24
+ tipo,
25
+ id_marca,
26
+ id
27
+ )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module FipeApi
2
+ VERSION = '0.1.beta'
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fipeapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.beta
5
+ platform: ruby
6
+ authors:
7
+ - Rafael da Silva Almeida
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - eusou@rafaelalmeida.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - fipeapi.gemspec
87
+ - lib/fipeapi.rb
88
+ - lib/fipeapi/marca.rb
89
+ - lib/fipeapi/modelo.rb
90
+ - lib/fipeapi/objeto_com_construtor.rb
91
+ - lib/fipeapi/preco.rb
92
+ - lib/fipeapi/veiculo.rb
93
+ - lib/fipeapi/version.rb
94
+ homepage: http://github.com/stupied4ever/fipeapi
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">"
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.1
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Consulte a FipeApi.
118
+ test_files: []