fipe_api 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11e82b968e983b25767cf2205ceac52b3722b8bd
4
- data.tar.gz: 67d6962cd5691ab04decabf5a7787bbe2e201a34
3
+ metadata.gz: f0358ab75e6e72f7ebf6faf032da9838f267f535
4
+ data.tar.gz: c644953ebe9061facce589f862170674a91a5edf
5
5
  SHA512:
6
- metadata.gz: 4eff20d057c666b1a316f9d7bd9778e96a0d9049fa0f396e8a4d355857466bc00c43c0914762e8bad111613037eac901d069dee5fe76ccb3bfe7de6d07e01c24
7
- data.tar.gz: 9d7225a80365a58f495ac12c2565d5a9eaca408ff4327f42870d4a56df6d7a3dc44914771663375184547fb1c29369f1d54308faa8115ba1b69275a5f4b442f7
6
+ metadata.gz: d5268b71775cde9e86251d46c07e6fc0d216b2370e1057d802b4ae86d6d190b4028889025dfaff5587c8c0dc8d0fb36cb6cfb67600b337c4ac10c8c183c1b3ab
7
+ data.tar.gz: 169fcb47a9b622a8a7b61a2f25e0f914cd33fb7fcd573ab1a45f9d6e54dcbf69a6ab736cfa77b7c6f1ed2eea299d62a41e744714e22423ac26276df07f2b2436
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Caio Teixeira
3
+ Copyright (c) 2016 Caio Teixeira
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # FipeApi
2
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]
3
+ ![Gem Version](http://img.shields.io/gem/v/fipe_api.svg)
4
+ ![Build Status](http://img.shields.io/travis/caiofct/fipe_api.svg)
5
+ ![Dependency Status](http://img.shields.io/gemnasium/caiofct/fipe_api.svg)
6
+ ![Code Climate](http://img.shields.io/codeclimate/github/caiofct/fipe_api.svg)
7
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
8
+ This application is a ruby client to the Tabela Fipe Api - http://www.fipe.org.br/pt-br/indices/veiculos/. It makes use of the excellent http gem to make http requests and nokogiri to parse the response
9
9
 
10
10
  ## Installation
11
11
 
@@ -27,9 +27,9 @@ Or install it yourself as:
27
27
 
28
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
29
 
30
- FipeApi::Vehicle::CAR
31
- FipeApi::Vehicle::MOTORCYCLE
32
- FipeApi::Vehicle::TRUCK
30
+ * `FipeApi::Vehicle::CAR`
31
+ * `FipeApi::Vehicle::MOTORCYCLE`
32
+ * `FipeApi::Vehicle::TRUCK`
33
33
 
34
34
  You can get all Vehicles types with:
35
35
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Caio Teixeira"]
10
10
  spec.email = ["caiofct@ifce.edu.br"]
11
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.}
12
+ spec.summary = %q{A ruby client to consume Tabela Fipe api data - http://veiculos.fipe.org.br/}
13
+ spec.description = %q{This application is a ruby client to the Tabela Fipe Api - http://veiculos.fipe.org.br/. It makes use of the excellent http gem to make http requests and nokogiri to parse the responses.}
14
14
  spec.homepage = "https://github.com/caiofct/fipe_api"
15
15
  spec.license = "MIT"
16
16
 
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "byebug", "~> 5.0"
26
26
 
27
27
  spec.add_dependency 'nokogiri', '~> 1.6'
28
- spec.add_dependency 'http', '~> 0.8'
28
+ spec.add_dependency 'http', '~> 2.0'
29
29
 
30
- spec.required_ruby_version = '>= 1.9.3'
30
+ spec.required_ruby_version = '>= 2.0'
31
31
  spec.required_rubygems_version = '>= 1.3.5'
32
32
  end
@@ -1,3 +1,4 @@
1
+ require 'byebug'
1
2
  require "fipe_api/version"
2
3
  require "fipe_api/base"
3
4
  require "fipe_api/utils"
@@ -17,7 +17,7 @@ module FipeApi
17
17
  table = Table.latest(self.vehicle)
18
18
  end
19
19
 
20
- response = HTTP.post("http://www.fipe.org.br/IndicesConsulta-ConsultarModelos",
20
+ response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarModelos",
21
21
  params: {
22
22
  codigoTabelaReferencia: table.id,
23
23
  codigoTipoVeiculo: self.vehicle.id,
@@ -15,7 +15,7 @@ module FipeApi
15
15
  table = Table.latest(self.brand.vehicle)
16
16
  end
17
17
 
18
- response = HTTP.post("http://www.fipe.org.br/IndicesConsulta-ConsultarAnoModelo",
18
+ response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarAnoModelo",
19
19
  params: {
20
20
  codigoTabelaReferencia: table.id,
21
21
  codigoTipoVeiculo: self.brand.vehicle.id,
@@ -16,11 +16,12 @@ module FipeApi
16
16
  def self.all(vehicle)
17
17
  return [] if vehicle.nil?
18
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)
19
+ response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarTabelaDeReferencia", body: {}.to_json).to_s
20
+ tables_hash = JSON.parse(response)
21
+ tables_hash.each do |table|
22
+ if table["Mes"] != ""
23
+ parts = table["Mes"].strip.split("/")
24
+ tables << Table.new(table["Codigo"], Utils.month_name_to_int(parts[0]), parts[1].to_i)
24
25
  end
25
26
  end
26
27
 
@@ -31,11 +32,12 @@ module FipeApi
31
32
  def self.latest(vehicle)
32
33
  return nil if vehicle.nil? || !vehicle.kind_of?(FipeApi::Vehicle)
33
34
  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)
35
+ response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarTabelaDeReferencia", body: {}.to_json).to_s
36
+ table = JSON.parse(response).first
37
+ # first_option = doc.css("#selectTabelaReferencia#{vehicle.name_id} option").first
38
+ if table["Mes"] != ""
39
+ parts = table["Mes"].strip.split("/")
40
+ table = Table.new(table["Codigo"], Utils.month_name_to_int(parts[0]), parts[1].to_i)
39
41
  end
40
42
  table
41
43
  end
@@ -45,6 +47,7 @@ module FipeApi
45
47
  return nil if vehicle.nil? || !vehicle.kind_of?(FipeApi::Vehicle)
46
48
  result = nil
47
49
  tables = self.all(vehicle)
50
+
48
51
  tables.each do |table|
49
52
  if table.month == month && table.year == year
50
53
  result = table
@@ -27,7 +27,7 @@ module FipeApi
27
27
  table = Table.latest(self)
28
28
  end
29
29
 
30
- response = HTTP.post("http://www.fipe.org.br/IndicesConsulta-ConsultarMarcas", params: { codigoTabelaReferencia: table.id, codigoTipoVeiculo: self.id }, body: {}.to_json).to_s
30
+ response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarMarcas", params: { codigoTabelaReferencia: table.id, codigoTipoVeiculo: self.id }, body: {}.to_json).to_s
31
31
  brands_hash = JSON.parse(response)
32
32
  brands_result = []
33
33
  brands_hash.each do |brand|
@@ -17,7 +17,7 @@ module FipeApi
17
17
  table = Table.latest(self.model.brand.vehicle)
18
18
  end
19
19
 
20
- response = HTTP.post("http://www.fipe.org.br/IndicesConsulta-ConsultarValorComTodosParametros",
20
+ response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarValorComTodosParametros",
21
21
  params: {
22
22
  codigoTabelaReferencia: table.id,
23
23
  codigoTipoVeiculo: self.model.brand.vehicle.id,
@@ -1,3 +1,3 @@
1
1
  module FipeApi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fipe_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Teixeira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,17 +86,17 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.8'
89
+ version: '2.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.8'
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.
96
+ version: '2.0'
97
+ description: This application is a ruby client to the Tabela Fipe Api - http://veiculos.fipe.org.br/.
98
+ It makes use of the excellent http gem to make http requests and nokogiri to parse
99
+ the responses.
100
100
  email:
101
101
  - caiofct@ifce.edu.br
102
102
  executables: []
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 1.9.3
139
+ version: '2.0'
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - ">="
@@ -144,8 +144,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: 1.3.5
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.4.6
147
+ rubygems_version: 2.5.1
148
148
  signing_key:
149
149
  specification_version: 4
150
- summary: A ruby client to consume Tabela Fipe api data - http://www.fipe.org.br/pt-br/indices/veiculos/
150
+ summary: A ruby client to consume Tabela Fipe api data - http://veiculos.fipe.org.br/
151
151
  test_files: []
152
+ has_rdoc: