fipextractor 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +50 -50
  3. data/.rspec +3 -0
  4. data/.rspec_status +31 -0
  5. data/.travis.yml +7 -0
  6. data/Gemfile +7 -3
  7. data/LICENSE +21 -0
  8. data/README.md +88 -118
  9. data/Rakefile +6 -10
  10. data/fipextractor.gemspec +29 -21
  11. data/lib/fipextractor.rb +9 -40
  12. data/lib/fipextractor/brand.rb +24 -0
  13. data/lib/fipextractor/brand_response.rb +7 -0
  14. data/lib/fipextractor/converter/vehicle_type.rb +16 -0
  15. data/lib/fipextractor/model.rb +26 -0
  16. data/lib/fipextractor/model_response.rb +15 -0
  17. data/lib/fipextractor/model_through_year.rb +30 -0
  18. data/lib/fipextractor/model_through_year_response.rb +7 -0
  19. data/lib/fipextractor/model_year.rb +28 -0
  20. data/lib/fipextractor/model_year_response.rb +7 -0
  21. data/lib/fipextractor/reference_table.rb +10 -0
  22. data/lib/fipextractor/reference_table_response.rb +7 -0
  23. data/lib/fipextractor/request.rb +53 -0
  24. data/lib/fipextractor/resource.rb +10 -0
  25. data/lib/fipextractor/response.rb +16 -0
  26. data/lib/fipextractor/vehicle.rb +39 -0
  27. data/lib/fipextractor/vehicle_response.rb +7 -0
  28. data/lib/fipextractor/version.rb +3 -0
  29. metadata +67 -33
  30. data/lib/fipextractor/api_parameter/parameter_converter.rb +0 -39
  31. data/lib/fipextractor/api_parameter/parameter_validator.rb +0 -46
  32. data/lib/fipextractor/api_response/brand_response_converter.rb +0 -10
  33. data/lib/fipextractor/api_response/model_response_converter.rb +0 -45
  34. data/lib/fipextractor/api_response/model_through_year_response_converter.rb +0 -10
  35. data/lib/fipextractor/api_response/response_converter.rb +0 -60
  36. data/lib/fipextractor/api_response/response_converter_builder.rb +0 -22
  37. data/lib/fipextractor/fipe_api/api_factory.rb +0 -12
  38. data/lib/fipextractor/fipe_api/api_requester.rb +0 -49
  39. data/lib/fipextractor/fipe_api/api_response.rb +0 -23
  40. data/test/parameter_converter_spec.rb +0 -23
  41. data/test/parameter_validator_spec.rb +0 -67
  42. data/test/response_converter_spec.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86bfa1930e1374a1c6e65b1b466f6103ae0da70a
4
- data.tar.gz: 3bbd65e7bebeef4ce48afaa6a9e92a2d57fd2136
3
+ metadata.gz: 947417125d10b74d823ed81ebc3834a8ac6d505d
4
+ data.tar.gz: 51ef7702055873c3db28fa3d088ed95c7144b209
5
5
  SHA512:
