Class: Afip::AuthData

Inherits:
Object
  • Object
show all
Defined in:
lib/Afip/auth_data.rb

Overview

This class handles authorization data

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.environmentObject

Returns the value of attribute environment.



9
10
11
# File 'lib/Afip/auth_data.rb', line 9

def environment
  @environment
end

.todays_data_file_nameString

Creates the data file name for a cuit number and the current day

Returns:



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

Returns:



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.(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

.wsaa_urlString

Returns the right wsaa url for the specific environment

Returns:



51
52
53
# File 'lib/Afip/auth_data.rb', line 51

def wsaa_url
  Afip::URLS[Afip.environment][:wsaa]
end

.wsfe_urlString

Returns the right wsfe url for the specific environment

Returns:



58
59
60
61
# File 'lib/Afip/auth_data.rb', line 58

def wsfe_url
  raise 'Environment not sent to either :test or :production' unless Afip::URLS.keys.include? environment
  Afip::URLS[Afip.environment][:wsfe]
end