Class: SatMx::Authentication
- Inherits:
-
Object
- Object
- SatMx::Authentication
- Defined in:
- lib/sat_mx/authentication.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(xml_auth_body:, client:) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(xml_auth_body:, client:) ⇒ Authentication
Returns a new instance of Authentication.
20 21 22 23 |
# File 'lib/sat_mx/authentication.rb', line 20 def initialize(xml_auth_body:, client:) @xml_auth_body = xml_auth_body @client = client end |
Class Method Details
.authenticate(certificate:, private_key:, uuid: SecureRandom.uuid) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sat_mx/authentication.rb', line 7 def self.authenticate(certificate:, private_key:, uuid: SecureRandom.uuid) new( xml_auth_body: XmlAuthBody.new( certificate:, uuid: ), client: Client.new( private_key:, access_token: "" ) ).authenticate end |
Instance Method Details
#authenticate ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sat_mx/authentication.rb', line 25 def authenticate response = client.authenticate(xml_auth_body.generate) case response.status when 200..299 Result.new(success?: true, value: response.xml.xpath("//xmlns:AutenticaResult", xmlns: "http://DescargaMasivaTerceros.gob.mx").inner_text, xml: response.xml) when 400..599 Result.new(success?: false, value: nil, xml: response.xml) else SatMx::Error end end |