6
- metadata.gz: ab6ba54eedef1e09c98ba6c4d51847252061dd313169eb15593eb53a4b6d616609a07128bc0541138a0970b2bc4fca34937e612af89b9013952512711658ebcb
7
- data.tar.gz: 426aa8c17105c2a2c735f52b1b17cf7beee7efd7747dc029b6e566cf495e487d04fd83c570e35442e90947d7f8f5ba6762e73e4b82742f8455cc4331411872cb
6
+ metadata.gz: 5f57812ad1e28187eacddda651ca87db6844a2adee0058f862aa359cd25562b1bdfacfec04812e61cb0ac6f935a3342e19cc2c1c0417ec07ab89922bf695c43d
7
+ data.tar.gz: e634ac79351a2691182c9fd63e9c7aae1a05c540ea6f16c2048feb6df8da0dc1ad39ff96a7548d5f87e630be98a646285448b8ab0a6873bcc1fbc73e348ec873
data/.gitignore CHANGED
@@ -1,50 +1,50 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /spec/examples.txt
9
- /test/tmp/
10
- /test/version_tmp/
11
- /tmp/
12
-
13
- # Used by dotenv library to load environment variables.
14
- # .env
15
-
16
- ## Specific to RubyMotion:
17
- .dat*
18
- .repl_history
19
- build/
20
- *.bridgesupport
21
- build-iPhoneOS/
22
- build-iPhoneSimulator/
23
-
24
- ## Specific to RubyMotion (use of CocoaPods):
25
- #
26
- # We recommend against adding the Pods directory to your .gitignore. However
27
- # you should judge for yourself, the pros and cons are mentioned at:
28
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
- #
30
- # vendor/Pods/
31
-
32
- ## Documentation cache and generated files:
33
- /.yardoc/
34
- /_yardoc/
35
- /doc/
36
- /rdoc/
37
-
38
- ## Environment normalization:
39
- /.bundle/
40
- /vendor/bundle
41
- /lib/bundler/man/
42
-
43
- # for a library or gem, you might want to ignore these files since the code is
44
- # intended to run in multiple environments; otherwise, check them in:
45
- Gemfile.lock
46
- # .ruby-version
47
- # .ruby-gemset
48
-
49
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
- .rvmrc
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,31 @@
1
+ example_id | status | run_time |
2
+ --------------------------------------------------------------- | ------ | --------------- |
3
+ ./spec/lib/fipextractor/brand_spec.rb[1:1:1] | passed | 0.00105 seconds |
4
+ ./spec/lib/fipextractor/brand_spec.rb[1:2:1] | passed | 0.00031 seconds |
5
+ ./spec/lib/fipextractor/converter/vehicle_type_spec.rb[1:1:1:1] | passed | 0.00016 seconds |
6
+ ./spec/lib/fipextractor/converter/vehicle_type_spec.rb[1:1:2:1] | passed | 0.00013 seconds |
7
+ ./spec/lib/fipextractor/converter/vehicle_type_spec.rb[1:1:3:1] | passed | 0.00012 seconds |
8
+ ./spec/lib/fipextractor/converter/vehicle_type_spec.rb[1:1:4:1] | passed | 0.00013 seconds |
9
+ ./spec/lib/fipextractor/model_response_spec.rb[1:1:1] | passed | 0.00044 seconds |
10
+ ./spec/lib/fipextractor/model_response_spec.rb[1:2:1] | passed | 0.00028 seconds |
11
+ ./spec/lib/fipextractor/model_spec.rb[1:1:1] | passed | 0.00022 seconds |
12
+ ./spec/lib/fipextractor/model_spec.rb[1:2:1] | passed | 0.0003 seconds |
13
+ ./spec/lib/fipextractor/model_through_year_spec.rb[1:1:1] | passed | 0.0002 seconds |
14
+ ./spec/lib/fipextractor/model_through_year_spec.rb[1:2:1:1] | passed | 0.00052 seconds |
15
+ ./spec/lib/fipextractor/model_through_year_spec.rb[1:2:1:2:1] | passed | 0.00034 seconds |
16
+ ./spec/lib/fipextractor/model_year_spec.rb[1:1:1] | passed | 0.00015 seconds |
17
+ ./spec/lib/fipextractor/model_year_spec.rb[1:2:1] | passed | 0.00025 seconds |
18
+ ./spec/lib/fipextractor/reference_table_spec.rb[1:1:1] | passed | 0.0002 seconds |
19
+ ./spec/lib/fipextractor/request_spec.rb[1:1:1:1] | passed | 0.0072 seconds |
20
+ ./spec/lib/fipextractor/request_spec.rb[1:1:2:1] | passed | 0.0016 seconds |
21
+ ./spec/lib/fipextractor/request_spec.rb[1:2:1] | passed | 0.00311 seconds |
22
+ ./spec/lib/fipextractor/request_spec.rb[1:3:1] | passed | 0.00017 seconds |
23
+ ./spec/lib/fipextractor/request_spec.rb[1:4:1] | passed | 0.00035 seconds |
24
+ ./spec/lib/fipextractor/request_spec.rb[1:5:1] | passed | 0.00079 seconds |
25
+ ./spec/lib/fipextractor/request_spec.rb[1:6:1] | passed | 0.00022 seconds |
26
+ ./spec/lib/fipextractor/request_spec.rb[1:7:1] | passed | 0.00043 seconds |
27
+ ./spec/lib/fipextractor/resource_spec.rb[1:1:1] | passed | 0.0004 seconds |
28
+ ./spec/lib/fipextractor/response_spec.rb[1:1:1:1] | passed | 0.00034 seconds |
29
+ ./spec/lib/fipextractor/response_spec.rb[1:1:2:1] | passed | 0.00035 seconds |
30
+ ./spec/lib/fipextractor/vehicle_spec.rb[1:1:1] | passed | 0.00023 seconds |
31
+ ./spec/lib/fipextractor/vehicle_spec.rb[1:2:1] | passed | 0.00043 seconds |
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.0
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'coveralls', require: false
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Henrique Aparecido Lavezzo
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,118 +1,88 @@
1
- ## FipExtractor
2
- ---
3
- FipExtractor is a easy-to-use translator of the FIPE API.
4
-
5
- Actually FIPE only release the information about their vehicle market search on
6
- your website. To get information generally you need to do many DOM manipulations,
7
- with your user common behaviour (clicking in selects, and buttons).
8
-
9
- FipExtractor is here for you! We consumes the FIPE API directly, and
10
- translates the some parameters that have non-sense labels. Making this gem more useful for you.
11
-
12
- ### Using FipExtractor
13
- ---
14
-
15
- FipExtractor only provides a easy way to consume FIPE informations, we don't create any
16
- conversions to generate SQL, or another way to insert data into databases.
17
- You can do this with the FipExtractor application result data.
18
-
19
- We use the FIPE API, and with this information, we clearly need to work under their
20
- API rules. FipExtractor provides a validator that shows to you if your request parameters
21
- are malformed.
22
-
23
- FipExtractor creates a huge and simple abstraction around API requests.
24
-
25
- The API routes are:
26
-
27
- |Route|Parameters|
28
- |------|----------|
29
- |reference_table|none|
30
- |brand|reference_table_id, vehicle_type|
31
- |model|reference_table_id, vehicle_type, brand_id|
32
- |model_through_year|reference_table_id, vehicle_type, brand_id, model_id|
33
- |model_year|reference_table_id, vehicle_type, brand_id, model_id, year, model_year, fuel_type_id|
34
- |full|reference_table_id, vehicle_type, brand_id, model_id, year, model_year, fuel_type_id, vehicle_type|
35
-
36
- ---
37
- #### Building a request
38
-
39
- ````ruby
40
- extractor = FipExtractor.new(:full, {reference_table_id: 189, vehicle_type: :car, brand_id: 3, model_id: 7, model_year: "1999", year: "1999", fuel_type_id: 1})
41
- ````
42
-
43
- You only need to create your FipExtractor object, and fill the parameters ``method`` and ``parameters``
44
-
45
- The ``method`` only accepts the Symbol reference.
46
-
47
- The ``parameters`` only accepts a Hash. (optional on ``:reference_table`` method)
48
-
49
- ---
50
- #### Checking the request parameters
51
-
52
- FipExtractor allows to submit a request directly, or check your parameters. You can choose, if you will validate your parameters, or not.
53
-
54
- Example of validation:
55
-
56
- ````ruby
57
- extractor = FipExtractor.new(:brand, {reference_table_id: 189, vehicle_type: :truck})
58
- validator = extractor.validate_parameters
59
- if validator.is_ok?
60
- api = extractor.request
61
- api = api.send
62
- puts api.response
63
- else
64
- puts validator.message
65
- end
66
- ````
67
-
68
- The validation layer is a object like everything in Ruby. Calling ``validate_parameters``, you automatic validate your parameters and generate a object with the ``is_ok?`` and ``message`` methods.
69
-
70
- ``is_ok?`` Returns a ``boolean``, if all parameters are OK, you get a ``true`` value here, otherwise a ``false`` value appears.
71
-
72
- ``message`` Returns an array of String with the parameters problems with the request method, if have one.
73
-
74
- ---
75
- #### Getting the data
76
-
77
- FipExtractor provides a friendly response data layout. All original API parameters are converted to a FipExtractor pattern. This pattern is more developer-like.
78
-
79
- The original API response layout provides some JSON keys like ``Label`` and ``Value``. This patterns isn't a good pattern. FipExtractor converts these kind of parameters, in a specific Hash based on request method.
80
-
81
- Getting data response:
82
- ````ruby
83
- extractor = FipExtractor.new(:model, {reference_table_id: 189, vehicle_type: :truck, brand_id: 102})
84
- api = extractor.request
85
- api = api.send
86
- puts api.response
87
- ````
88
-
89
- Output:
90
-
91
- ````ruby
92
- {:brand_name=>"AGRALE", :brand_id=>"102"}
93
- {:brand_name=>"CHEVROLET", :brand_id=>"103"}
94
- {:brand_name=>"CICCOBUS", :brand_id=>"121"}
95
- {:brand_name=>"DAF", :brand_id=>"197"}
96
- {:brand_name=>"EFFA-JMC", :brand_id=>"179"}
97
- {:brand_name=>"FIAT", :brand_id=>"104"}
98
- {:brand_name=>"FORD", :brand_id=>"105"}
99
- {:brand_name=>"FOTON", :brand_id=>"191"}
100
- {:brand_name=>"GMC", :brand_id=>"106"}
101
- {:brand_name=>"HYUNDAI", :brand_id=>"181"}
102
- {:brand_name=>"IVECO", :brand_id=>"122"}
103
- {:brand_name=>"MAN", :brand_id=>"184"}
104
- {:brand_name=>"MARCOPOLO", :brand_id=>"108"}
105
- {:brand_name=>"MASCARELLO", :brand_id=>"196"}
106
- {:brand_name=>"MAXIBUS", :brand_id=>"194"}
107
- {:brand_name=>"MERCEDES-BENZ", :brand_id=>"109"}
108
- {:brand_name=>"NAVISTAR", :brand_id=>"110"}
109
- {:brand_name=>"NEOBUS", :brand_id=>"111"}
110
- {:brand_name=>"PUMA-ALFA", :brand_id=>"112"}
111
- {:brand_name=>"SAAB-SCANIA", :brand_id=>"113"}
112
- {:brand_name=>"SCANIA", :brand_id=>"114"}
113
- {:brand_name=>"SHACMAN", :brand_id=>"193"}
114
- {:brand_name=>"SINOTRUK", :brand_id=>"166"}
115
- {:brand_name=>"VOLKSWAGEN", :brand_id=>"115"}
116
- {:brand_name=>"VOLVO", :brand_id=>"116"}
117
- {:brand_name=>"WALKBUS", :brand_id=>"144"}
118
- ````
1
+ # FipExtractor
2
+
3
+ Unofficial client gem for FIPE vehicle table.
4
+
5
+ ## Installation
6
+
7
+ Add this line in your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fipextractor', '~> 1.0'
11
+ ```
12
+
13
+ $ bundle
14
+
15
+ Or
16
+
17
+ $ gem install fipextractor
18
+
19
+ ## Implemented Calls
20
+
21
+ - [ReferenceTable](#referencetable)
22
+ - [Brand](#brand)
23
+ - [Model](#Model)
24
+ - [ModelYear](#modelyear)
25
+ - [ModelThroughYear](#modelthroughyear)
26
+ - [Vehicle](#vehicle)
27
+
28
+ ### ReferenceTable
29
+
30
+ ```ruby
31
+ response = FipExtractor::ReferenceTable.new.call
32
+ response.all # array of reference tables id
33
+ ```
34
+
35
+ ### Brand
36
+
37
+ ```ruby
38
+ response = FipExtractor::Brand.new(vehicle_type: :car, reference_table_id: 66).call
39
+ response.all # array of vehicle brands
40
+ ```
41
+
42
+ ### Model
43
+
44
+ ```ruby
45
+ response = FipExtractor::Model.new(vehicle_type: :car, reference_table_id: 66, brand_id: 44).call
46
+ response.all # array of model and years
47
+ response.models # array of model hashes
48
+ response.years # array of year designated
49
+ ```
50
+
51
+ ### ModelYear
52
+
53
+ ```ruby
54
+ response = FipExtractor::ModelYear.new(vehicle_type: :car, reference_table_id: 66, brand_id: 44, model_id: 1878).call
55
+ response.all # array of models with aging
56
+ ```
57
+
58
+ ### ModelThroughYear
59
+
60
+ ```ruby
61
+ response = FipExtractor::ModelThroughYear.new(vehicle_type: :car, reference_table_id: 66, brand_id: 44, year: 1999, fuel: 1).call
62
+ response.all # array of models ordered by year, and/or fuel filter
63
+ ```
64
+
65
+ ### Vehicle
66
+
67
+ ```ruby
68
+ response = FipExtractor::Vehicle.new(vehicle_type: :car, reference_table_id: 237, brand_id: 59, model_id: 2365, year: 1999, fuel: 3).call
69
+ response.details # detailed fipe information of vehicle
70
+ ```
71
+
72
+ #### Vehicle Types
73
+
74
+ ```ruby
75
+ { car: 1, motorcycle: 2, truck: 3 }
76
+ ```
77
+
78
+ ### Tests
79
+
80
+ `rake spec`
81
+
82
+ ### Console
83
+
84
+ `bundle console`
85
+
86
+ ## License
87
+
88
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,10 +1,6 @@
1
- require 'rake/testtask'
2
-
3
- desc "Run all tests in folder test/*_test.rb"
4
- Rake::TestTask.new do |t|
5
- t.libs << "test"
6
- t.test_files = FileList['test/*_spec.rb']
7
- t.verbose = true
8
- end
9
-
10
- task :default => :test
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/fipextractor.gemspec CHANGED
@@ -1,21 +1,29 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'fipextractor'
3
- s.version = '0.0.1'
4
- s.summary = 'FipExtractor'
5
- s.description = 'Consume, and extract data about vehicles from FIPE API'
6
- s.authors = ["Rynaro"]
7
- s.email = 'iam@henriquelavezzo.com.br'
8
- s.homepage = 'https://github.com/Rynaro/fipextractor'
9
- s.license = 'MIT'
10
-
11
- s.add_dependency('unirest', '~> 1.1')
12
-
13
- s.add_development_dependency('minitest', '~> 5.10')
14
- s.add_development_dependency('rake')
15
-
16
- s.required_ruby_version = '~> 2.0'
17
-
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- test/*`.split("\n")
20
- s.require_paths = ['lib']
21
- end
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fipextractor/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fipextractor"
8
+ spec.version = FipExtractor::VERSION
9
+ spec.authors = ["Henrique A. Lavezzo"]
10
+ spec.email = ["me@hlavezzo.run"]
11
+
12
+ spec.summary = %q{Parsing fixed width files made easy}
13
+ spec.homepage = "https://github.com/Rynaro/estratto"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency('faraday', '~> 0.15')
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "pry-nav"
29
+ end