Class: Termworld::Credential
- Inherits:
-
Object
- Object
- Termworld::Credential
- Defined in:
- lib/termworld/credential.rb
Instance Attribute Summary collapse
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
3 4 5 |
# File 'lib/termworld/credential.rb', line 3 def @error_message end |
Class Method Details
.get_credential ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/termworld/credential.rb', line 21 def get_credential email, token = nil begin File.open(Termworld::CREDENTIAL_FILE_NAME) do |file| email, token = file.read.split("\n") end rescue return [nil, nil] end [email, token] end |
Instance Method Details
#logged_in? ⇒ Boolean
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/termworld/credential.rb', line 4 def logged_in? if !File.exists?(Termworld::CREDENTIAL_FILE_NAME) @error_message = Utils::Color.reden "Login required" return false end email, token = Credential.get_credential File.open(Termworld::CREDENTIAL_FILE_NAME) do |file| email, token = file.read.split("\n") end res = $api_client.call(:post, '/login', {email: email, token: token}) if res.code != 200 @error_message = Utils::Color.reden "Wrong credential\nPlease login again" return false end true end |