Class: Arca::WSAA
- Inherits:
-
Object
- Object
- Arca::WSAA
- Defined in:
- lib/arca/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}/test/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.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#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.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/arca/wsaa.rb', line 15 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]) @store = [:store] @ta_path = [:ta_path] || default_ta_path end |
Instance Attribute Details
#cert ⇒ Object (readonly)
Returns the value of attribute cert.
7 8 9 |
# File 'lib/arca/wsaa.rb', line 7 def cert @cert end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/arca/wsaa.rb', line 7 def client @client end |
#cuit ⇒ Object (readonly)
Returns the value of attribute cuit.
7 8 9 |
# File 'lib/arca/wsaa.rb', line 7 def cuit @cuit end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/arca/wsaa.rb', line 7 def env @env end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/arca/wsaa.rb', line 7 def key @key end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
7 8 9 |
# File 'lib/arca/wsaa.rb', line 7 def service @service end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
7 8 9 |
# File 'lib/arca/wsaa.rb', line 7 def store @store end |
#ta ⇒ Object (readonly)
Returns the value of attribute ta.
7 8 9 |
# File 'lib/arca/wsaa.rb', line 7 def ta @ta end |
Instance Method Details
#auth ⇒ Object
65 66 67 68 |
# File 'lib/arca/wsaa.rb', line 65 def auth ta = obtener_y_cachear_ta { token: ta[:token], sign: ta[:sign] } end |
#codificar_tra(pkcs7) ⇒ Object
46 47 48 |
# File 'lib/arca/wsaa.rb', line 46 def codificar_tra(pkcs7) pkcs7.to_pem.lines.to_a[1..-2].join end |
#firmar_tra(tra, key, crt) ⇒ Object
40 41 42 43 44 |
# File 'lib/arca/wsaa.rb', line 40 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
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/arca/wsaa.rb', line 27 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
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/arca/wsaa.rb', line 54 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
50 51 52 |
# File 'lib/arca/wsaa.rb', line 50 def tra(key, cert, service, ttl) codificar_tra firmar_tra(generar_tra(service, ttl), key, cert) end |