enotas_api 0.1.0 → 1.0.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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -2
- data/CHANGELOG.md +3 -1
- data/README.md +85 -76
- data/Rakefile +3 -6
- data/lib/enotas_api/common/entity.rb +7 -19
- data/lib/enotas_api/common/json_result.rb +42 -0
- data/lib/enotas_api/common/raw_result.rb +21 -0
- data/lib/enotas_api/common/request.rb +32 -27
- data/lib/enotas_api/request_provider.rb +29 -16
- data/lib/enotas_api/support/{dynamic_attributes.rb → attributable.rb} +12 -9
- data/lib/enotas_api/support/encoding_helper.rb +0 -5
- data/lib/enotas_api/support/type_handler.rb +30 -0
- data/lib/enotas_api/v1/baixar_pdf_nfs.rb +15 -0
- data/lib/enotas_api/v1/baixar_pdf_nfs_id_externo.rb +15 -0
- data/lib/enotas_api/v1/baixar_xml_nfs.rb +15 -0
- data/lib/enotas_api/v1/baixar_xml_nfs_id_externo.rb +15 -0
- data/lib/enotas_api/v1/cancelar_nfs.rb +13 -0
- data/lib/enotas_api/v1/cancelar_nfs_id_externo.rb +13 -0
- data/lib/enotas_api/v1/consultar_caracteristicas_prefeitura.rb +1 -6
- data/lib/enotas_api/v1/consultar_cidades_servico_municipal_unificado.rb +3 -3
- data/lib/enotas_api/v1/consultar_empresa.rb +1 -6
- data/lib/enotas_api/v1/consultar_nfs.rb +13 -0
- data/lib/enotas_api/v1/consultar_nfs_id_externo.rb +13 -0
- data/lib/enotas_api/v1/consultar_servicos_municipais.rb +1 -7
- data/lib/enotas_api/v1/desabilitar_empresa.rb +13 -0
- data/lib/enotas_api/v1/emitir_nfs.rb +13 -0
- data/lib/enotas_api/v1/entities/empresa.rb +23 -20
- data/lib/enotas_api/v1/entities/empresa_configuracoes.rb +9 -7
- data/lib/enotas_api/v1/entities/empresa_endereco.rb +20 -0
- data/lib/enotas_api/v1/entities/nfs.rb +19 -0
- data/lib/enotas_api/v1/entities/nfs_cliente.rb +16 -0
- data/lib/enotas_api/v1/entities/nfs_cliente_endereco.rb +17 -0
- data/lib/enotas_api/v1/entities/nfs_servico.rb +21 -0
- data/lib/enotas_api/v1/habilitar_empresa.rb +13 -0
- data/lib/enotas_api/v1/incluir_atualizar_empresa.rb +13 -0
- data/lib/enotas_api/v1/listar_empresas.rb +2 -2
- data/lib/enotas_api/v1/listar_notas_fiscais.rb +17 -0
- data/lib/enotas_api/v1/vincular_certificado.rb +14 -0
- data/lib/enotas_api/v1/vincular_logotipo.rb +14 -0
- data/lib/enotas_api/version.rb +1 -1
- metadata +26 -6
- data/lib/enotas_api/common/result.rb +0 -45
- data/lib/enotas_api/support/conversion_helper.rb +0 -31
- data/lib/enotas_api/v1/entities/endereco.rb +0 -18
@@ -4,27 +4,37 @@ require 'net/http'
|
|
4
4
|
|
5
5
|
module EnotasApi
|
6
6
|
class RequestProvider
|
7
|
-
def get(url
|
8
|
-
request(Net::HTTP::Get, url
|
7
|
+
def get(url)
|
8
|
+
request(obj: Net::HTTP::Get, url: url)
|
9
9
|
end
|
10
10
|
|
11
|
-
def post(url, body
|
12
|
-
request(Net::HTTP::Post, url, body
|
11
|
+
def post(url, body)
|
12
|
+
request(obj: Net::HTTP::Post, url: url, body: body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_form(url, form_data)
|
16
|
+
request(obj: Net::HTTP::Post, url: url, form_data: form_data.to_a)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(url)
|
20
|
+
request(obj: Net::HTTP::Delete, url: url)
|
13
21
|
end
|
14
22
|
|
15
23
|
private
|
16
24
|
|
17
|
-
def request(
|
18
|
-
|
19
|
-
|
25
|
+
def request(obj:, url:, body: nil, form_data: nil, headers: {})
|
26
|
+
uri = URI(url)
|
27
|
+
|
28
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
http.use_ssl = true if url.start_with?('https')
|
20
30
|
|
21
|
-
|
22
|
-
|
31
|
+
request = obj.new(uri)
|
32
|
+
configure_request_headers(request, headers)
|
23
33
|
|
24
|
-
|
25
|
-
|
34
|
+
request.body = body if body
|
35
|
+
request.set_form(form_data, 'multipart/form-data') if form_data
|
26
36
|
|
27
|
-
|
37
|
+
track_request_time(request) do
|
28
38
|
response = http.request(request)
|
29
39
|
|
30
40
|
[response.code.to_i, response.body]
|
@@ -34,17 +44,20 @@ module EnotasApi
|
|
34
44
|
def configure_request_headers(request, custom_headers)
|
35
45
|
{
|
36
46
|
'Authorization' => "Basic #{EnotasApi::Configuration.current.api_key}",
|
47
|
+
"Accept": 'application/json',
|
37
48
|
'Content-Type' => 'application/json',
|
38
|
-
'User-Agent' => 'Enotas-Ruby-SDK'
|
39
|
-
"Accept": 'application/json'
|
49
|
+
'User-Agent' => 'Enotas-Ruby-SDK'
|
40
50
|
}.merge(custom_headers).each { |key, value| request[key] = value }
|
41
51
|
end
|
42
52
|
|
43
|
-
def track_request_time(
|
53
|
+
def track_request_time(request)
|
44
54
|
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
45
55
|
value = yield
|
46
56
|
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
47
|
-
|
57
|
+
|
58
|
+
info = "#{request.method} #{request.path}"
|
59
|
+
time = "#{(finish - start).round(2)} seconds"
|
60
|
+
EnotasApi::Configuration.current.logger.info("[RequestProvider] #{info} done in #{time}")
|
48
61
|
value
|
49
62
|
end
|
50
63
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'type_handler'
|
4
4
|
|
5
5
|
module EnotasApi
|
6
|
-
module
|
6
|
+
module Attributable
|
7
7
|
def self.included(base)
|
8
8
|
base.extend ClassMethods
|
9
9
|
end
|
@@ -17,7 +17,11 @@ module EnotasApi
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def attribute_changed?(attribute)
|
20
|
-
attributes_changed.
|
20
|
+
attributes_changed.include?(attribute)
|
21
|
+
end
|
22
|
+
|
23
|
+
def attributes
|
24
|
+
self.class.attributes
|
21
25
|
end
|
22
26
|
|
23
27
|
def set(attributes)
|
@@ -34,16 +38,15 @@ module EnotasApi
|
|
34
38
|
|
35
39
|
module ClassMethods
|
36
40
|
def attribute(name, type)
|
37
|
-
|
41
|
+
handler = EnotasApi::TypeHandler.new(type)
|
38
42
|
|
39
43
|
(@attributes ||= {})[name] = type
|
40
|
-
|
41
|
-
define_method name do
|
42
|
-
instance_variable_get("@#{name}")
|
43
|
-
end
|
44
|
+
attr_reader name
|
44
45
|
|
45
46
|
define_method "#{name}=" do |value|
|
46
|
-
|
47
|
+
handler.validate!(value)
|
48
|
+
|
49
|
+
instance_variable_set("@#{name}", handler.entity? && value.is_a?(Hash) ? type.new(value) : value)
|
47
50
|
(@attributes_changed ||= []) << name
|
48
51
|
end
|
49
52
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'erb'
|
4
|
-
require 'CGI'
|
5
4
|
|
6
5
|
module EnotasApi
|
7
6
|
module EncodingHelper
|
@@ -9,10 +8,6 @@ module EnotasApi
|
|
9
8
|
ERB::Util.url_encode(value)
|
10
9
|
end
|
11
10
|
|
12
|
-
def query_encode(value)
|
13
|
-
CGI.escape(value)
|
14
|
-
end
|
15
|
-
|
16
11
|
def encode_query_params(params)
|
17
12
|
URI.encode_www_form(params.compact { |_k, v| v.nil? })
|
18
13
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EnotasApi
|
4
|
+
class TypeHandler
|
5
|
+
VALIDATOR = {
|
6
|
+
boolean: ->(value, _type) { value.is_a?(TrueClass) || value.is_a?(FalseClass) },
|
7
|
+
decimal: ->(value, _type) { value.is_a?(Float) || value.is_a?(Integer) },
|
8
|
+
integer: ->(value, _type) { value.is_a?(Integer) },
|
9
|
+
string: ->(value, _type) { value.is_a?(String) },
|
10
|
+
entity: ->(value, type) { value.is_a?(type) || value.is_a?(Hash) }
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def initialize(type)
|
14
|
+
@type = type
|
15
|
+
@validator_type = type.is_a?(Class) && type < EnotasApi::Entity ? :entity : type
|
16
|
+
@validator = VALIDATOR[@validator_type]
|
17
|
+
raise EnotasApi::Error, "Type #{type} not supported" unless @validator
|
18
|
+
end
|
19
|
+
|
20
|
+
def entity?
|
21
|
+
@validator_type == :entity
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate!(value)
|
25
|
+
return if value.nil? || @validator.call(value, @type)
|
26
|
+
|
27
|
+
raise EnotasApi::Error, "Invalid value set '#{value}:#{value.class}' for type '#{@type}'"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
require_relative '../common/raw_result'
|
5
|
+
|
6
|
+
module EnotasApi
|
7
|
+
module V1
|
8
|
+
class BaixarPdfNfs < EnotasApi::Request
|
9
|
+
def initialize(empresa_id, nfs_id)
|
10
|
+
uri = "/v1/empresas/#{url_encode(empresa_id)}/nfes/#{url_encode(nfs_id)}/pdf"
|
11
|
+
super(uri: uri, result_object: EnotasApi::RawResult)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
require_relative '../common/raw_result'
|
5
|
+
|
6
|
+
module EnotasApi
|
7
|
+
module V1
|
8
|
+
class BaixarPdfNfsIdExterno < EnotasApi::Request
|
9
|
+
def initialize(empresa_id, id_externo)
|
10
|
+
uri = "/v1/empresas/#{url_encode(empresa_id)}/nfes/porIdExterno/#{url_encode(id_externo)}/pdf"
|
11
|
+
super(uri: uri, result_object: EnotasApi::RawResult)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
require_relative '../common/raw_result'
|
5
|
+
|
6
|
+
module EnotasApi
|
7
|
+
module V1
|
8
|
+
class BaixarXmlNfs < EnotasApi::Request
|
9
|
+
def initialize(empresa_id, nfs_id)
|
10
|
+
uri = "/v1/empresas/#{url_encode(empresa_id)}/nfes/#{url_encode(nfs_id)}/xml"
|
11
|
+
super(uri: uri)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
require_relative '../common/raw_result'
|
5
|
+
|
6
|
+
module EnotasApi
|
7
|
+
module V1
|
8
|
+
class BaixarXmlNfsIdExterno < EnotasApi::Request
|
9
|
+
def initialize(empresa_id, id_externo)
|
10
|
+
uri = "/v1/empresas/#{url_encode(empresa_id)}/nfes/porIdExterno/#{url_encode(id_externo)}/xml"
|
11
|
+
super(uri: uri)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
|
5
|
+
module EnotasApi
|
6
|
+
module V1
|
7
|
+
class CancelarNfs < EnotasApi::Request
|
8
|
+
def initialize(empresa_id, nfs_id)
|
9
|
+
super(method: :DELETE, uri: "/v1/empresas/#{url_encode(empresa_id)}/nfes/#{url_encode(nfs_id)}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
|
5
|
+
module EnotasApi
|
6
|
+
module V1
|
7
|
+
class CancelarNfsIdExterno < EnotasApi::Request
|
8
|
+
def initialize(empresa_id, id_externo)
|
9
|
+
super(method: :DELETE, uri: "/v1/empresas/#{url_encode(empresa_id)}/nfes/porIdExterno/#{url_encode(id_externo)}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -6,12 +6,7 @@ module EnotasApi
|
|
6
6
|
module V1
|
7
7
|
class ConsultarCaracteristicasPrefeitura < EnotasApi::Request
|
8
8
|
def initialize(codigo_ibge_cidade)
|
9
|
-
|
10
|
-
super()
|
11
|
-
end
|
12
|
-
|
13
|
-
def uri
|
14
|
-
"/v1/estados/cidades/#{url_encode(@codigo_ibge_cidade)}/provedor"
|
9
|
+
super(uri: "/v1/estados/cidades/#{url_encode(codigo_ibge_cidade)}/provedor")
|
15
10
|
end
|
16
11
|
end
|
17
12
|
end
|
@@ -4,11 +4,11 @@ require_relative '../common/request'
|
|
4
4
|
|
5
5
|
module EnotasApi
|
6
6
|
module V1
|
7
|
-
class
|
7
|
+
class ConsultarCidadesServicoMunicipalUnificado < EnotasApi::Request
|
8
8
|
paginable
|
9
9
|
|
10
|
-
def
|
11
|
-
'/v1/servicos/cidades'
|
10
|
+
def initialize
|
11
|
+
super(uri: '/v1/servicos/cidades')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
|
5
|
+
module EnotasApi
|
6
|
+
module V1
|
7
|
+
class ConsultarNfs < EnotasApi::Request
|
8
|
+
def initialize(empresa_id, nfe_id)
|
9
|
+
super(uri: "/v1/empresas/#{url_encode(empresa_id)}/nfes/#{url_encode(nfe_id)}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
|
5
|
+
module EnotasApi
|
6
|
+
module V1
|
7
|
+
class ConsultarNfsIdExterno < EnotasApi::Request
|
8
|
+
def initialize(empresa_id, id_externo)
|
9
|
+
super(uri: "/v1/empresas/#{url_encode(empresa_id)}/nfes/porIdExterno/#{url_encode(id_externo)}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -9,13 +9,7 @@ module EnotasApi
|
|
9
9
|
filterable :descricao, :contains
|
10
10
|
|
11
11
|
def initialize(uf, nome_cidade)
|
12
|
-
|
13
|
-
@nome_cidade = nome_cidade
|
14
|
-
super()
|
15
|
-
end
|
16
|
-
|
17
|
-
def uri
|
18
|
-
"/v1/estados/#{url_encode(@uf)}/cidades/#{url_encode(@nome_cidade)}/servicos"
|
12
|
+
super(uri: "/v1/estados/#{url_encode(uf)}/cidades/#{url_encode(nome_cidade)}/servicos")
|
19
13
|
end
|
20
14
|
end
|
21
15
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
|
5
|
+
module EnotasApi
|
6
|
+
module V1
|
7
|
+
class DesabilitarEmpresa < EnotasApi::Request
|
8
|
+
def initialize(empresa_id)
|
9
|
+
super(method: :POST, uri: "/v1/empresas/#{url_encode(empresa_id)}/desabilitar")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common/request'
|
4
|
+
|
5
|
+
module EnotasApi
|
6
|
+
module V1
|
7
|
+
class EmitirNfs < EnotasApi::Request
|
8
|
+
def initialize(empresa_id, nfs)
|
9
|
+
super(method: :POST, uri: "/v1/empresas/#{url_encode(empresa_id)}/nfes", content: nfs.to_json)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,28 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../common/entity'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'empresa_endereco'
|
5
5
|
require_relative 'empresa_configuracoes'
|
6
6
|
|
7
7
|
module EnotasApi
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
8
|
+
module V1
|
9
|
+
class Empresa < EnotasApi::Entity
|
10
|
+
attribute :id, :string
|
11
|
+
attribute :cnpj, :string
|
12
|
+
attribute :inscricaoMunicipal, :string
|
13
|
+
attribute :inscricaoEstadual, :string
|
14
|
+
attribute :razaoSocial, :string
|
15
|
+
attribute :nomeFantasia, :string
|
16
|
+
attribute :optanteSimplesNacional, :boolean
|
17
|
+
attribute :email, :string
|
18
|
+
attribute :telefoneComercial, :string
|
19
|
+
attribute :incentivadorCultural, :boolean
|
20
|
+
attribute :regimeEspecialTributacao, :string
|
21
|
+
attribute :codigoServicoMunicipal, :string
|
22
|
+
attribute :cnae, :string
|
23
|
+
attribute :aliquotaIss, :decimal
|
24
|
+
attribute :descricaoServico, :string
|
25
|
+
attribute :itemListaServicoLC116, :string
|
26
|
+
attribute :endereco, EnotasApi::V1::EmpresaEndereco
|
27
|
+
attribute :configuracoesNFSeHomologacao, EnotasApi::V1::EmpresaConfiguracoes
|
28
|
+
attribute :configuracoesNFSeProducao, EnotasApi::V1::EmpresaConfiguracoes
|
29
|
+
end
|
27
30
|
end
|
28
31
|
end
|
@@ -3,12 +3,14 @@
|
|
3
3
|
require_relative '../../common/entity'
|
4
4
|
|
5
5
|
module EnotasApi
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
module V1
|
7
|
+
class EmpresaConfiguracoes < EnotasApi::Entity
|
8
|
+
attribute :sequencialNFe, :integer
|
9
|
+
attribute :serieNFe, :string
|
10
|
+
attribute :sequencialLoteNFe, :integer
|
11
|
+
attribute :usuarioAcessoProvedor, :string
|
12
|
+
attribute :senhaAcessoProvedor, :string
|
13
|
+
attribute :tokenAcessoProvedor, :string
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|