Class: Cts::Mpx::User
Overview
Class to wrap the user and basic functions related to it.
Instance Attribute Summary collapse
-
#duration ⇒ Numeric
Total time to live for the token.
-
#idle_timeout ⇒ Numeric
How long the token will stay alive without communicating with the services.
-
#password ⇒ String
Password of the user.
-
#token ⇒ String
The retrieved token.
-
#username ⇒ String
Username of the user.
Instance Method Summary collapse
-
#inspect ⇒ String
Override to masq the password.
-
#sign_in(idle_timeout: nil, duration: nil) ⇒ Self
Attempt to sign the user in with the provided credentials.
-
#sign_out ⇒ Void
Sign the token out.
-
#token! ⇒ String
raise an error if the token is not set, otherwise return the token.
Instance Attribute Details
#duration ⇒ Numeric
Returns total time to live for the token.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cts/mpx/user.rb', line 14 class User include Creatable attribute name: 'username', kind_of: String attribute name: 'password', kind_of: String attribute name: 'idle_timeout', kind_of: Integer attribute name: 'duration', kind_of: Integer attribute name: 'token', kind_of: [String, NilClass] # Attempt to sign the user in with the provided credentials # @param [Numeric] idle_timeout how long the token will stay alive without communicating with the services # @param [Numeric] duration total time to live for the token # @return [Self] def sign_in(idle_timeout: nil, duration: nil) raise 'token is already set, use sign_out first.' if token arguments = {} arguments['idleTimeout'] if idle_timeout arguments['duration'] if duration headers = { 'Authorization' => "Basic #{Base64.encode64("#{username}:#{password}").tr "\n", ''}" } self.token = 'sign_in_token' response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signIn', arguments: arguments, headers: headers self.token = nil raise "sign_in exception, status: #{response.status}" unless response.status == 200 self.token = response.data['signInResponse']['token'] self end # Sign the token out # @return [Void] def sign_out arguments = { "token" => token } response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signOut', arguments: arguments @token = nil if response.status == 200 nil end # Override to masq the password # @return [String] updated output def inspect output = "#<#{self.class}:#{(object_id << 1).to_s(16)}" %i[username token idle_timeout duration].each do |attribute| value = instance_variable_get "@#{attribute}".to_sym output += " @#{attribute}=#{value}" unless value.nil? end output += '>' output end # raise an error if the token is not set, otherwise return the token # @return [String] token def token! raise "#{username} is not signed in, (token is set to nil)." unless token token end end |
#idle_timeout ⇒ Numeric
Returns how long the token will stay alive without communicating with the services.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cts/mpx/user.rb', line 14 class User include Creatable attribute name: 'username', kind_of: String attribute name: 'password', kind_of: String attribute name: 'idle_timeout', kind_of: Integer attribute name: 'duration', kind_of: Integer attribute name: 'token', kind_of: [String, NilClass] # Attempt to sign the user in with the provided credentials # @param [Numeric] idle_timeout how long the token will stay alive without communicating with the services # @param [Numeric] duration total time to live for the token # @return [Self] def sign_in(idle_timeout: nil, duration: nil) raise 'token is already set, use sign_out first.' if token arguments = {} arguments['idleTimeout'] if idle_timeout arguments['duration'] if duration headers = { 'Authorization' => "Basic #{Base64.encode64("#{username}:#{password}").tr "\n", ''}" } self.token = 'sign_in_token' response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signIn', arguments: arguments, headers: headers self.token = nil raise "sign_in exception, status: #{response.status}" unless response.status == 200 self.token = response.data['signInResponse']['token'] self end # Sign the token out # @return [Void] def sign_out arguments = { "token" => token } response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signOut', arguments: arguments @token = nil if response.status == 200 nil end # Override to masq the password # @return [String] updated output def inspect output = "#<#{self.class}:#{(object_id << 1).to_s(16)}" %i[username token idle_timeout duration].each do |attribute| value = instance_variable_get "@#{attribute}".to_sym output += " @#{attribute}=#{value}" unless value.nil? end output += '>' output end # raise an error if the token is not set, otherwise return the token # @return [String] token def token! raise "#{username} is not signed in, (token is set to nil)." unless token token end end |
#password ⇒ String
Returns password of the user.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cts/mpx/user.rb', line 14 class User include Creatable attribute name: 'username', kind_of: String attribute name: 'password', kind_of: String attribute name: 'idle_timeout', kind_of: Integer attribute name: 'duration', kind_of: Integer attribute name: 'token', kind_of: [String, NilClass] # Attempt to sign the user in with the provided credentials # @param [Numeric] idle_timeout how long the token will stay alive without communicating with the services # @param [Numeric] duration total time to live for the token # @return [Self] def sign_in(idle_timeout: nil, duration: nil) raise 'token is already set, use sign_out first.' if token arguments = {} arguments['idleTimeout'] if idle_timeout arguments['duration'] if duration headers = { 'Authorization' => "Basic #{Base64.encode64("#{username}:#{password}").tr "\n", ''}" } self.token = 'sign_in_token' response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signIn', arguments: arguments, headers: headers self.token = nil raise "sign_in exception, status: #{response.status}" unless response.status == 200 self.token = response.data['signInResponse']['token'] self end # Sign the token out # @return [Void] def sign_out arguments = { "token" => token } response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signOut', arguments: arguments @token = nil if response.status == 200 nil end # Override to masq the password # @return [String] updated output def inspect output = "#<#{self.class}:#{(object_id << 1).to_s(16)}" %i[username token idle_timeout duration].each do |attribute| value = instance_variable_get "@#{attribute}".to_sym output += " @#{attribute}=#{value}" unless value.nil? end output += '>' output end # raise an error if the token is not set, otherwise return the token # @return [String] token def token! raise "#{username} is not signed in, (token is set to nil)." unless token token end end |
#token ⇒ String
Returns the retrieved token.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cts/mpx/user.rb', line 14 class User include Creatable attribute name: 'username', kind_of: String attribute name: 'password', kind_of: String attribute name: 'idle_timeout', kind_of: Integer attribute name: 'duration', kind_of: Integer attribute name: 'token', kind_of: [String, NilClass] # Attempt to sign the user in with the provided credentials # @param [Numeric] idle_timeout how long the token will stay alive without communicating with the services # @param [Numeric] duration total time to live for the token # @return [Self] def sign_in(idle_timeout: nil, duration: nil) raise 'token is already set, use sign_out first.' if token arguments = {} arguments['idleTimeout'] if idle_timeout arguments['duration'] if duration headers = { 'Authorization' => "Basic #{Base64.encode64("#{username}:#{password}").tr "\n", ''}" } self.token = 'sign_in_token' response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signIn', arguments: arguments, headers: headers self.token = nil raise "sign_in exception, status: #{response.status}" unless response.status == 200 self.token = response.data['signInResponse']['token'] self end # Sign the token out # @return [Void] def sign_out arguments = { "token" => token } response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signOut', arguments: arguments @token = nil if response.status == 200 nil end # Override to masq the password # @return [String] updated output def inspect output = "#<#{self.class}:#{(object_id << 1).to_s(16)}" %i[username token idle_timeout duration].each do |attribute| value = instance_variable_get "@#{attribute}".to_sym output += " @#{attribute}=#{value}" unless value.nil? end output += '>' output end # raise an error if the token is not set, otherwise return the token # @return [String] token def token! raise "#{username} is not signed in, (token is set to nil)." unless token token end end |
#username ⇒ String
Returns username of the user.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cts/mpx/user.rb', line 14 class User include Creatable attribute name: 'username', kind_of: String attribute name: 'password', kind_of: String attribute name: 'idle_timeout', kind_of: Integer attribute name: 'duration', kind_of: Integer attribute name: 'token', kind_of: [String, NilClass] # Attempt to sign the user in with the provided credentials # @param [Numeric] idle_timeout how long the token will stay alive without communicating with the services # @param [Numeric] duration total time to live for the token # @return [Self] def sign_in(idle_timeout: nil, duration: nil) raise 'token is already set, use sign_out first.' if token arguments = {} arguments['idleTimeout'] if idle_timeout arguments['duration'] if duration headers = { 'Authorization' => "Basic #{Base64.encode64("#{username}:#{password}").tr "\n", ''}" } self.token = 'sign_in_token' response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signIn', arguments: arguments, headers: headers self.token = nil raise "sign_in exception, status: #{response.status}" unless response.status == 200 self.token = response.data['signInResponse']['token'] self end # Sign the token out # @return [Void] def sign_out arguments = { "token" => token } response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signOut', arguments: arguments @token = nil if response.status == 200 nil end # Override to masq the password # @return [String] updated output def inspect output = "#<#{self.class}:#{(object_id << 1).to_s(16)}" %i[username token idle_timeout duration].each do |attribute| value = instance_variable_get "@#{attribute}".to_sym output += " @#{attribute}=#{value}" unless value.nil? end output += '>' output end # raise an error if the token is not set, otherwise return the token # @return [String] token def token! raise "#{username} is not signed in, (token is set to nil)." unless token token end end |
Instance Method Details
#inspect ⇒ String
Override to masq the password
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cts/mpx/user.rb', line 57 def inspect output = "#<#{self.class}:#{(object_id << 1).to_s(16)}" %i[username token idle_timeout duration].each do |attribute| value = instance_variable_get "@#{attribute}".to_sym output += " @#{attribute}=#{value}" unless value.nil? end output += '>' output end |
#sign_in(idle_timeout: nil, duration: nil) ⇒ Self
Attempt to sign the user in with the provided credentials
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cts/mpx/user.rb', line 27 def sign_in(idle_timeout: nil, duration: nil) raise 'token is already set, use sign_out first.' if token arguments = {} arguments['idleTimeout'] if idle_timeout arguments['duration'] if duration headers = { 'Authorization' => "Basic #{Base64.encode64("#{username}:#{password}").tr "\n", ''}" } self.token = 'sign_in_token' response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signIn', arguments: arguments, headers: headers self.token = nil raise "sign_in exception, status: #{response.status}" unless response.status == 200 self.token = response.data['signInResponse']['token'] self end |
#sign_out ⇒ Void
Sign the token out
48 49 50 51 52 53 |
# File 'lib/cts/mpx/user.rb', line 48 def sign_out arguments = { "token" => token } response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signOut', arguments: arguments @token = nil if response.status == 200 nil end |
#token! ⇒ String
raise an error if the token is not set, otherwise return the token
71 72 73 74 75 |
# File 'lib/cts/mpx/user.rb', line 71 def token! raise "#{username} is not signed in, (token is set to nil)." unless token token end |