Module: SatMx

Defined in:
lib/sat_mx.rb,
lib/sat_mx/body.rb,
lib/sat_mx/client.rb,
lib/sat_mx/result.rb,
lib/sat_mx/signer.rb,
lib/sat_mx/version.rb,
lib/sat_mx/configuration.rb,
lib/sat_mx/authentication.rb,
lib/sat_mx/verify_request.rb,
lib/sat_mx/download_request.rb,
lib/sat_mx/download_petition.rb,
lib/sat_mx/verify_request_body.rb,
lib/sat_mx/download_request_body.rb,
lib/sat_mx/download_petition_body.rb

Defined Under Namespace

Modules: Body Classes: Authentication, Client, DownloadPetition, DownloadPetitionBody, DownloadRequest, DownloadRequestBody, Error, Signer, VerifyRequest, VerifyRequestBody, XmlAuthBody

Constant Summary collapse

Result =
Data.define(:success?, :value, :xml)
VERSION =
"0.2.0"
Configuration =
Data.define(:certificate, :private_key) do
  def initialize(certificate:, private_key:, password:)
    super(
      certificate: OpenSSL::X509::Certificate.new(File.read(certificate)),
      private_key: OpenSSL::PKey::RSA.new(
        File.read(private_key),
        password
      )
    )
  end
end

Class Method Summary collapse

Class Method Details

.authenticateSatMx::Result

Authenticates with the SAT web service using the configured certificate and private key. This method uses SOAP to communicate with the SAT authentication service and returns a token that can be used for subsequent requests.

result = SatMx.authenticate
if result.success?
  puts "Authentication token: #{result.value}"
else
  puts "Authentication failed"
end

Returns:

  • (SatMx::Result)

    A Result object containing:

    • success?: [Boolean] whether the authentication was successful

    • value: [String, nil] the authentication token if successful, nil otherwise

    • xml: [Nokogiri::XML::Document] the raw XML response from the service

See Also:



56
57
58
59
60
61
# File 'lib/sat_mx.rb', line 56

def authenticate
  Authentication.authenticate(
    certificate: configuration.certificate,
    private_key: configuration.private_key
  )
end

.configurationObject



34
35
36
# File 'lib/sat_mx.rb', line 34

def configuration
  @configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Configures the gem using a block, its not threadsafe, so its recommended call only when you’re initializing your application, e.g. in your initializers directory of your rails app

@example
 SatMx.configure do |config|
   config[:certificate] = "path/to/certificate.cer"
   config[:private_key] = "path/to/private.key"
   config[:password] = "key_password"
 end

Yields:

  • (config)


28
29
30
31
32
# File 'lib/sat_mx.rb', line 28

def configure
  config = {}
  yield(config)
  @configuration = Configuration.new(**config)
end