Class: SysAid
- Inherits:
-
Object
- Object
- SysAid
- Defined in:
- lib/sysaid.rb
Overview
The main SysAid class
Defined Under Namespace
Classes: Activity, Project, Task, Ticket, User
Constant Summary collapse
- @@logged_in =
false- @@server_settings =
{ account: nil, username: nil, password: nil, wsdl_uri: nil, debug: false }
Class Method Summary collapse
-
.client ⇒ Object
Accessor for internal SysaidApiService object.
-
.ensure_logged_in ⇒ Object
The SysAid API isn’t clear on what creates an API timeout.
-
.logged_in? ⇒ Boolean
Returns true if logged into SysAid server Note: By design, logged_in? will try to log in if it isn’t already.
-
.login(account = nil, username = nil, password = nil, wsdl_uri = nil, debug = nil) ⇒ Object
self.login does not require credentials be passed every time.
-
.server_settings ⇒ Object
Accessor for server settings.
- .server_settings=(server_settings) ⇒ Object
-
.session_id ⇒ Object
Accessor for session ID returned by SysAid server.
Class Method Details
.client ⇒ Object
Accessor for internal SysaidApiService object. Used by SysAid::Ticket
14 15 16 |
# File 'lib/sysaid.rb', line 14 def self.client @@client end |
.ensure_logged_in ⇒ Object
The SysAid API isn’t clear on what creates an API timeout. It’s possible to login and make SOAP calls many minutes later but the API seems to timeout at some point. With the exception of the added delay, there’s no harm in simply logging in over and over with each call, so we do this in ensure_logged_in until we can get a better answer on what we can do with the SysAid API to actually ensure we’re logged in.
40 41 42 |
# File 'lib/sysaid.rb', line 40 def self.ensure_logged_in self.login unless self.logged_in? end |
.logged_in? ⇒ Boolean
Returns true if logged into SysAid server Note: By design, logged_in? will try to log in if it isn’t already
Example:
>> SysAid.logged_in?
=> true
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sysaid.rb', line 50 def self.logged_in? puts "SysAid.logged_in? called" if @@server_settings[:debug] # Until official word comes from the company, we're going to login every time # to avoid a problem with undetected timeouts. #if @@logged_in == false login #end if @@logged_in return true else return false end end |
.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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sysaid.rb', line 69 def self.login(account = nil, username = nil, password = nil, wsdl_uri = nil, debug = nil) puts "SysAid.login" if @@server_settings[:debug] if account and username and password and wsdl_uri # Save server settings in case we need to log in again later @@server_settings = { :account => 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 = @@client.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 |
.server_settings ⇒ Object
Accessor for server settings. Used by SysAid::Ticket
26 27 28 |
# File 'lib/sysaid.rb', line 26 def self.server_settings @@server_settings end |
.server_settings=(server_settings) ⇒ Object
29 30 31 32 33 |
# File 'lib/sysaid.rb', line 29 def self.server_settings=(server_settings) @@server_settings = server_settings # If they don't pass in debug, set it to false to maintain default settings @@server_settings[:debug] = false if server_settings[:debug].nil? end |
.session_id ⇒ Object
Accessor for session ID returned by SysAid server. Used by SysAid::Ticket
20 21 22 |
# File 'lib/sysaid.rb', line 20 def self.session_id @@session_id end |