receitaws 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3143d2561d56b51e76ba04d9fb3416ea24a353f0
4
+ data.tar.gz: 3089c4e95d211771e00247eb7040d54fe091ca15
5
+ SHA512:
6
+ metadata.gz: 12b6a6bc7d1e88abef60b9ef94e653b5a26c38879a332cb26b7d42b9378baeb10fc0f5100971adf5618e50435edf0f4fc3a026a26bfb911195625d220a5b272a
7
+ data.tar.gz: 9eef68b1abeb7ccfb8dbd4aff086d6e326a30fbd6e7c1d20872b1e10eb63d296cbd7b5549c20cd67f0a598c725ecaab11255c8a957e212a93a4375bd14940f7c
data/.gitignore ADDED
@@ -0,0 +1,52 @@
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
51
+
52
+ .to_do
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ receitaws (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ receitaws!
15
+
16
+ BUNDLED WITH
17
+ 1.16.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 QW3 - Software, Marketing e Consultoria
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 ADDED
@@ -0,0 +1,179 @@
1
+ # Gem ReceitaWS API - Consulta de Dados de CNPJ
2
+
3
+ Mantenha seu sistema sempre atualizado com dados fiéis das empresas que se relacionam com você.
4
+
5
+ ## Versão Beta
6
+
7
+ Uma Gem simples para recuperação de informações de empresas através de seu CNPJ utilizando Webservice da [ReceitaWS](https://receitaws.com.br/) versão **Comercial**. Acreditamos que estas informações devem estar acessíveis a qualquer indivíduo ou empresa, e sem nenhum custo.
8
+
9
+ Acesso a documentação de desenvolvimento da [https://receitaws.com.br/](https://receitaws.com.br/api)
10
+
11
+ ## Instalando
12
+
13
+ ### Gemfile
14
+
15
+ Adicione esta linha ao Gemfile do seu aplicativo:
16
+
17
+ ```ruby
18
+ gem 'receitaws'
19
+ ```
20
+
21
+ - Execute o comando `bundle install`.
22
+
23
+ ### Instalação direta
24
+
25
+ ```ruby
26
+ gem install receitaws
27
+ ```
28
+
29
+ ## Configuração
30
+
31
+ Para fazer a autenticação, você precisará configurar as credenciais da ReceitaWS. Crie o arquivo `config/initializers/receitaws.rb` com o conteúdo abaixo.
32
+
33
+ ```ruby
34
+ Receitaws.configure do |config|
35
+
36
+ #
37
+ # Cadastrar token fornecido no cadastro na ReceitaWS
38
+ config.token = 'cPHqyaLe6X2mVsFp1dBogWh92x7HLizeKu4AbsZo3t1qg5HIzh8ns6fwjFcBkc2b'
39
+
40
+ #
41
+ # Opções de ambiente
42
+ # Quantidade máxima de dias com relação à última consulta na Receita Federal deste CNPJ
43
+ config.days = 365
44
+
45
+ #
46
+ # Tempo de espera pela resposta do WeService em segundos
47
+ config.timeout = 10
48
+
49
+ end
50
+ ```
51
+
52
+ ## Consultar CNPJ
53
+
54
+ Nesse endpoint é realizado a consulta de um CNPJ.
55
+
56
+ > Enviar somente os números do CNPJ, sem pontos e traços.
57
+
58
+ Será retornado um objeto do tipo **Receitaws::Cnpj** descrito abaixo.
59
+
60
+
61
+ ```ruby
62
+ cnpj = = Receitaws::ConsultarCnpj.executar 27865757000102
63
+ ```
64
+
65
+ Verificar se se a consulta foi realizada com sucesso.
66
+
67
+ ```ruby
68
+ #
69
+ # Caso tenha ocorrido algum erro na consulta
70
+ cnpj.status == :error
71
+
72
+ #
73
+ # Mensagem explicativa indicando erro.
74
+ cnpj.message
75
+
76
+ #
77
+ # Consulta realizada com sucesso
78
+ cnpj.status == :ok
79
+
80
+
81
+ #
82
+ # LIsta de atributos disponíveis
83
+
84
+ # CNPJ no formato 00.000.000/0000-00.
85
+ cnpj.cnpj
86
+
87
+ # Data de abertura no formato dd/mm/aaaa.
88
+ cnpj.abertura
89
+
90
+ # Razão social.
91
+ cnpj.nome
92
+
93
+ # Nome fantasia.
94
+ cnpj.fantasia
95
+
96
+ # Logradouro.
97
+ cnpj.logradouro
98
+
99
+ # Número.
100
+ cnpj.numero
101
+
102
+ # Complemento.
103
+ cnpj.complemento
104
+
105
+ # CEP no formato 00.000-000.
106
+ cnpj.cep
107
+
108
+ # Bairro.
109
+ cnpj.bairro
110
+
111
+ # Município.
112
+ cnpj.municipio
113
+
114
+ # Sigla da Unidade da Federação.
115
+ cnpj.uf
116
+
117
+ # Email.
118
+ cnpj.email
119
+
120
+ # Telefone.
121
+ cnpj.telefone
122
+
123
+ # Situação.
124
+ cnpj.situacao
125
+
126
+ # Data da situação no formato dd/mm/aaaa.
127
+ cnpj.data_situacao
128
+
129
+ # Lista (Array de Hash) completa de todos os CNAE do CNPJ
130
+ # O primeiro da lista será sempre o CNAE Principal
131
+ cnpj.atividades
132
+
133
+ # Descrição da atividade.
134
+ cnpj.atividades[0][:text]
135
+
136
+ # Código CNAE da atividade no formato 00.00-0-00.
137
+ cnpj.atividades[0][:code]
138
+
139
+ # Lista (Array) completa de todos os CNAE do CNPJ
140
+ # Somente os números dos CNAES sem pontos e traços
141
+ cnpj.cnaes
142
+
143
+ ```
144
+
145
+ ---
146
+
147
+
148
+ ## Autor
149
+
150
+ - [QW3 Software & Marketing](http://qw3.com.br)
151
+ - [Leandro dos Santos Falcão](https://www.linkedin.com/in/lsfalcao)
152
+
153
+ ## Copyright
154
+
155
+ [QW3 Software & Marketing](http://qw3.com.br)
156
+
157
+ ![QW3 Logo](http://qw3.com.br/qw3_logo.png)
158
+
159
+ MIT License
160
+
161
+ Copyright (c) 2018 QW3 - Software, Marketing e Consultoria
162
+
163
+ Permission is hereby granted, free of charge, to any person obtaining a copy
164
+ of this software and associated documentation files (the "Software"), to deal
165
+ in the Software without restriction, including without limitation the rights
166
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
167
+ copies of the Software, and to permit persons to whom the Software is
168
+ furnished to do so, subject to the following conditions:
169
+
170
+ The above copyright notice and this permission notice shall be included in all
171
+ copies or substantial portions of the Software.
172
+
173
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
174
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
175
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
176
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
177
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
178
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
179
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,46 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Receitaws
3
+ class Base
4
+ require 'uri'
5
+ require 'net/http'
6
+ require 'timeout'
7
+
8
+ def self.build_request endpoint, metodo, body=nil
9
+
10
+ url = URI("#{Receitaws.base_uri}/#{endpoint}")
11
+
12
+ http = Net::HTTP.new(url.host, url.port)
13
+ http.use_ssl = true
14
+
15
+ case metodo
16
+ when "delete"
17
+ request = Net::HTTP::Delete.new(url)
18
+ when "get"
19
+ request = Net::HTTP::Get.new(url)
20
+ when "put"
21
+ request = Net::HTTP::Put.new(url)
22
+ when "post"
23
+ request = Net::HTTP::Post.new(url)
24
+ end
25
+ request = Receitaws::Base.default_headers request
26
+
27
+ request.body = body.to_json unless body.nil?
28
+
29
+ begin
30
+ status = Timeout::timeout(Receitaws.timeout.to_i) {
31
+ return http.request(request)
32
+ }
33
+ rescue Timeout::Error
34
+ puts 'That took too long, exiting...'
35
+ return nil
36
+ end
37
+ end
38
+
39
+ def self.default_headers request
40
+ request["authorization"] = "Bearer #{Receitaws.token}"
41
+ request["Content-Type"] = "application/json"
42
+ return request
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Receitaws
3
+ class Cnpj
4
+
5
+ attr_reader :status, :message, :nome, :uf, :telefone, :email, :fantasia, :cnpj, :bairro, :logradouro, :numero, :cep, :municipio, :abertura, :data_situacao, :complemento, :atividades, :cnaes
6
+
7
+ def initialize(result=nil)
8
+
9
+ if result.nil?
10
+ @status = :error
11
+ @message = "Timeout"
12
+ end
13
+
14
+ if result["status"] == "ERROR"
15
+ @status = :error
16
+ @message = result["message"]
17
+ return self
18
+ end
19
+
20
+ @status = :ok
21
+ @nome = result["nome"]
22
+ @uf = result["uf"]
23
+ @telefone = result["telefone"]
24
+ @email = result["email"]
25
+ @fantasia = result["fantasia"]
26
+ @cnpj = result["cnpj"]
27
+ @bairro = result["bairro"]
28
+ @logradouro = result["logradouro"]
29
+ @numero = result["numero"]
30
+ @cep = result["cep"]
31
+ @municipio = result["municipio"]
32
+ @abertura = result["abertura"]
33
+ @data_situacao = result["data_situacao"]
34
+ @situacao = result["situacao"]
35
+ @complemento = result["complemento"]
36
+ @atividades = []
37
+ result["atividade_principal"].each do |atividade|
38
+ @atividades << {code: atividade["code"], text: atividade["text"]}
39
+ end
40
+ result["atividades_secundarias"].each do |atividade|
41
+ @atividades << {code: atividade["code"], text: atividade["text"]}
42
+ end
43
+ @cnaes = @atividades.collect{|a| a[:code].to_s.gsub(/[^0-9A-Za-z]/, '')}
44
+
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,73 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Receitaws
3
+ module Configure
4
+
5
+ # Endereço do WeService
6
+ URL_RECEITAWS = "https://www.receitaws.com.br"
7
+
8
+ # Parâmetros iniciais
9
+ API_VERSION = 'v1'
10
+
11
+ # Parâmetros iniciais
12
+ TOKEN = 'cPHqyaLe6X2mVsFp1dBogWh92x7HLizeKu4AbsZo3t1qg5HIzh8ns6fwjFcBkc2b'
13
+
14
+ # Parâmetros iniciais
15
+ DAYS = 365
16
+
17
+ # Parâmetros iniciais
18
+ TIMEOUT = 10
19
+
20
+ # Endereço do WeService
21
+ attr_writer :url
22
+
23
+ # Enviado pela ReceitaWS
24
+ attr_writer :api_version
25
+
26
+ # Enviado pela ReceitaWS
27
+ attr_writer :token
28
+
29
+ # Obrigatório, numérico, quantidade máxima de dias com relação à última consulta na Receita Federal deste CNPJ
30
+ attr_writer :days
31
+
32
+ # Obrigatório, numérico, Tempo de espera pela resposta do WeService em segundos
33
+ attr_writer :timeout
34
+
35
+ # Comando que recebe as configurações
36
+ def configure
37
+ yield self if block_given?
38
+ end
39
+
40
+ # Definir url_receitaws
41
+ def url_receitaws
42
+ @url_receitaws ||= URL_RECEITAWS
43
+ end
44
+
45
+ # Definir api_version
46
+ def api_version
47
+ @api_version ||= API_VERSION
48
+ end
49
+
50
+ # Definir token
51
+ def token
52
+ @token ||= TOKEN
53
+ end
54
+
55
+ # Definir days
56
+ # Obrigatório, numérico, quantidade máxima de dias com relação à última consulta na Receita Federal deste CNPJ
57
+ def days
58
+ @days ||= DAYS
59
+ end
60
+
61
+ # Definir timeout em segundos
62
+ # Tempo de espera pela resposta do WeService em segundos
63
+ def timeout
64
+ @timeout ||= TIMEOUT
65
+ end
66
+
67
+ # Definir url que será utilizado
68
+ def base_uri
69
+ return "#{self.url_receitaws}/#{self.api_version}"
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Receitaws
3
+ class ConsultarCnpj < Base
4
+
5
+ # Metodo para consultar um CNPJ
6
+ # cnpj: obrigatório, numérico, o CNPJ a ser pesquisado
7
+ # Retonar um obejto do tipo Receitaws::Cnpj
8
+ def self.executar cnpj
9
+
10
+ response = self.build_request self.endpoint(cnpj), "get"
11
+
12
+ begin
13
+ result = JSON.parse(response.read_body) unless response.nil?
14
+ rescue
15
+ result = nil
16
+ end
17
+
18
+ return Receitaws::Cnpj.new(result)
19
+
20
+ end
21
+
22
+ private
23
+
24
+ def self.endpoint cnpj
25
+ return "cnpj/#{cnpj}/days/#{Receitaws.days}"
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Receitaws
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
+ end
9
+ end
data/lib/receitaws.rb ADDED
@@ -0,0 +1,13 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rubygems'
3
+ require 'active_model'
4
+
5
+ require "receitaws/version"
6
+ require "receitaws/configure"
7
+ require "receitaws/base"
8
+ require "receitaws/consultar_cnpj"
9
+ require "receitaws/cnpj"
10
+
11
+ module Receitaws
12
+ extend Receitaws::Configure
13
+ end
data/receitaws.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'receitaws/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "receitaws"
8
+ spec.version = Receitaws::Version::STRING
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["QW3 Software & Marketing"]
11
+ spec.email = ["contato@qw3.com.br"]
12
+ spec.summary = "Gem ReceitaWS API - Consulta de Dados de CNPJ"
13
+ spec.description = "Uma Gem simples para recuperação de informações de empresas através de seu CNPJ utilizando Webservice da ReceitaWS - https://receitaws.com.br/ versão Comercial. Acreditamos que estas informações devem estar acessíveis a qualquer indivíduo ou empresa, e sem nenhum custo."
14
+ spec.homepage = "https://github.com/qw3/receitaws"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.required_ruby_version = Gem::Requirement.new(">= 1.9")
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: receitaws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - QW3 Software & Marketing
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Uma Gem simples para recuperação de informações de empresas através de
14
+ seu CNPJ utilizando Webservice da ReceitaWS - https://receitaws.com.br/ versão Comercial.
15
+ Acreditamos que estas informações devem estar acessíveis a qualquer indivíduo ou
16
+ empresa, e sem nenhum custo.
17
+ email:
18
+ - contato@qw3.com.br
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".gitignore"
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - lib/receitaws.rb
30
+ - lib/receitaws/base.rb
31
+ - lib/receitaws/cnpj.rb
32
+ - lib/receitaws/configure.rb
33
+ - lib/receitaws/consultar_cnpj.rb
34
+ - lib/receitaws/version.rb
35
+ - receitaws.gemspec
36
+ homepage: https://github.com/qw3/receitaws
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '1.9'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.4.8
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Gem ReceitaWS API - Consulta de Dados de CNPJ
60
+ test_files: []