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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +6 -2
  4. data/CHANGELOG.md +3 -1
  5. data/README.md +85 -76
  6. data/Rakefile +3 -6
  7. data/lib/enotas_api/common/entity.rb +7 -19
  8. data/lib/enotas_api/common/json_result.rb +42 -0
  9. data/lib/enotas_api/common/raw_result.rb +21 -0
  10. data/lib/enotas_api/common/request.rb +32 -27
  11. data/lib/enotas_api/request_provider.rb +29 -16
  12. data/lib/enotas_api/support/{dynamic_attributes.rb → attributable.rb} +12 -9
  13. data/lib/enotas_api/support/encoding_helper.rb +0 -5
  14. data/lib/enotas_api/support/type_handler.rb +30 -0
  15. data/lib/enotas_api/v1/baixar_pdf_nfs.rb +15 -0
  16. data/lib/enotas_api/v1/baixar_pdf_nfs_id_externo.rb +15 -0
  17. data/lib/enotas_api/v1/baixar_xml_nfs.rb +15 -0
  18. data/lib/enotas_api/v1/baixar_xml_nfs_id_externo.rb +15 -0
  19. data/lib/enotas_api/v1/cancelar_nfs.rb +13 -0
  20. data/lib/enotas_api/v1/cancelar_nfs_id_externo.rb +13 -0
  21. data/lib/enotas_api/v1/consultar_caracteristicas_prefeitura.rb +1 -6
  22. data/lib/enotas_api/v1/consultar_cidades_servico_municipal_unificado.rb +3 -3
  23. data/lib/enotas_api/v1/consultar_empresa.rb +1 -6
  24. data/lib/enotas_api/v1/consultar_nfs.rb +13 -0
  25. data/lib/enotas_api/v1/consultar_nfs_id_externo.rb +13 -0
  26. data/lib/enotas_api/v1/consultar_servicos_municipais.rb +1 -7
  27. data/lib/enotas_api/v1/desabilitar_empresa.rb +13 -0
  28. data/lib/enotas_api/v1/emitir_nfs.rb +13 -0
  29. data/lib/enotas_api/v1/entities/empresa.rb +23 -20
  30. data/lib/enotas_api/v1/entities/empresa_configuracoes.rb +9 -7
  31. data/lib/enotas_api/v1/entities/empresa_endereco.rb +20 -0
  32. data/lib/enotas_api/v1/entities/nfs.rb +19 -0
  33. data/lib/enotas_api/v1/entities/nfs_cliente.rb +16 -0
  34. data/lib/enotas_api/v1/entities/nfs_cliente_endereco.rb +17 -0
  35. data/lib/enotas_api/v1/entities/nfs_servico.rb +21 -0
  36. data/lib/enotas_api/v1/habilitar_empresa.rb +13 -0
  37. data/lib/enotas_api/v1/incluir_atualizar_empresa.rb +13 -0
  38. data/lib/enotas_api/v1/listar_empresas.rb +2 -2
  39. data/lib/enotas_api/v1/listar_notas_fiscais.rb +17 -0
  40. data/lib/enotas_api/v1/vincular_certificado.rb +14 -0
  41. data/lib/enotas_api/v1/vincular_logotipo.rb +14 -0
  42. data/lib/enotas_api/version.rb +1 -1
  43. metadata +26 -6
  44. data/lib/enotas_api/common/result.rb +0 -45
  45. data/lib/enotas_api/support/conversion_helper.rb +0 -31
  46. data/lib/enotas_api/v1/entities/endereco.rb +0 -18
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../common/entity'
4
+
5
+ module EnotasApi
6
+ module V1
7
+ class EmpresaEndereco < EnotasApi::Entity
8
+ attribute :codigoIbgeUf, :integer
9
+ attribute :codigoIbgeCidade, :integer
10
+ attribute :pais, :string
11
+ attribute :uf, :string
12
+ attribute :cidade, :string
13
+ attribute :logradouro, :string
14
+ attribute :numero, :string
15
+ attribute :complemento, :string
16
+ attribute :bairro, :string
17
+ attribute :cep, :string
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../common/entity'
4
+ require_relative 'nfs_cliente'
5
+ require_relative 'nfs_servico'
6
+
7
+ module EnotasApi
8
+ module V1
9
+ class Nfs < EnotasApi::Entity
10
+ attribute :idExterno, :string
11
+ attribute :ambienteEmissao, :string
12
+ attribute :enviarPorEmail, :boolean
13
+ attribute :cliente, EnotasApi::V1::NfsCliente
14
+ attribute :servico, EnotasApi::V1::NfsServico
15
+ attribute :valorTotal, :decimal
16
+ attribute :observacoes, :string
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../common/entity'
4
+ require_relative 'nfs_cliente_endereco'
5
+
6
+ module EnotasApi
7
+ module V1
8
+ class NfsCliente < EnotasApi::Entity
9
+ attribute :tipoPessoa, :string
10
+ attribute :nome, :string
11
+ attribute :email, :string
12
+ attribute :cpfCnpj, :string
13
+ attribute :endereco, EnotasApi::V1::NfsClienteEndereco
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../common/entity'
4
+
5
+ module EnotasApi
6
+ module V1
7
+ class NfsClienteEndereco < EnotasApi::Entity
8
+ attribute :logradouro, :string
9
+ attribute :numero, :string
10
+ attribute :complemento, :string
11
+ attribute :bairro, :string
12
+ attribute :cep, :string
13
+ attribute :uf, :string
14
+ attribute :cidade, :string
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../common/entity'
4
+
5
+ module EnotasApi
6
+ module V1
7
+ class NfsServico < EnotasApi::Entity
8
+ attribute :descricao, :string
9
+ attribute :aliquotaIss, :decimal
10
+ attribute :issRetidoFonte, :boolean
11
+ attribute :cnae, :string
12
+ attribute :codigoServicoMunicipio, :string
13
+ attribute :valorPis, :decimal
14
+ attribute :valorCofins, :decimal
15
+ attribute :valorCsll, :decimal
16
+ attribute :valorInss, :decimal
17
+ attribute :valorIr, :decimal
18
+ attribute :codigoInternoServicoMunicipal, :string
19
+ end
20
+ end
21
+ 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 HabilitarEmpresa < EnotasApi::Request
8
+ def initialize(empresa_id)
9
+ super(method: :POST, uri: "/v1/empresas/#{url_encode(empresa_id)}/habilitar")
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 IncluirAtualizarEmpresa < EnotasApi::Request
8
+ def initialize(empresa)
9
+ super(method: :POST, uri: '/v1/empresas', content: empresa.to_json)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,8 +9,8 @@ module EnotasApi
9
9
  searchable %i[nome_fantasia razao_social]
