Class: Wsaa::Tra

Inherits:
Object
  • Object
show all
Defined in:
lib/wsaa/tra.rb

Overview

Builds the Ticket de Requerimiento de Acceso (TRA) XML document.

The TRA is the access request ticket required by WSAA for authentication.

Constant Summary collapse

TIMEZONE_OFFSET =
'-03:00'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service:, generation_time: nil, expiration_time: nil, unique_id: nil) ⇒ Tra

Creates a new TRA.

Parameters:

  • service (String)

    The AFIP service to authenticate for.

  • generation_time (Time, nil) (defaults to: nil)

    Start of validity period. Defaults to today 00:00:00.

  • expiration_time (Time, nil) (defaults to: nil)

    End of validity period. Defaults to today 23:59:59.

  • unique_id (Integer, nil) (defaults to: nil)

    Unique request identifier. Defaults to current timestamp.



25
26
27
28
29
30
# File 'lib/wsaa/tra.rb', line 25

def initialize(service:, generation_time: nil, expiration_time: nil, unique_id: nil)
  @service = service
  @unique_id = unique_id || Time.now.to_i
  @generation_time = generation_time || default_generation_time
  @expiration_time = expiration_time || default_expiration_time
end

Instance Attribute Details

#expiration_timeTime (readonly)

When the TRA expires.

Returns:

  • (Time)

    the current value of expiration_time



13
14
15
# File 'lib/wsaa/tra.rb', line 13

def expiration_time
  @expiration_time
end

#generation_timeTime (readonly)

When the TRA was generated.

Returns:

  • (Time)

    the current value of generation_time



13
14
15
# File 'lib/wsaa/tra.rb', line 13

def generation_time
  @generation_time
end

#serviceString (readonly)

The AFIP service name.

Returns:

  • (String)

    the current value of service



13
14
15
# File 'lib/wsaa/tra.rb', line 13

def service
  @service
end

#unique_idInteger (readonly)

Unique identifier for the request.

Returns:

  • (Integer)

    the current value of unique_id



13
14
15
# File 'lib/wsaa/tra.rb', line 13

def unique_id
  @unique_id
end

Instance Method Details

#to_xmlString

Converts the TRA to an XML string.

Returns:

  • (String)

    The TRA as XML.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/wsaa/tra.rb', line 36

def to_xml
  doc = REXML::Document.new
  doc << REXML::XMLDecl.new('1.0', 'UTF-8')

  root = doc.add_element('loginTicketRequest', 'version' => '1.0')

  header = root.add_element('header')
  header.add_element('uniqueId').text = unique_id.to_s
  header.add_element('generationTime').text = format_time(generation_time)
  header.add_element('expirationTime').text = format_time(expiration_time)

  root.add_element('service').text = service

  output = String.new
  doc.write(output)
  output
end