Class: EnotasApi::Request
- Inherits:
-
Object
- Object
- EnotasApi::Request
- Includes:
- EncodingHelper, Filterable, Paginable, Searchable, Sortable
- Defined in:
- lib/enotas_api/common/request.rb
Direct Known Subclasses
V1::BaixarPdfNfs, V1::BaixarPdfNfsIdExterno, V1::BaixarXmlNfs, V1::BaixarXmlNfsIdExterno, V1::CancelarNfs, V1::CancelarNfsIdExterno, V1::ConsultarCaracteristicasPrefeitura, V1::ConsultarCidadesServicoMunicipalUnificado, V1::ConsultarEmpresa, V1::ConsultarNfs, V1::ConsultarNfsIdExterno, V1::ConsultarServicosMunicipais, V1::DesabilitarEmpresa, V1::EmitirNfs, V1::HabilitarEmpresa, V1::IncluirAtualizarEmpresa, V1::ListarEmpresas, V1::ListarNotasFiscais, V1::VincularCertificado, V1::VincularLogotipo, V2::CancelarNf, V2::CancelarNfc, V2::ConsultarEmpresa, V2::ConsultarNf, V2::ConsultarNfc, V2::EmitirNf, V2::EmitirNfc, V2::IncluirAtualizarEmpresa, V2::ListarEmpresas, V2::VincularCertificado, V2::VincularLogotipo
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#result_object ⇒ Object
readonly
Returns the value of attribute result_object.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #call ⇒ Object
- #call! ⇒ Object
-
#initialize(uri:, method: :GET, content: nil, result_object: EnotasApi::JsonResult) ⇒ Request
constructor
A new instance of Request.
- #param(name, value) ⇒ Object
- #to_json(options = nil) ⇒ Object
- #to_url ⇒ Object
Methods included from Sortable
Methods included from Searchable
Methods included from Paginable
Methods included from Filterable
Methods included from EncodingHelper
#encode_query_params, #url_encode
Constructor Details
#initialize(uri:, method: :GET, content: nil, result_object: EnotasApi::JsonResult) ⇒ Request
21 22 23 24 25 26 27 28 29 |
# File 'lib/enotas_api/common/request.rb', line 21 def initialize(uri:, method: :GET, content: nil, result_object: EnotasApi::JsonResult) @method = method @uri = uri @content = content @result_object = result_object @params = {} page if respond_to?(:page) super() end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
19 20 21 |
# File 'lib/enotas_api/common/request.rb', line 19 def content @content end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
19 20 21 |
# File 'lib/enotas_api/common/request.rb', line 19 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
19 20 21 |
# File 'lib/enotas_api/common/request.rb', line 19 def params @params end |
#result_object ⇒ Object (readonly)
Returns the value of attribute result_object.
19 20 21 |
# File 'lib/enotas_api/common/request.rb', line 19 def result_object @result_object end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
19 20 21 |
# File 'lib/enotas_api/common/request.rb', line 19 def uri @uri end |
Instance Method Details
#call ⇒ Object
31 32 33 34 35 |
# File 'lib/enotas_api/common/request.rb', line 31 def call code, content = make_request result_object.new(code, content) end |
#call! ⇒ Object
37 38 39 40 41 42 |
# File 'lib/enotas_api/common/request.rb', line 37 def call! result = call raise EnotasApi::Error, "[Request][ERROR] Status:#{result.status_code}\n#{result.to_json}" if result.error? result end |
#param(name, value) ⇒ Object
59 60 61 62 |
# File 'lib/enotas_api/common/request.rb', line 59 def param(name, value) @params[name] = value self end |
#to_json(options = nil) ⇒ Object
53 54 55 56 57 |
# File 'lib/enotas_api/common/request.rb', line 53 def to_json( = nil) return nil if content.nil? content.is_a?(String) ? content : content.to_json() end |
#to_url ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/enotas_api/common/request.rb', line 44 def to_url url = "#{base_url}#{uri}" query_params = encode_query_params(params) if params url += "?#{query_params}" unless query_params&.empty? url end |