module Deliveries::Couriers::Envialia::Authentication

Public Instance Methods

login_body() click to toggle source
# File lib/deliveries/couriers/envialia/authentication.rb, line 22
        def login_body
          <<~XML
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
              <soapenv:Body>
                <tns:LoginWSService___LoginCli2 xmlns:tns="http://tempuri.org/">
                  <strCodAge>#{Deliveries.courier(:envialia).config(:agency_code)}</strCodAge>
                  <strCliente>#{Deliveries.courier(:envialia).config(:username)}</strCliente>
                  <strPass>#{Deliveries.courier(:envialia).config(:password)}</strPass>
                </tns:LoginWSService___LoginCli2>
              </soapenv:Body>
            </soapenv:Envelope>
          XML
        end
login_endpoint() click to toggle source
# File lib/deliveries/couriers/envialia/authentication.rb, line 40
def login_endpoint
  if Envialia.live?
    Envialia::ENVIALIA_LOGIN_ENDPOINT_LIVE
  else
    Envialia::ENVIALIA_LOGIN_ENDPOINT_TEST
  end
end
login_headers() click to toggle source
# File lib/deliveries/couriers/envialia/authentication.rb, line 36
def login_headers
  { 'Content-Type' => 'application/json;charset=UTF-8', 'Accept' => 'application/json' }
end
session_id() click to toggle source
# File lib/deliveries/couriers/envialia/authentication.rb, line 9
def session_id
  response = HTTParty.post(
    login_endpoint,
    body: login_body,
    headers: login_headers,
    debug_output: Deliveries.debug ? Deliveries.logger : nil
  )

  raise Deliveries::ClientError unless response.success?

  response.dig('Envelope', 'Header', 'ROClientIDHeader', 'ID')
end