10
10
  sortable %i[nome_fantasia razao_social cidade data_criacao data_ultima_modificacao]
11
11
 
12
- def uri
13
- '/v1/empresas'
12
+ def initialize
13
+ super(uri: '/v1/empresas')
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../common/request'
4
+
5
+ module EnotasApi
6
+ module V1
7
+ class ListarNotasFiscais < EnotasApi::Request
8
+ paginable
9
+ filterable :status, :eq
10
+ sortable %i[data_criacao]
11
+
12
+ def initialize(empresa_id)
13
+ super(uri: "/v1/empresas/#{url_encode(empresa_id)}/nfes")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../common/request'
4
+
5
+ module EnotasApi
6
+ module V1
7
+ class VincularCertificado < EnotasApi::Request
8
+ def initialize(empresa_id, nome_arquivo, arquivo, senha)
9
+ form_data = { 'FileName' => nome_arquivo, 'arquivo' => arquivo, 'senha' => senha }
10
+ super(method: :POST_FORM, uri: "/v1/empresas/#{url_encode(empresa_id)}/certificadoDigital", content: form_data)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../common/request'
4
+
5
+ module EnotasApi
6
+ module V1
7
+ class VincularLogotipo < EnotasApi::Request
8
+ def initialize(empresa_id, nome_arquivo, arquivo)
9
+ form_data = { 'FileName' => nome_arquivo, 'logotipo' => arquivo }
10
+ super(method: :POST_FORM, uri: "/v1/empresas/#{url_encode(empresa_id)}/logo", content: form_data)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EnotasApi
4
- VERSION = '0.1.0'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enotas_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Bohrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-17 00:00:00.000000000 Z
11
+ date: 2020-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -104,25 +104,45 @@ files:
104
104
  - lib/enotas_api.rb
105
105
  - lib/enotas_api/common/entity.rb
106
106
  - lib/enotas_api/common/error.rb
107
+ - lib/enotas_api/common/json_result.rb
108
+ - lib/enotas_api/common/raw_result.rb
107
109
  - lib/enotas_api/common/request.rb
108
- - lib/enotas_api/common/result.rb
109
110
  - lib/enotas_api/configuration.rb
110
111
  - lib/enotas_api/request_provider.rb
111
- - lib/enotas_api/support/conversion_helper.rb
112
- - lib/enotas_api/support/dynamic_attributes.rb
112
+ - lib/enotas_api/support/attributable.rb
113
113
  - lib/enotas_api/support/encoding_helper.rb
114
114
  - lib/enotas_api/support/filterable.rb
115
115
  - lib/enotas_api/support/paginable.rb
116
116
  - lib/enotas_api/support/searchable.rb
117
117
  - lib/enotas_api/support/sortable.rb
