Class: Gdexpress::Client
- Inherits:
-
Object
- Object
- Gdexpress::Client
- Defined in:
- lib/gdexpress/client.rb
Constant Summary collapse
- CONFIG_OPTIONS =
[:api_token, :dte_box, :environment]
- API_ENDPOINTS =
{ fiscal_status: "/api/Core.svc/Core/FiscalStatus/", tracking: "/api/Core.svc/Core/Tracking/", recover_pdf: "/api/Core.svc/Core/RecoverPdf/", recover_xml: "/api/Core.svc/Core/RecoverXml/", }
- GDE_STATUS_CODES =
{ processed: 0, processing_dte: 1, }
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#dte_box ⇒ Object
Returns the value of attribute dte_box.
-
#environment ⇒ Object
Returns the value of attribute environment.
Instance Method Summary collapse
- #accepted?(dte) ⇒ Boolean
- #find_dte(params = {}) ⇒ Object
- #fiscal_status(dte) ⇒ Object
-
#initialize(config = {}) ⇒ Client
constructor
A new instance of Client.
- #processed?(dte) ⇒ Boolean
- #recover_pdf_base64(dte) ⇒ Object
- #recover_xml(dte) ⇒ Object
- #tracking(dte) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Client
Returns a new instance of Client.
21 22 23 |
# File 'lib/gdexpress/client.rb', line 21 def initialize(config = {}) set_config(config) end |
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
19 20 21 |
# File 'lib/gdexpress/client.rb', line 19 def api_token @api_token end |
#dte_box ⇒ Object
Returns the value of attribute dte_box.
19 20 21 |
# File 'lib/gdexpress/client.rb', line 19 def dte_box @dte_box end |
#environment ⇒ Object
Returns the value of attribute environment.
19 20 21 |
# File 'lib/gdexpress/client.rb', line 19 def environment @environment end |
Instance Method Details
#accepted?(dte) ⇒ Boolean
45 46 47 48 |
# File 'lib/gdexpress/client.rb', line 45 def accepted?(dte) response = fiscal_status(dte) response[:status].to_i == GDE_STATUS_CODES[:processed] end |
#find_dte(params = {}) ⇒ Object
25 26 27 28 |
# File 'lib/gdexpress/client.rb', line 25 def find_dte(params = {}) raise ArgumentError, "Missing config param" unless config_params_valid?(params, [:rut_emisor, :tipo_dte, :folio]) Gdexpress::Dte.new params end |
#fiscal_status(dte) ⇒ Object
50 51 52 53 |
# File 'lib/gdexpress/client.rb', line 50 def fiscal_status(dte) response = get "fiscal_status", dte response end |
#processed?(dte) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gdexpress/client.rb', line 30 def processed?(dte) begin response = fiscal_status dte rescue DTENotFound => e # Si no lo encontramos puede que aun haya llegado a # GDexpress Cloud, por eso decimos que no se ha procesado return false end # Estamos confiando que GDexpress devuelve Status = 1 # mientras se espera respuesta de SII return false if response[:status].to_i == GDE_STATUS_CODES[:processing_dte] true end |
#recover_pdf_base64(dte) ⇒ Object
60 61 62 63 |
# File 'lib/gdexpress/client.rb', line 60 def recover_pdf_base64(dte) response = get "recover_pdf", dte response[:data] end |
#recover_xml(dte) ⇒ Object
65 66 67 68 |
# File 'lib/gdexpress/client.rb', line 65 def recover_xml(dte) response = get "recover_xml", dte response end |
#tracking(dte) ⇒ Object
55 56 57 58 |
# File 'lib/gdexpress/client.rb', line 55 def tracking(dte) response = get "tracking", dte response end |