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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13a5351ba686d3a3210dad5388240d5cd7f6ba666bf0d5a1a91c7d9e77236695
4
- data.tar.gz: 3586d0c17bc0088e6dc3de95d1832b0b828551f717db0b84ffebe8015757d13a
3
+ metadata.gz: 4721088f9ef97e488e098c9b6df68929b1807690911634eb14d334a12b733c0c
4
+ data.tar.gz: e938a5ed1dbcbd56893e177de99770329e99e3934c365a63d2447df3eb1cea91
5
5
  SHA512:
6
- metadata.gz: 64e30fef619fbbed94af1d424312e812ad67b75232cef877891d60eefbb65cedcd00162f097fcb74516f22de1bd0c1017413f0d1e09a6bbedd0acda35b474770
7
- data.tar.gz: 4abbb3a41c1585e7f74056e903860313fbc65703611f3129820619d2417ab0d3744539f2b10d364d3595f1d0eff4ed7669b97750f09d887bd70fb605e0695cb1
6
+ metadata.gz: bc396e03d1883571e80ded83c31d0a37d3248a5e2ad080dd4f4693cbeab1d00a37720cf84088a7f087eb0f757d485847dc4b2f26c236f2b291848404718a6cd5
7
+ data.tar.gz: d0437e3cc3b6e4981d9d54a4854796fa68a0a3ac3516dc0211fc2e7dc29688925f261a38d4945cb7d9b4bc2019a5829dd85d5aca6acc9eb376c85423044c2794
data/.gitignore CHANGED
@@ -9,5 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ *.gem
12
13
 
13
14
  sample.rb
@@ -5,11 +5,15 @@ AllCops:
5
5
  - sample.rb
6
6
  NewCops: enable
7
7
  UseCache: true
8
+ Layout/LineLength:
9
+ Max: 150
10
+ Metrics/AbcSize:
11
+ Max: 20
8
12
  Metrics/BlockLength:
9
13
  Exclude:
10
14
  - spec/**/*.rb
11
- Metrics/LineLength:
12
- Max: 150
15
+ Metrics/MethodLength:
16
+ Max: 15
13
17
  Naming/MethodParameterName:
14
18
  Enabled: false
15
19
  RSpec/ExampleLength:
@@ -1,2 +1,4 @@
1
+ # 1.0.0
2
+ - Implemenado suporte completo a API V1 (NFS-e)
1
3
  # 0.1.0
