Class: Gdexpress::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gdexpress/client.rb

Constant Summary collapse

CONFIG_OPTIONS =
[:api_token, :dte_box, :environment]
ENVIROMENTS =
{
  testing: "T",
  production: "P"
}
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

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Client

Returns a new instance of Client.



25
26
27
# File 'lib/gdexpress/client.rb', line 25

def initialize(config = {})
  set_config(config)
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



23
24
25
# File 'lib/gdexpress/client.rb', line 23

def api_token
  @api_token
end

#dte_boxObject

Returns the value of attribute dte_box.



23
24
25
# File 'lib/gdexpress/client.rb', line 23

def dte_box
  @dte_box
end

#environmentObject

Returns the value of attribute environment.



23
24
25
# File 'lib/gdexpress/client.rb', line 23

def environment
  @environment
end

Instance Method Details

#accepted?(dte) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/gdexpress/client.rb', line 49

def accepted?(dte)
  response = fiscal_status(dte)
  response[:status].to_i == GDE_STATUS_CODES[:processed]
end

#find_dte(params = {}) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
# File 'lib/gdexpress/client.rb', line 29

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



54
55
56
57
# File 'lib/gdexpress/client.rb', line 54

def fiscal_status(dte)
  response = get "fiscal_status", dte
  response
end

#processed?(dte) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gdexpress/client.rb', line 34

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



64
65
66
67
# File 'lib/gdexpress/client.rb', line 64

def recover_pdf_base64(dte)
  response = get "recover_pdf", dte
  response[:data]
end

#recover_xml(dte) ⇒ Object



69
70
71
72
# File 'lib/gdexpress/client.rb', line 69

def recover_xml(dte)
  response = get "recover_xml", dte
  response
end

#tracking(dte) ⇒ Object



59
60
61
62
# File 'lib/gdexpress/client.rb', line 59

def tracking(dte)
  response = get "tracking", dte
  response
end