Afip 1.4.6 → 1.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/Afip/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Afip
2
- VERSION = "1.4.6"
3
- end
data/lib/Afip/wsaa.rb DELETED
@@ -1,94 +0,0 @@
1
- module Afip
2
- # Authorization class. Handles interactions wiht the WSAA, to provide
3
- # valid key and signature that will last for a day.
4
- #
5
- class Wsaa
6
- # Main method for authentication and authorization.
7
- # When successful, produces the yaml file with auth data.
8
- #
9
- def self.login(service = "wsfe")
10
- tra = build_tra(service)
11
- cms = build_cms(tra)
12
- req = build_request(cms)
13
- auth = call_wsaa(req)
14
-
15
- write_yaml(auth)
16
- end
17
-
18
- protected
19
- # Builds the xml for the 'Ticket de Requerimiento de Acceso'
20
- # @return [String] containing the request body
21
- #
22
- def self.build_tra service
23
- @now = (Time.now) - 120
24
- @from = @now.strftime('%FT%T%:z')
25
- @to = (@from.to_time.end_of_day).strftime('%FT%T%:z')
26
- @id = @now.strftime('%s')
27
- tra = <<-EOF
28
- <?xml version="1.0" encoding="UTF-8"?>
29
- <loginTicketRequest version="1.0">
30
- <header>
31
- <uniqueId>#{ @id }</uniqueId>
32
- <generationTime>#{ @from }</generationTime>
33
- <expirationTime>#{ @to }</expirationTime>
34
- </header>
35
- <service>#{service}</service>
36
- </loginTicketRequest>
37
- EOF
38
- return tra
39
- end
40
-
41
- # Builds the CMS
42
- # @return [String] cms
43
- #
44
- def self.build_cms(tra)
45
- cms = `echo '#{ tra }' |
46
- #{ Afip.openssl_bin } cms -sign -in /dev/stdin -signer #{ Afip.cert } -inkey #{ Afip.pkey } -nodetach \
47
- -outform der |
48
- #{ Afip.openssl_bin } base64 -e`
49
- return cms
50
- end
51
-
52
- # Builds the CMS request to log in to the server
53
- # @return [String] the cms body
54
- #
55
- def self.build_request(cms)
56
- request = <<-XML
57
- <?xml version="1.0" encoding="UTF-8"?>
58
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://wsaa.view.sua.dvadac.desein.afip.gov">
59
- <SOAP-ENV:Body>
60
- <ns1:loginCms>
61
- <ns1:in0>
62
- #{ cms }
63
- </ns1:in0>
64
- </ns1:loginCms>
65
- </SOAP-ENV:Body>
66
- </SOAP-ENV:Envelope>
67
- XML
68
- return request
69
- end
70
-
71
- # Calls the WSAA with the request built by build_request
72
- # @return [Array] with the token and signature
73
- #
74
- def self.call_wsaa(req)
75
- response = `echo '#{ req }' | curl -k -s -H 'Content-Type: application/soap+xml; action=""' -d @- #{ Afip::AuthData.wsaa_url }`
76
- pp response
77
- response = CGI::unescapeHTML(response)
78
- token = response.scan(/\<token\>(.+)\<\/token\>/).first.first
79
- sign = response.scan(/\<sign\>(.+)\<\/sign\>/).first.first
80
- return [token, sign]
81
- end
82
-
83
- # Writes the token and signature to a YAML file in the /tmp directory
84
- #
85
- def self.write_yaml(certs)
86
- yml = <<-YML
87
- token: #{certs[0]}
88
- sign: #{certs[1]}
89
- YML
90
- `echo '#{ yml }' > /tmp/#{Afip::AuthData.environment.to_s}_Afip_#{ Afip.cuit }_#{ Time.new.strftime('%Y_%m_%d') }.yml`
91
- end
92
-
93
- end
94
- end