2
- * Versão em desenvolvimento, ainda não disponível para utilizar em produção
4
+ - WIP (ainda não disponível para uso em produção)
data/README.md CHANGED
@@ -1,14 +1,18 @@
1
- # EnotasApi (WORK IN PROGRESS)
1
+ # EnotasApi
2
2
  *enotas_api* é um cliente ruby para a [API](https://docs.enotasgw.com.br/reference) do [e-notas](https://enotas.com.br/).
3
3
 
4
- Não oficial, porém com design simples e suportada com carinho por [@salaozen](https://github.com/salaozen).
4
+ EnotasApi é uma gem não oficial porém com design simples, livre de dependências
5
+
6
+ Criada e mantida com carinho por [@salaozen](https://github.com/salaozen).
5
7
 
6
8
  ## English Readers
7
9
  *enotas_api* is a ruby api client for [e-notas](https://enotas.com.br/) [API](https://docs.enotasgw.com.br/reference).
8
10
 
9
- Non oficial, but well supported with love by [@salaozen](https://github.com/salaozen).
11
+ EnotasApi its a non oficial, but well with simple design an dependency free
12
+
13
+ Created and supported with love by [@salaozen](https://github.com/salaozen).
10
14
 
11
- Because e-notas api is entire in portuguese, the code and documentation from here will also be. Sorry about that. :D
15
+ PS: Because e-notas api is entire in portuguese, the code and documentation from here will also be. Sorry about that. :D
12
16
 
13
17
  ## Dependencias
14
18
  EnotasApi não depende de nenhuma Gem externa para executar, (aloha dependency hell).
@@ -32,7 +36,7 @@ Ou instale você mesmo com:
32
36
  $ gem install enotas_api
33
37
  ```
34
38
 
35
- ## Utilização (WIP)
39
+ ## Utilização
36
40
 
37
41
  Primeiro é necessário configurar o `EnotasApi`
38
42
  ```ruby
@@ -69,78 +73,83 @@ result = instance.call
69
73
  result.to_json # = <JSON retornado pela API do e-notas>
70
74
  ```
71
75
 
72
- ### Lista de objetos disponiveis
73
- ```ruby
74
- EnotasApi::V1::ConsultarCaracteristicasPrefeitura.new(codigo_ibge_cidade)
75
-
76
- EnotasApi::V1::ConsultarCidadesServicioMunicipalUnificado.new
77
-
78
- EnotasApi::V1::ConsultarEmpresa.new(id)
79
-
80
- EnotasApi::V1::ConsultarServicosMunicipais.new(uf, nome_cidade)
81
-
82
- EnotasApi::V1::ListarEmpresas.new
83
- ```
84
-
85
-
86
76
  ## Endpoints suportados (marcados com X) e em desenvolvimento (sem marcação)
87
- API - NFS-e (V1) - [Documentação](https://docs.enotasgw.com.br/reference)
88
- - [x] Empresa: Consultar Empresa
89
- - [x] Empresa: Listar Empresas
90
- - [ ] Empresa: Incluir / Atualizar Empresa
91
- - [ ] Empresa: Vincular Certificado
92
- - [ ] Empresa: Vincular Logotipo
93
- - [ ] Empresa: Desabilitar Empresa
94
- - [ ] Empresa: Habilitar Empresa
95
- - [ ] NFS-E: Listar Notas Fiscais
96
- - [ ] NFS-E: Consultar pelo ID do Gateway
97
- - [ ] NFS-E: Consultar pelo Id Externo
98
- - [ ] NFS-E: Download XML
99
- - [ ] NFS-E: Download XML (IdExterno)
100
- - [ ] NFS-E: Download PDF
101
- - [ ] NFS-E: Download PDF (IdExterno)
102
- - [ ] NFS-E: Emissão de Nota Fiscal
103
- - [ ] NFS-E: Cancelar
104
- - [ ] NFS-E: Cancelar (IdExterno)
105
- - [x] API Complementar: Serviços Municipais da Cidade
106
- - [x] API Complementar: Características da Prefeitura
107
- - [x] API Complementar: Cidades com Serviço Municipal Unificado
108
-
109
- API - NF-e & NFC-e (v2) - [Documentação](https://docs.enotasgw.com.br/v2/reference)
110
- - [ ] Empresa: Incluir/Alterar Empresa
111
- - [ ] Empresa: Vincular Certificado
112
- - [ ] Empresa: Vincular Logotipo
113
- - [ ] Empresa: Consultar Empresa
114
- - [ ] Empresa: Listar Empresas
115
- - [ ] NFC-E: Emitir Nota Fiscal
116
- - [ ] NFC-E: Consultar Nota Fiscal
117
- - [ ] NFC-E: Consultar XML
118
- - [ ] NFC-E: Cancelar Nota Fiscal
119
- - [ ] NFC-E: Consultar XML de Envio do Cancelamento
120
- - [ ] NFC-E: Consultar XML de Retorno do Cancelamento
121
- - [ ] NFC-E: Inutilizar Numeração
122
- - [ ] NFC-E: Consultar Inutilização de Número da Nota Fiscal
123
- - [ ] NFC-E: Consultar XML de Inutilização
124
- - [ ] NF-E: Emitir Nota Fiscal
125
- - [ ] NF-E: Consultar Nota Fiscal
126
- - [ ] NF-E: Cancelar Nota Fiscal
127
- - [ ] NF-E: Consultar XML de Cancelamento
128
- - [ ] NF-E: Emitir Carta de Correção pela Chave da NF-e
129
- - [ ] NF-E: Consultar Carta de Correção
130
- - [ ] NF-E: Consultar XML da Carta de Correção
131
- - [ ] NF-E: Inutilizar Numeração
132
- - [ ] NF-E: Consultar Inutilização de Número da Nota Fiscal
133
- - [ ] NF-E: Consultar XML de Inutilização
134
- - [ ] S@T - SÃO PAULO: Download EXE customizado do S@T
135
- - [ ] Consulta de nota prestada (emitida): NFS-e - Consulta de Nota Prestada (Emitida)
136
- - [ ] Consulta de nota tomada (recebida): NF-e - Consulta de Nota Tomada (Recebida)
137
- - [ ] Consulta de nota tomada (recebida): NF-e - Consulta de Nota Tomada sem manifestação
138
- - [ ] Consulta de nota tomada (recebida): NFS-e - Consulta de Nota Tomada (Recebida)
139
- - [ ] Manifestação de destinatário - NF-E: Manifestação de Destinatário (NF-e)
77
+ Atualmente EnotasApi suporta por complexo a API V1 do enotas (NFS-e)
78
+ O suporte as novas APIs (V2) com suporte a NFC-e e NF-e estarão disponíveis em breve.
79
+
80
+ - [NFS-e (V1)](https://docs.enotasgw.com.br/reference)
81
+ - Empresa
82
+ - [x] Consultar Empresa - `EnotasApi::V1::ConsultarEmpresa`
83
+ - [x] Listar Empresas - `EnotasApi::V1::ListarEmpresas`
84
+ - [x] Incluir / Atualizar Empresa - `EnotasApi::V1::IncluirAtualizarEmpresa`
85
+ - [x] Vincular Certificado - `EnotasApi::V1::VincularCertificado`
86
+ - [x] Vincular Logotipo - `EnotasApi::V1::VincularLogotipo`
87
+ - [x] Desabilitar Empresa - `EnotasApi::V1::DesabilitarEmpresa`
88
+ - [x] Habilitar Empresa - `EnotasApi::V1::HabilitarEmpresa`
89
+ - Nota Fiscal eletrônica de serviço (NFS-e)
90
+ - [x] Listar Notas Fiscais - `EnotasApi::V1::ListarNotasFiscais`
91
+ - [x] Consultar pelo ID do Gateway - `EnotasApi::V1::ConsultarNotaFiscal`
92
+ - [x] Consultar pelo Id Externo - `EnotasApi::V1::ConsultarNotaFiscalIdExterno`
93
+ - [x] Download XML - `EnotasApi::V1::BaixarXmlNfs`
94
+ - [x] Download XML (IdExterno) - `EnotasApi::V1::BaixarXmlNfsIdExterno`
95
+ - [x] Download PDF - `EnotasApi::V1::BaixarPdfNfs`
96
+ - [x] Download PDF (IdExterno) - `EnotasApi::V1::BaixarPdfNfsIdExterno`
97
+ - [X] Emissão de Nota Fiscal - `EnotasApi::V1::EmitirNfs`
98
+ - [X] Cancelar - `EnotasApi::V1::CancelarNfs`
99
+ - [X] Cancelar (IdExterno) - `EnotasApi::V1::CancelarNfsIdExterno`
100
+ - API Complementar
101
+ - [x] Serviços Municipais da Cidade - `EnotasApi::V1::ConsultarServicosMunicipais`
102
+ - [x] Características da Prefeitura - `EnotasApi::V1::ConsultarCaracteristicasPrefeitura`
103
+ - [x] Cidades com Serviço Municipal Unificado - `EnotasApi::V1::ConsultarCidadesServicoMunicipalUnificado`
104
+ - [NF-e & NFC-e (v2)](https://docs.enotasgw.com.br/v2/reference)
105
+ - Empresa
106
+ - [ ] Incluir/Alterar Empresa
107
+ - [ ] Vincular Certificado
108
+ - [ ] Vincular Logotipo
109
+ - [ ] Consultar Empresa
110
+ - [ ] Listar Empresas
111
+ - Nota Fiscal eletrônica de consumidor (NFC-e)
112
+ - [ ] Emitir Nota Fiscal
113
+ - [ ] Consultar Nota Fiscal
114
+ - [ ] Consultar XML
115
+ - [ ] Cancelar Nota Fiscal
116
+ - [ ] Consultar XML de Envio do Cancelamento
117
+ - [ ] Consultar XML de Retorno do Cancelamento
118
+ - [ ] Inutilizar Numeração
119
+ - [ ] Consultar Inutilização de Número da Nota Fiscal
120
+ - [ ] Consultar XML de Inutilização
121
+ - Nota fiscal eletrônica de produto (NF-e)
122
+ - [ ] Emitir Nota Fiscal
123
+ - [ ] Consultar Nota Fiscal
124
+ - [ ] Cancelar Nota Fiscal
125
+ - [ ] Consultar XML de Cancelamento
126
+ - [ ] Emitir Carta de Correção pela Chave da NF-e
127
+ - [ ] Consultar Carta de Correção
128
+ - [ ] Consultar XML da Carta de Correção
129
+ - [ ] Inutilizar Numeração
130
+ - [ ] Consultar Inutilização de Número da Nota Fiscal
131
+ - [ ] Consultar XML de Inutilização
132
+ - S@T - SÃO PAULO
133
+ - [ ] Download EXE customizado do S@T
134
+ - Consulta de nota prestada (emitida)
135
+ - [ ] NFS-e - Consulta de Nota Prestada (Emitida)
136
+ - Consulta de nota tomada (recebida)
137
+ - [ ] NF-e - Consulta de Nota Tomada (Recebida)
138
+ - [ ] NF-e - Consulta de Nota Tomada sem manifestação
139
+ - [ ] NFS-e - Consulta de Nota Tomada (Recebida)
140
+ - Manifestação de destinatário NF-e
141
+ - [ ] Manifestação de Destinatário (NF-e)
142
+
143
+ # Como liberar uma nova versão
144
+ 1. Atualizar o [CHANGELOG](https://github.com/salaozen/enotas_api/blob/main/CHANGELOG.md)
145
+ 1. Atualizar a versão em [version.rb](https://github.com/salaozen/enotas_api/blob/main/lib/enotas_api/version.rb)
146
+ 1. Realizar o commit
147
+ 1. Enviar ao repositório `git push origin main`
148
+ 1. Criar uma tag `git tag <VERSAO> && git push origin <VERSAO>`
149
+ 1. Gerar uma nova versão da gem `gem build enotas_api`
150
+ 1. Publicar a gem `gem push enotas_api-<VERSAO>`
140
151
  ## Contributing
141
-
142
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enotas_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/enotas_api/blob/master/CODE_OF_CONDUCT.md).
143
-
152
+ Bug reports and pull requests are welcome on GitHub at https://github.com/salaozen/enotas_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/salaozen/enotas_api/blob/main/CODE_OF_CONDUCT.md).
144
153
 
145
154
  ## License
146
155
 
@@ -148,4 +157,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
148
157
 
149
158
  ## Code of Conduct
150
159
 
151
- Everyone interacting in the EnotasApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/enotas_api/blob/master/CODE_OF_CONDUCT.md).
160
+ Everyone interacting in the EnotasApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/salaozen/enotas_api/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -2,17 +2,14 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
-
8
- desc 'Run Rubocop'
9
- task :rubocop do
10
- sh 'rubocop . --auto-correct'
11
- end
8
+ RuboCop::RakeTask.new
12
9
 
13
10
  desc 'Run All Resources Check'
14
11
  task :check do
15
- %w[rubocop spec].each do |task|
12
+ %w[rubocop:auto_correct spec].each do |task|
16
13
  Rake::Task[task].execute
17
14
  end
18
15
  end
@@ -1,29 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
- require_relative '../support/dynamic_attributes'
4
+ require_relative '../support/attributable'
5
5
 
6
6
  module EnotasApi
7
7
  class Entity
8
- include EnotasApi::DynamicAttributes
8
+ include EnotasApi::Attributable
9
9
 
10
- def apply_json(json)
11
- json.each_pair do |field, value|
12
- setter = "#{field}="
13
- send(setter, value) if respond_to?(setter)
14
- end
15
- self
16
- end
17
-
18
- def as_json(_options = {})
19
- self.class.attributes
20
- .map { |att| [att, try(att)] }
21
- .select { |e| !e[1].nil? || attribute_changed?(e[0]) }
22
- .to_h
23
- end
24
-
25
- def to_json(*options)
26
- as_json.to_json(*options)
10
+ def to_json(options = nil)
11
+ self.class.attributes.keys
12
+ .map { |att| [att, send(att)] }
13
+ .reject { |e| e[1].nil? && !attribute_changed?(e[0]) }
14
+ .to_h.to_json(options)
27
15
  end
28
16
  end
29
17
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'raw_result'
5
+
6
+ module EnotasApi
7
+ class JsonResult < EnotasApi::RawResult
8
+ def initialize(status_code, json)
9
+ @data = JSON.parse(json) unless json.nil? || json.empty?
10
+ @data = @data.first if @data.is_a?(Array) && @data.any?
11
+ content = @data.is_a?(String) ? @data : json
12
+ super(status_code, content, json)
13
+ end
14
+
15
+ def to_json(*_args)
16
+ @data.to_json
17
+ end
18
+
19
+ def respond_to_missing?(field, _include_private)
20
+ return true if complex_object? && @data.key?(field.to_s)
21
+
22
+ super
23
+ end
24
+
25
+ def method_missing(field, *_args)
26
+ if complex_object? && @data.key?(field.to_s)
27
+ value = @data[field.to_s]
28
+
29
+ return case value
30
+ when Array then value.map { |v| EnotasApi::JsonResult.new(@status_code, v.to_json) }
31
+ when Hash then EnotasApi::JsonResult.new(@status_code, value.to_json)
32
+ else value
33
+ end
34
+ end
35
+ super
36
+ end
37
+
38
+ def complex_object?
39
+ !@data.nil? && @data.is_a?(Hash)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnotasApi
4
+ class RawResult
5
+ attr_reader :status_code, :content, :raw_content
6
+
7
+ def initialize(status_code, content, raw_content = nil)
8
+ @status_code = status_code
9
+ @content = content
10
+ @raw_content = raw_content || content
11
+ end
12
+
13
+ def success?
14
+ status_code.between?(200, 299)
15
+ end
16
+
17
+ def error?
18
+ !success?
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'result'
3
+ require 'json'
4
+ require_relative 'json_result'
4
5
  require_relative '../support/encoding_helper'
5
6
  require_relative '../support/filterable'
6
7
  require_relative '../support/paginable'
@@ -15,20 +16,20 @@ module EnotasApi
15
16
  include EnotasApi::Searchable
16
17
  include EnotasApi::Sortable
17
18
 
18
- attr_reader :params
19
+ attr_reader :params, :uri, :content, :method, :result_object
19
20
 
20
- def initialize
21
+ def initialize(uri:, method: :GET, content: nil, result_object: EnotasApi::JsonResult)
22
+ @method = method
23
+ @uri = uri
24
+ @content = content
25
+ @result_object = result_object
21
26
  @params = {}
22
27
  page if respond_to?(:page)
23
- super
28
+ super()
24
29
  end
25
30
 
26
31
  def call
27
- code, content = case method
28
- when :GET then configuration.request_provider.get(to_url)
29
- # when :POST then configuration.request_provider.post(to_url, to_json)
30
- else raise EnotasApi::Error, "Invalid method #{@method}"
31
- end
32
+ code, content = make_request
32
33
 
33
34
  result_object.new(code, content)
34
35
  end
@@ -40,29 +41,19 @@ module EnotasApi
40
41
  result
41
42
  end
42
43
 
43
- def method
44
- :GET
45
- end
46
-
47
- def entity; end
48
-
49
- def result_object
50
- EnotasApi::Result
51
- end
52
-
53
- def uri; end
54
-
55
44
  def to_url
56
- url = "#{configuration.base_url}#{uri}"
45
+ url = "#{base_url}#{uri}"
57
46
 
58
- query_params = encode_query_params(@params) if @params
47
+ query_params = encode_query_params(params) if params
59
48
  url += "?#{query_params}" unless query_params&.empty?
60
49
 
61
50
  url
62
51
  end
63
52
 
64
- def to_json(*_args)
65
- @entity&.to_json
53
+ def to_json(options = nil)
54
+ return nil if content.nil?
55
+
56
+ content.is_a?(String) ? content : content.to_json(options)
66
57
  end
67
58
 
68
59
  def param(name, value)
@@ -72,8 +63,22 @@ module EnotasApi
72
63
 
73
64
  private
74
65
 
75
- def configuration
76
- EnotasApi::Configuration.current
66
+ def make_request
67
+ case method
68
+ when :GET then request_provider.get(to_url)
69
+ when :POST then request_provider.post(to_url, content)
70
+ when :POST_FORM then request_provider.post_form(to_url, content)
71
+ when :DELETE then request_provider.delete(to_url)
72
+ else raise EnotasApi::Error, "Invalid http method '#{method}'"
73
+ end
74
+ end
75
+
76
+ def base_url
77
+ EnotasApi::Configuration.current.base_url
78
+ end
79
+
80
+ def request_provider
81
+ EnotasApi::Configuration.current.request_provider
77
82
  end
78
83
  end
79
84
  end