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
-
.authenticate ⇒ SatMx::Result
Authenticates with the SAT web service using the configured certificate and private key.
- .configuration ⇒ Object
-
.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.
Class Method Details
.authenticate ⇒ SatMx::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
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 |
.configuration ⇒ Object
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
28 29 30 31 32 |
# File 'lib/sat_mx.rb', line 28 def configure config = {} yield(config) @configuration = Configuration.new(**config) end |