118
+ - lib/enotas_api/support/type_handler.rb
119
+ - lib/enotas_api/v1/baixar_pdf_nfs.rb
120
+ - lib/enotas_api/v1/baixar_pdf_nfs_id_externo.rb
121
+ - lib/enotas_api/v1/baixar_xml_nfs.rb
122
+ - lib/enotas_api/v1/baixar_xml_nfs_id_externo.rb
123
+ - lib/enotas_api/v1/cancelar_nfs.rb
124
+ - lib/enotas_api/v1/cancelar_nfs_id_externo.rb
118
125
  - lib/enotas_api/v1/consultar_caracteristicas_prefeitura.rb
119
126
  - lib/enotas_api/v1/consultar_cidades_servico_municipal_unificado.rb
120
127
  - lib/enotas_api/v1/consultar_empresa.rb
128
+ - lib/enotas_api/v1/consultar_nfs.rb
129
+ - lib/enotas_api/v1/consultar_nfs_id_externo.rb
121
130
  - lib/enotas_api/v1/consultar_servicos_municipais.rb
131
+ - lib/enotas_api/v1/desabilitar_empresa.rb
132
+ - lib/enotas_api/v1/emitir_nfs.rb
122
133
  - lib/enotas_api/v1/entities/empresa.rb
123
134
  - lib/enotas_api/v1/entities/empresa_configuracoes.rb
124
- - lib/enotas_api/v1/entities/endereco.rb
135
+ - lib/enotas_api/v1/entities/empresa_endereco.rb
136
+ - lib/enotas_api/v1/entities/nfs.rb
137
+ - lib/enotas_api/v1/entities/nfs_cliente.rb
138
+ - lib/enotas_api/v1/entities/nfs_cliente_endereco.rb
139
+ - lib/enotas_api/v1/entities/nfs_servico.rb
140
+ - lib/enotas_api/v1/habilitar_empresa.rb
141
+ - lib/enotas_api/v1/incluir_atualizar_empresa.rb
125
142
  - lib/enotas_api/v1/listar_empresas.rb
143
+ - lib/enotas_api/v1/listar_notas_fiscais.rb
144
+ - lib/enotas_api/v1/vincular_certificado.rb
145
+ - lib/enotas_api/v1/vincular_logotipo.rb
126
146
  - lib/enotas_api/version.rb
127
147
  homepage: https://github.com/salaozen/enotas_api
128
148
  licenses:
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
-
5
- module EnotasApi
6
- class Result
7
- attr_reader :status_code
8
-
9
- def initialize(status_code, json)
10
- @status_code = status_code
11
- @data = JSON.parse(json)
12
- end
13
-
14
- def success?
15
- @status_code.between?(200, 299)
16
- end
17
-
18
- def error?
19
- !success?
20
- end
21
-
22
- def to_json(*_args)
23
- @data.to_json
24
- end
25
-
26
- def respond_to_missing?(field, _include_private)
27
- return true if @data.key?(field.to_s)
28
-
29
- super
30
- end
31
-
32
- def method_missing(field, *_args)
33
- if @data.key?(field.to_s)
34
- value = @data[field.to_s]
35
-
36
- return case value
37
- when Array then value.map { |v| EnotasApi::Result.new(@status_code, v.to_json) }
38
- when Hash then EnotasApi::Result.new(@status_code, value.to_json)
39
- else value
40
- end
41
- end
42
- super
43
- end
44
- end
45
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module EnotasApi
4
- module ConversionHelper
5
- TYPE_HANDLERS = {
6
- boolean: ->(value) { value == 'true' },
7
- decimal: ->(value) { value.to_f },
8
- entity: ->(_value) {},
9
- integer: ->(value) { value.to_i },
10
- string: ->(value) { value }
11
- }.freeze
12
-
13
- def self.support_type?(type)
14
- !type_handler(type).nil?
15
- end
16
-
17
- def self.type_handler(type)
18
- type = :entity if type.is_a?(Class) && type <= EnotasApi::Entity
19
- TYPE_HANDLERS[type]
20
- end
21
-
22
- def self.convert_value(type, value)
23
- return nil if value.nil?
24
-
25
- str_value = value.to_s
26
- return nil if type != :string && str_value.empty?
27
-
28
- type_handler(type).call(str_value)
29
- end
30
- end
31
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../common/entity'
4
-
5
- module EnotasApi
6
- class Endereco < EnotasApi::Entity
7
- attribute :codigoIbgeUf, :integer
8
- attribute :codigoIbgeCidade, :integer
9
- attribute :pais, :string
10
- attribute :uf, :string
11
- attribute :cidade, :string
12
- attribute :logradouro, :string
13
- attribute :numero, :string
14
- attribute :complemento, :string
15
- attribute :bairro, :string
16
- attribute :cep, :string
17
- end
18
- end