brasilapi 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40af8e101ebaefb3a05d6e4eb5bf756b6e0fb5feac9bd1b7df9d6aeeb920ee7e
4
- data.tar.gz: dd7b7cb583665180ef77b39e040a585b8746fc53a4ecfc1ec7821d19f01e26d3
3
+ metadata.gz: 2d4feae01c7e83e53c8f30fe32b71bb335e64d17a05874b0e465abc695ba518a
4
+ data.tar.gz: 8d36f60325e36d611da49f21a513fbe6e8551fea5f44446e7b9106c6d16ae221
5
5
  SHA512:
6
- metadata.gz: 0a2b7630a8d5eef7358231019feaeed5610969b09357e439128f138e1456d89fc0cdddc211fa4c1cd3bec363913b192bcab0639e9f034ff4121710a15c6e4f87
7
- data.tar.gz: 9841a7a7fc7df413fee19810872969b9290ec2dbb93a7519acea864a2953327dc80d0ce0bca028a8c6d042f368cdafad1774ac56b489d5cd7d1d1228127884c2
6
+ metadata.gz: df32ff8fb00d74216638a81b683e1ca95abd42be4f0404deff5ada20ec1b52d411711a854aed8c4650e93b76d81ac587dab67db54c08abfa36907fbf9c987de8
7
+ data.tar.gz: 005a4a9b91af86ad408f2f8fb5293d5285b2a974b4720d9b884c2e657f84286add533d0ed6a2d3cea75105c3ed4583ea89738fa44396b4e94430c421ba011b39
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.7.0] - 2025-04-21
4
+
5
+ - Integração da API do CPTEC
6
+ - Integração da API da Tabela FIPE
7
+ - Integração da API de ISBN
8
+ - Integração da API de NCM
9
+ - Integração da API de PIX
10
+ - Integração da API de Registros BR
11
+ - Integração da API de Taxas
12
+
13
+ ## [0.6.0] - 2024-02-25
14
+
15
+ - Integração da API do IBGE
16
+
3
17
  ## [0.5.1] - 2023-12-01
4
18
 
5
19
  - Corrigindo versão publicada no RubyGems
data/Gemfile CHANGED
@@ -9,6 +9,6 @@ group :development do
9
9
  gem "rspec", "~> 3.0"
10
10
  gem "rubocop", "~> 1.21"
11
11
  gem "rubocop-rspec", "~> 2.24"
12
- gem "vcr", "~> 6.2"
13
- gem "webmock", "~> 3.19"
12
+ gem "vcr", "~> 6.3"
13
+ gem "webmock", "~> 3.25"
14
14
  end
