Class: Afipws::WSAA
- Inherits:
-
Object
- Object
- Afipws::WSAA
- Defined in:
- lib/afipws/wsaa.rb
Constant Summary collapse
- WSDL =
{ development: 'https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl', production: 'https://wsaa.afip.gov.ar/ws/services/LoginCms?wsdl', test: Root + '/spec/fixtures/wsaa/wsaa.wsdl' }
Instance Attribute Summary collapse
-
#cert ⇒ Object
readonly
Returns the value of attribute cert.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#cuit ⇒ Object
readonly
Returns the value of attribute cuit.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#ta ⇒ Object
readonly
Returns the value of attribute ta.
Instance Method Summary collapse
- #auth ⇒ Object
- #codificar_tra(pkcs7) ⇒ Object
- #firmar_tra(tra, key, crt) ⇒ Object
- #generar_tra(service, ttl) ⇒ Object
-
#initialize(options = {}) ⇒ WSAA
constructor
A new instance of WSAA.
- #login ⇒ Object
- #tra(key, cert, service, ttl) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ WSAA
Returns a new instance of WSAA.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/afipws/wsaa.rb', line 11 def initialize = {} @env = ([:env] || :test).to_sym @key = [:key] @cert = [:cert] @service = [:service] || 'wsfe' @ttl = [:ttl] || 2400 @cuit = [:cuit] @client = Client.new Hash([:savon]).reverse_merge(wsdl: WSDL[@env]) @ta_path = [:ta_path] || File.join(Dir.pwd, 'tmp', "#{@cuit}-#{@env}-#{@service}-ta.dump") end |
Instance Attribute Details
#cert ⇒ Object (readonly)
Returns the value of attribute cert.
3 4 5 |
# File 'lib/afipws/wsaa.rb', line 3 def cert @cert end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/afipws/wsaa.rb', line 3 def client @client end |
#cuit ⇒ Object (readonly)
Returns the value of attribute cuit.
3 4 5 |
# File 'lib/afipws/wsaa.rb', line 3 def cuit @cuit end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/afipws/wsaa.rb', line 3 def env @env end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/afipws/wsaa.rb', line 3 def key @key end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
3 4 5 |
# File 'lib/afipws/wsaa.rb', line 3 def service @service end |
#ta ⇒ Object (readonly)
Returns the value of attribute ta.
3 4 5 |
# File 'lib/afipws/wsaa.rb', line 3 def ta @ta end |
Instance Method Details
#auth ⇒ Object
60 61 62 63 |
# File 'lib/afipws/wsaa.rb', line 60 def auth ta = obtener_y_cachear_ta {token: ta[:token], sign: ta[:sign]} end |
#codificar_tra(pkcs7) ⇒ Object
41 42 43 |
# File 'lib/afipws/wsaa.rb', line 41 def codificar_tra pkcs7 pkcs7.to_pem.lines.to_a[1..-2].join end |
#firmar_tra(tra, key, crt) ⇒ Object
35 36 37 38 39 |
# File 'lib/afipws/wsaa.rb', line 35 def firmar_tra tra, key, crt key = OpenSSL::PKey::RSA.new key crt = OpenSSL::X509::Certificate.new crt OpenSSL::PKCS7.sign crt, key, tra end |
#generar_tra(service, ttl) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/afipws/wsaa.rb', line 22 def generar_tra service, ttl xml = Builder::XmlMarkup.new indent: 2 xml.instruct! xml.loginTicketRequest version: 1 do xml.header do xml.uniqueId Time.now.to_i xml.generationTime xsd_datetime Time.now - ttl xml.expirationTime xsd_datetime Time.now + ttl end xml.service service end end |
#login ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/afipws/wsaa.rb', line 49 def login response = @client.request :login_cms, in0: tra(@key, @cert, @service, @ttl) ta = Nokogiri::XML(Nokogiri::XML(response.to_xml).text) { token: ta.css('token').text, sign: ta.css('sign').text, generation_time: from_xsd_datetime(ta.css('generationTime').text), expiration_time: from_xsd_datetime(ta.css('expirationTime').text) } end |
#tra(key, cert, service, ttl) ⇒ Object
45 46 47 |
# File 'lib/afipws/wsaa.rb', line 45 def tra key, cert, service, ttl codificar_tra firmar_tra(generar_tra(service, ttl), key, cert) end |