request-cnpj 0.1.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 +7 -0
- data/.claude/settings.json +11 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/README.md +57 -0
- data/README.pt-BR.md +57 -0
- data/Rakefile +12 -0
- data/lib/request/cnpj/base_client.rb +39 -0
- data/lib/request/cnpj/client.rb +20 -0
- data/lib/request/cnpj/version.rb +7 -0
- data/lib/request/cnpj.rb +13 -0
- data/sig/request/cnpj.rbs +6 -0
- metadata +56 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8107226372f6afef3e83e5bf0ca7a44c5024492d02f22eee29cbe062f5dd3a8c
|
|
4
|
+
data.tar.gz: 17404f2e1f66e641cceb063929548a2e3dbc10ad8fe14cb3a2999b97650e9b49
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1e06229aa3c680ca81c4bd9ac786519a65408cf2666679a0c4ae3b28c29777151e848f171c93baf6170df246399882cfdf56d5a3f818562825eefbcc481ea131
|
|
7
|
+
data.tar.gz: 3d2114d93c14947943c26e6f04c94a72e58f7ca9498f445e02316da05b7616d05f4d84d0b8fa8c8b28385d2b7f12fca6890290d789606cd7e8998083f1fbdc05
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(bundle install *)",
|
|
5
|
+
"Bash(curl -s -o /dev/null -w \"%{http_code}\\\\n\" --max-time 5 https://api.opencnpj.org/00000000000191)",
|
|
6
|
+
"Bash(curl -s --max-time 5 https://api.opencnpj.org/00000000000191)",
|
|
7
|
+
"Bash(curl -s -o /dev/null -w \"%{http_code}\\\\n\" --max-time 5 https://api.opencnpj.org/11111111111111)",
|
|
8
|
+
"Bash(gem build *)"
|
|
9
|
+
]
|
|
10
|
+
}
|
|
11
|
+
}
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"request-cnpj" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["moises.ribeiro.developer@gmail.com"](mailto:"moises.ribeiro.developer@gmail.com").
|
data/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Request::Cnpj
|
|
2
|
+
|
|
3
|
+
[Leia em Português](README.pt-BR.md)
|
|
4
|
+
|
|
5
|
+
A Ruby client for looking up Brazilian company registration data (CNPJ) via the [OpenCNPJ API](https://api.opencnpj.org).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install the gem and add it to the application's Gemfile by executing:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bundle add request-cnpj
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
gem install request-cnpj
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Alternatively, add it directly to your Gemfile:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
gem 'request-cnpj'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
And run:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bundle install
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
require 'request/cnpj'
|
|
37
|
+
|
|
38
|
+
client = Request::Cnpj::Client.new
|
|
39
|
+
client.find('12.345.678/0001-95')
|
|
40
|
+
# => { "cnpj" => "12345678000195", ... }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`find` accepts the CNPJ with or without punctuation — any non-digit characters are stripped before the request is made.
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
48
|
+
|
|
49
|
+
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`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
50
|
+
|
|
51
|
+
## Contributing
|
|
52
|
+
|
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/moshepedroribeiro/request-cnpj. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
|
|
54
|
+
|
|
55
|
+
## Code of Conduct
|
|
56
|
+
|
|
57
|
+
Everyone interacting in the Request::Cnpj project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
data/README.pt-BR.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Request::Cnpj
|
|
2
|
+
|
|
3
|
+
[Read in English](README.md)
|
|
4
|
+
|
|
5
|
+
Um cliente Ruby para consultar dados de CNPJ (Cadastro Nacional da Pessoa Jurídica) por meio da [API OpenCNPJ](https://api.opencnpj.org).
|
|
6
|
+
|
|
7
|
+
## Instalação
|
|
8
|
+
|
|
9
|
+
Instale a gem e adicione-a ao Gemfile da aplicação executando:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bundle add request-cnpj
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Se o bundler não estiver sendo usado para gerenciar as dependências, instale a gem executando:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
gem install request-cnpj
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Alternativamente, adicione-a diretamente ao seu Gemfile:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
gem 'request-cnpj'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
E execute:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bundle install
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Uso
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
require 'request/cnpj'
|
|
37
|
+
|
|
38
|
+
client = Request::Cnpj::Client.new
|
|
39
|
+
client.find('12.345.678/0001-95')
|
|
40
|
+
# => { "cnpj" => "12345678000195", ... }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
O método `find` aceita o CNPJ com ou sem pontuação — qualquer caractere que não seja número é removido antes da requisição.
|
|
44
|
+
|
|
45
|
+
## Desenvolvimento
|
|
46
|
+
|
|
47
|
+
Após clonar o repositório, rode `bin/setup` para instalar as dependências. Em seguida, rode `rake spec` para executar os testes. Você também pode rodar `bin/console` para um prompt interativo e experimentar o código.
|
|
48
|
+
|
|
49
|
+
Para instalar essa gem na sua máquina local, rode `bundle exec rake install`. Para lançar uma nova versão, atualize o número da versão em `version.rb` e rode `bundle exec rake release`, que cria uma tag no git, envia os commits e a tag criada, e publica o arquivo `.gem` no [rubygems.org](https://rubygems.org).
|
|
50
|
+
|
|
51
|
+
## Contribuindo
|
|
52
|
+
|
|
53
|
+
Relatos de bugs e pull requests são bem-vindos no GitHub em https://github.com/moshepedroribeiro/request-cnpj. Este projeto pretende ser um espaço seguro e acolhedor para colaboração, e espera-se que os contribuidores sigam o [código de conduta](CODE_OF_CONDUCT.md).
|
|
54
|
+
|
|
55
|
+
## Código de Conduta
|
|
56
|
+
|
|
57
|
+
Espera-se que todos que interagem nos códigos-fonte, issue trackers, salas de chat e listas de e-mail do projeto Request::Cnpj sigam o [código de conduta](CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Request
|
|
4
|
+
module Cnpj
|
|
5
|
+
# Base class for CNPJ request clients, providing shared execution logic.
|
|
6
|
+
class BaseClient
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
def get(path = nil, params: nil, headers: default_headers, url: url_for(path, **params.to_h), &)
|
|
10
|
+
execute(method: :get, url:, headers:, &)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def execute(**)
|
|
14
|
+
response = executor.execute(**default_execute_options, **)
|
|
15
|
+
|
|
16
|
+
return yield response if block_given?
|
|
17
|
+
|
|
18
|
+
response.body
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def default_headers
|
|
22
|
+
{
|
|
23
|
+
accept: 'application/json'
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def default_execute_options
|
|
28
|
+
{}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def url_for(path, **params)
|
|
32
|
+
URI('https://api.opencnpj.org').tap do |uri|
|
|
33
|
+
uri.path += path
|
|
34
|
+
uri.query = params.to_query if params.any?
|
|
35
|
+
end.to_s
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Request
|
|
4
|
+
module Cnpj
|
|
5
|
+
# Client for fetching CNPJ data from the OpenCNPJ API.
|
|
6
|
+
class Client < BaseClient
|
|
7
|
+
attr_reader :url, :executor
|
|
8
|
+
|
|
9
|
+
def initialize(executor: RestClient::Request)
|
|
10
|
+
super()
|
|
11
|
+
@executor = executor
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Method to request CNPJ to API
|
|
15
|
+
def find(cnpj)
|
|
16
|
+
JSON.parse(get("/#{cnpj.gsub(/[^0-9]/, '')}"))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/request/cnpj.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'rest-client'
|
|
5
|
+
require_relative 'cnpj/version'
|
|
6
|
+
require_relative 'cnpj/base_client'
|
|
7
|
+
require_relative 'cnpj/client'
|
|
8
|
+
|
|
9
|
+
module Request
|
|
10
|
+
module Cnpj
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: request-cnpj
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Moisés Ribeiro
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Request::Cnpj is a lightweight Ruby client for fetching CNPJ (Cadastro
|
|
13
|
+
Nacional da Pessoa Jurídica) data from the OpenCNPJ API.
|
|
14
|
+
email:
|
|
15
|
+
- moises.ribeiro.developer@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".claude/settings.json"
|
|
21
|
+
- CHANGELOG.md
|
|
22
|
+
- CODE_OF_CONDUCT.md
|
|
23
|
+
- README.md
|
|
24
|
+
- README.pt-BR.md
|
|
25
|
+
- Rakefile
|
|
26
|
+
- lib/request/cnpj.rb
|
|
27
|
+
- lib/request/cnpj/base_client.rb
|
|
28
|
+
- lib/request/cnpj/client.rb
|
|
29
|
+
- lib/request/cnpj/version.rb
|
|
30
|
+
- sig/request/cnpj.rbs
|
|
31
|
+
homepage: https://github.com/moshepedroribeiro/request-cnpj
|
|
32
|
+
licenses: []
|
|
33
|
+
metadata:
|
|
34
|
+
allowed_push_host: https://rubygems.org
|
|
35
|
+
homepage_uri: https://github.com/moshepedroribeiro/request-cnpj
|
|
36
|
+
source_code_uri: https://github.com/moshepedroribeiro/request-cnpj
|
|
37
|
+
changelog_uri: https://github.com/moshepedroribeiro/request-cnpj/blob/main/CHANGELOG.md
|
|
38
|
+
rdoc_options: []
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 3.2.0
|
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '0'
|
|
51
|
+
requirements: []
|
|
52
|
+
rubygems_version: 4.0.10
|
|
53
|
+
specification_version: 4
|
|
54
|
+
summary: Ruby client for looking up Brazilian company registration data (CNPJ) via
|
|
55
|
+
the OpenCNPJ API.
|
|
56
|
+
test_files: []
|