data/Gemfile.lock CHANGED
@@ -1,31 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brasilapi (0.5.1)
4
+ brasilapi (0.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- addressable (2.8.5)
10
- public_suffix (>= 2.0.2, < 6.0)
9
+ addressable (2.8.7)
10
+ public_suffix (>= 2.0.2, < 7.0)
11
11
  ast (2.4.2)
12
12
  base64 (0.1.1)
13
- crack (0.4.5)
13
+ bigdecimal (3.1.9)
14
+ crack (1.0.0)
15
+ bigdecimal
14
16
  rexml
15
17
  diff-lcs (1.5.0)
16
- hashdiff (1.0.1)
18
+ hashdiff (1.1.2)
17
19
  json (2.6.3)
18
20
  language_server-protocol (3.17.0.3)
19
21
  parallel (1.23.0)
20
22
  parser (3.2.2.4)
21
23
  ast (~> 2.4.1)
22
24
  racc
23
- public_suffix (5.0.3)
25
+ public_suffix (6.0.1)
24
26
  racc (1.7.1)
25
27
  rainbow (3.1.1)
26
28
  rake (13.0.6)
27
29
  regexp_parser (2.8.2)
28
- rexml (3.2.6)
30
+ rexml (3.4.1)
29
31
  rspec (3.12.0)
30
32
  rspec-core (~> 3.12.0)
31
33
  rspec-expectations (~> 3.12.0)
@@ -63,8 +65,9 @@ GEM
63
65
  rubocop-factory_bot (~> 2.22)
64
66
  ruby-progressbar (1.13.0)
65
67
  unicode-display_width (2.5.0)
66
- vcr (6.2.0)
67
- webmock (3.19.1)
68
+ vcr (6.3.1)
69
+ base64
70
+ webmock (3.25.1)
68
71
  addressable (>= 2.8.0)
69
72
  crack (>= 0.3.2)
70
73
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -78,8 +81,8 @@ DEPENDENCIES
78
81
  rspec (~> 3.0)
79
82
  rubocop (~> 1.21)
80
83
  rubocop-rspec (~> 2.24)
81
- vcr (~> 6.2)
82
- webmock (~> 3.19)
84
+ vcr (~> 6.3)
85
+ webmock (~> 3.25)
83
86
 
84
87
  BUNDLED WITH
85
88
  2.4.10
data/README.md CHANGED
@@ -10,16 +10,16 @@ Dependency-less Brasil API lookup gem for brazilian data with an easy-to-use API
10
10
  - [x] **CEP (Zip code)**
11
11
  - [x] **CNPJ**
12
12
  - [x] **Corretoras**
13
- - [ ] **CPTEC**
13
+ - [x] **CPTEC**
14
14
  - [x] **DDD**
15
15
  - [x] **Feriados Nacionais**
16
- - [ ] **FIPE**
17
- - [ ] **IBGE**
18
- - [ ] **ISBN**
19
- - [ ] **NCM**
20
- - [ ] **PIX**
21
- - [ ] **Registros BR**
22
- - [ ] **Taxas**
16
+ - [x] **FIPE**
17
+ - [x] **IBGE**
18
+ - [x] **ISBN**
19
+ - [x] **NCM**
20
+ - [x] **PIX**
21
+ - [x] **Registros BR**
22
+ - [x] **Taxas**
23
23
 
24
24
  ## Installation
25
25
 
@@ -98,8 +98,46 @@ BrasilAPI::Holiday.by_year(2024)
98
98
  [{"date"=>"2024-01-01", "name"=>"Confraternização mundial", "type"=>"national"},
99
99
  ...
100
100
  {"date"=>"2024-12-25", "name"=>"Natal", "type"=>"national"}]
101
+
102
+ # get states from ibge
103
+ BrasilAPI::IBGE.states
104
+ =>
105
+ [{"id"=>11,
106
+ "sigla"=>"RO"
107
+ "nome"=>"Rondônia",
108
+ "regiao"=>{"id"=>1, "sigla"=>"N", "nome"=>"Norte"}},
109
+ ...
110
+ {"id"=>53,
111
+ "sigla"=>"DF",
112
+ "nome"=>"Distrito Federal",
113
+ "regiao"=>{"id"=>5, "sigla"=>"CO", "nome"=>"Centro-Oeste"}}]
114
+
115
+ # find state by abbreviation from ibge
116
+ BrasilAPI::IBGE.find_state_by_code('PI')
117
+ =>
118
+ {"id"=>22,
119
+ "sigla"=>"PI",
120
+ "nome"=>"Piauí",
121
+ "regiao"=>{"id"=>2, "sigla"=>"NE", "nome"=>"Nordeste"}}
122
+
123
+ # find state by code from ibge
124
+ BrasilAPI::IBGE.find_state_by_code(53)
125
+ =>
126
+ {"id"=>53,
127
+ "sigla"=>"DF",
128
+ "nome"=>"Distrito Federal",
129
+ "regiao"=>{"id"=>5, "sigla"=>"CO", "nome"=>"Centro-Oeste"}}
130
+
131
+ # get cities by state abbreviation from ibge
132
+ BrasilAPI::IBGE.cities_by_state('CE')
133
+ =>
134
+ [{"nome"=>"ABAIARA", "codigo_ibge"=>"2300101"},
135
+ ...
136
+ {"nome"=>"VÁRZEA ALEGRE", "codigo_ibge"=>"2314003"},
137
+ {"nome"=>"VIÇOSA DO CEARÁ", "codigo_ibge"=>"2314102"}]
101
138
  ```
102
139
 
140
+
103
141
  # License
104
142
  [MIT](./LICENSE)
105
143
 
@@ -6,11 +6,17 @@ require "net/http"
6
6
  module BrasilAPI
7
7
  class Base
8
8
  BASE_URL = "https://brasilapi.com.br/api"
9
-
10
9
  class << self
11
- def get(path)
10
+ def get(path, params = {})
12
11
  uri = URI("#{BASE_URL}#{path}")
12
+ uri.query = URI.encode_www_form(params) if params.any?
13
+
14
+ request_data(uri)
15
+ end
13
16
 
17
+ protected
18
+
19
+ def request_data(uri)
14
20
  response = Net::HTTP.get_response(uri)
15
21
 
16
22
  case status_for(response)
@@ -23,8 +29,6 @@ module BrasilAPI
23
29
  end
24
30
  end
25
31
 
26
- protected
27
-
28
32
  def status_for(response)
29
33
  status = {
30
34
  Net::HTTPOK => 200,
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrasilAPI
4
+ class CPTEC < Base
5
+ class << self
6
+ def all
7
+ get("/cptec/v1/cidade")
8
+ end
9
+
10
+ def search_location(city_name)
11
+ get("/cptec/v1/cidade/#{city_name}")
12
+ end
13
+
14
+ def capital_weather
15
+ get("/cptec/v1/clima/capital")
16
+ end
17
+
18
+ def airport_weather(code)
19
+ get("/cptec/v1/clima/aeroporto/#{code}")
20
+ end
21
+
22
+ def city_weather(city_code, days = nil)
23
+ if days
24
+ get("/cptec/v1/clima/previsao/#{city_code}/#{days}")
25
+ else
26
+ get("/cptec/v1/clima/previsao/#{city_code}")
27
+ end
28
+ end
29
+
30
+ def ocean_forecast(city_code, days = nil)
31
+ if days
32
+ get("/cptec/v1/ondas/#{city_code}/#{days}")
33
+ else
34
+ get("/cptec/v1/ondas/#{city_code}")
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrasilAPI
4
+ class FIPE < Base
5
+ class << self
6
+ # https://brasilapi.com.br/api/fipe/marcas/v1/{tipoVeiculo}
7
+ def vehicle_brands(vehicle_type, reference_table = nil)
8
+ get("/fipe/marcas/v1/#{vehicle_type}", { tabela_referencia: reference_table })
9
+ end
10
+
11
+ # https://brasilapi.com.br/api/fipe/preco/v1/{codigoFipe}
12
+ def vehicle_price(vehicle_code, reference_table = nil)
13
+ get("/fipe/preco/v1/#{vehicle_code}", { tabela_referencia: reference_table })
14
+ end
15
+
16
+ # https://brasilapi.com.br/api/fipe/tabelas/v1
17
+ def fipe_tables
18
+ get("/fipe/tabelas/v1")
19
+ end
20
+
21
+ # https://brasilapi.com.br/api/fipe/veiculos/v1/{tipoVeiculo}/{codigoMarca}
22
+ def list_vehicles(vehicle_type, brand_code, reference_table = nil)
23
+ get("/fipe/veiculos/v1/#{vehicle_type}/#{brand_code}", { tabela_referencia: reference_table })
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrasilAPI
4
+ class IBGE < Base
5
+ class << self
6
+ def states
7
+ get("/ibge/uf/v1")
8
+ end
9
+
10
+ def find_state_by_code(code)
11
+ get("/ibge/uf/v1/#{code}")
12
+ end
13
+
14
+ def cities_by_state(state_abbr, providers: [])
15
+ return get("/ibge/municipios/v1/#{state_abbr}") if providers.empty?
16
+
17
+ get("/ibge/municipios/v1/#{state_abbr}", providers: providers.join(","))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrasilAPI
4
+ class ISBN < Base
5
+ class << self
6
+ def search(code, providers: [])
7
+ return get("/isbn/v1/#{code}") if providers.empty?
8
+
9
+ get("/isbn/v1/#{code}", providers: providers.join(","))
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrasilAPI
4
+ class NCM < Base
5
+ class << self
6
+ def all
7
+ get("/ncm/v1")
8
+ end
9
+
10
+ def search(code)
11
+ get("/ncm/v1", { search: code })
12
+ end
13
+
14
+ def find_by_code(code)
15
+ get("/ncm/v1/#{code}")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrasilAPI
4
+ class PIX < Base
5
+ class << self
6
+ def all
7
+ get("/pix/v1/participants")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrasilAPI
4
+ class RegistroBR < Base
5
+ class << self
6
+ def whois(domain)
7
+ get("/registrobr/v1/#{domain}")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrasilAPI
4
+ class Taxas < Base
5
+ class << self
6
+ def all
7
+ get("/taxas/v1")
8
+ end
9
+
10
+ def find_by_name(name)
11
+ get("/taxas/v1/#{name}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrasilAPI
4
- VERSION = "0.5.1"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/brasil_api.rb CHANGED
@@ -7,6 +7,14 @@ require_relative "brasil_api/bank"
7
7
  require_relative "brasil_api/company"
8
8
  require_relative "brasil_api/cvm"
9
9
  require_relative "brasil_api/holiday"
10
+ require_relative "brasil_api/ibge"
11
+ require_relative "brasil_api/cptec"
12
+ require_relative "brasil_api/fipe"
13
+ require_relative "brasil_api/isbn"
14
+ require_relative "brasil_api/ncm"
15
+ require_relative "brasil_api/pix"
16
+ require_relative "brasil_api/registrobr"
17
+ require_relative "brasil_api/taxas"
10
18
 
11
19
  module BrasilAPI
12
20
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brasilapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dayvid Emerson
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-12-01 00:00:00.000000000 Z
10
+ date: 2025-04-21 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Acesso programático de informações é algo fundamental na comunicação
14
13
  entre sistemas, mas, para nossa surpresa, uma informação tão útil e pública quanto
@@ -40,8 +39,16 @@ files:
40
39
  - lib/brasil_api/bank.rb
41
40
  - lib/brasil_api/base.rb
42
41
  - lib/brasil_api/company.rb
42
+ - lib/brasil_api/cptec.rb
43
43
  - lib/brasil_api/cvm.rb
44
+ - lib/brasil_api/fipe.rb
44
45
  - lib/brasil_api/holiday.rb
46
+ - lib/brasil_api/ibge.rb
47
+ - lib/brasil_api/isbn.rb
48
+ - lib/brasil_api/ncm.rb
49
+ - lib/brasil_api/pix.rb
50
+ - lib/brasil_api/registrobr.rb
51
+ - lib/brasil_api/taxas.rb
45
52
  - lib/brasil_api/version.rb
46
53
  - lib/brasilapi.rb
47
54
  homepage: https://brasilapi.com.br
@@ -52,7 +59,6 @@ metadata:
52
59
  source_code_uri: https://github.com/dayvidemerson/brasilapi-rb
53
60
  changelog_uri: https://github.com/dayvidemerson/brasilapi-rb/blob/main/CHANGELOG.md
54
61
  rubygems_mfa_required: 'true'
55
- post_install_message:
56
62
  rdoc_options: []
57
63
  require_paths:
58
64
  - lib
@@ -67,8 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
75
  requirements: []
70
- rubygems_version: 3.4.10
71
- signing_key:
76
+ rubygems_version: 3.6.2
72
77
  specification_version: 4
73
78
  summary: Cliente desenvolvido em Ruby para o consumo da Brasil API que permite buscar
74
79
  informações públicas referentes ao Brasil de modo eficiente e simplificado.