This file provides guidance to Claude Code when working with code in this repository.
Use ASD-STE100 (Simplified Technical English) for all communication:
- Write short sentences (20 words maximum)
- Use active voice
- Use approved vocabulary only
- Use one meaning per word
- Write instructions as commands
Add RDoc comments to all public classes and methods. Follow this format:
##
# Short description of the class or method.
#
# @param name [Type] Description of the parameter.
# @return [Type] Description of the return value.
# @raise [ErrorClass] Description of when this error occurs.
#
# @example
# result = method_name(arg)
# # => expected outputApply this requirement to all new code and modified code.
- Make commits atomic: include only one coherent change or fix
- Do not mix unrelated work in a single commit
- Write succinct commit messages that describe the change
- Add both co-authors to each commit message:
Co-Authored-By: Leandro Marcucci <leanucci@gmail.com> Co-Authored-By: Claude <noreply@anthropic.com>
wsaa-ruby is a Ruby gem for authenticating with AFIP's WSAA (Web Service de Autenticación y Autorización). It handles the login process to obtain TOKEN and SIGN credentials needed to call other AFIP services like WSFE (electronic invoicing).
bundle install # Install dependencies
bundle exec rspec # Run all RSpec tests
bundle exec rake # Run default task (specs)Run a single test file:
bundle exec rspec spec/wsaa/client_spec.rb- Ruby >= 2.7.0 (see gemspec)
- Valid AFIP X.509 certificate and private key
- Certificate must be registered with AFIP for the target service
Wsaa(lib/wsaa.rb) - Main module with configuration and authentication entry pointsWsaa::Client(lib/wsaa/client.rb) - Orchestrates the authentication flowWsaa::Tra(lib/wsaa/tra.rb) - Builds the Ticket de Requerimiento de Acceso XMLWsaa::CmsSigner(lib/wsaa/cms_signer.rb) - Signs TRA using OpenSSL PKCS#7Wsaa::Credentials(lib/wsaa/credentials.rb) - Immutable value object for TOKEN/SIGNWsaa::CredentialStore(lib/wsaa/credential_store.rb) - File-based credential cachingWsaa::Configuration(lib/wsaa/configuration.rb) - Configuration with validationWsaa::Errors(lib/wsaa/errors.rb) - Custom exceptions
Wsaa.authenticatechecks for cached credentials inCredentialStore- If no valid cache, builds TRA XML with service name and time boundaries
- Signs TRA using CMS/PKCS#7 with certificate and private key
- Calls WSAA
loginCmsSOAP operation via Savon - Parses response to extract TOKEN and SIGN
- Caches credentials for reuse until expiration
Uses Savon ~> 2.0 for AFIP web services:
- Testing (Homologación):
https://wsaahomo.afip.gov.ar/ws/services/LoginCms - Production:
https://wsaa.afip.gov.ar/ws/services/LoginCms
require 'wsaa'
Wsaa.configure do |config|
config.pkey = 'path/to/private_key'
config.cert = 'path/to/certificate'
config.service = 'wsfe'
config.environment = :testing # or :production
end
credentials = Wsaa.authenticate
credentials.token # => "PD94bWwg..."
credentials.sign # => "GGG2XMe..."- savon (~> 2.0) - SOAP client
- rack (~> 2.0) - Pinned for httpi compatibility
- openssl - Ruby stdlib, for PKCS#7 signing
- rexml - Ruby stdlib, for XML building