Method: SysAid.login

Defined in:
lib/sysaid.rb

.login(account = nil, username = nil, password = nil, wsdl_uri = nil, debug = nil) ⇒ Object

self.login does not require credentials be passed every time. SysAid sometimes times out the session and we can simply call ‘login’ again with the saved credentials to get around the timeout.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/sysaid.rb', line 84

def self.( = nil, username = nil, password = nil, wsdl_uri = nil, debug = nil)
  puts "SysAid.login" if @@server_settings[:debug]

  if  and username and password and wsdl_uri
    # Save server settings in case we need to log in again later
    @@server_settings = { :account => , :username => username, :password => password, :wsdl_uri => wsdl_uri }
    # 'debug' parameter cannot default to false else it would override default, so use nil and check
    @@server_settings[:debug] = debug if debug != nil
  end

  begin
    @@client = Savon.client(wsdl: @@server_settings[:wsdl_uri], log: @@server_settings[:debug])

    # login
    unless @@server_settings[:account].nil?
      # Call login
      response = self.call(:login, message: { accountId: @@server_settings[:account], userName: @@server_settings[:username], password: @@server_settings[:password] })

      # Retrieve response
      @@session_id = response.to_hash[:login_response][:return]

      @@logged_in = true
    end
  rescue Net::ReadTimeout => e
    # This isn't the API timeout, this is a normal socket timeout error.
    raise SysAidException, "Unable to log into SysAid server: #{e.message}"
  end
end