Class: Afip::AuthData
- Inherits:
-
Object
- Object
- Afip::AuthData
- Defined in:
- lib/Afip/auth_data.rb
Overview
This class handles authorization data
Class Attribute Summary collapse
-
.environment ⇒ Object
Returns the value of attribute environment.
-
.todays_data_file_name ⇒ String
Creates the data file name for a cuit number and the current day.
Class Method Summary collapse
-
.auth_hash(service = "wsfe") ⇒ Hash
Returns the authorization hash, containing the Token, Signature and Cuit.
-
.fetch(service = "wsfe") ⇒ Object
Fetches WSAA Authorization Data to build the datafile for the day.
-
.wsaa_url ⇒ String
Returns the right wsaa url for the specific environment.
-
.wsfe_url ⇒ String
Returns the right wsfe url for the specific environment.
Class Attribute Details
.environment ⇒ Object
Returns the value of attribute environment.
9 10 11 |
# File 'lib/Afip/auth_data.rb', line 9 def environment @environment end |
.todays_data_file_name ⇒ String
Creates the data file name for a cuit number and the current day
66 67 68 |
# File 'lib/Afip/auth_data.rb', line 66 def todays_data_file_name @todays_data_file_name end |
Class Method Details
.auth_hash(service = "wsfe") ⇒ Hash
Returns the authorization hash, containing the Token, Signature and Cuit
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/Afip/auth_data.rb', line 36 def auth_hash(service = "wsfe") fetch unless Afip.constants.include?(:TOKEN) && Afip.constants.include?(:SIGN) case service when "wsfe" { 'Token' => Afip::TOKEN, 'Sign' => Afip::SIGN, 'Cuit' => Afip.cuit } when "ws_sr_padron_a4" { 'token' => Afip::TOKEN, 'sign' => Afip::SIGN, 'cuitRepresentado' => Afip.cuit } when "wsctg" { 'token' => Afip::TOKEN, 'sign' => Afip::SIGN, 'cuitRepresentado' => Afip.cuit } end end |
.fetch(service = "wsfe") ⇒ Object
Fetches WSAA Authorization Data to build the datafile for the day. It requires the private key file and the certificate to exist and to be configured as Afip.pkey and Afip.cert
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/Afip/auth_data.rb', line 15 def fetch(service = "wsfe") unless File.exists?(Afip.pkey) raise "Archivo de llave privada no encontrado en #{ Afip.pkey }" end unless File.exists?(Afip.cert) raise "Archivo certificado no encontrado en #{ Afip.cert }" end unless File.exists?(todays_data_file_name) Afip::Wsaa.login(service) end YAML.load_file(todays_data_file_name).each do |k, v| Afip.const_set(k.to_s.upcase, v) #unless Afip.const_defined?(k.to_s.upcase) end end |