(#29) Don't system exit in Auth class

This commit cleans up the Auth class so that it no longer system exits
if an error occurs. Instead it will return nil if it could not properly
make the request, and it's on the consumer of the class to handle
error cases.
This commit is contained in:
Brian Cain 2016-09-15 08:47:38 -07:00
parent 59eb5678ed
commit b07139b64c
4 changed files with 50 additions and 25 deletions

View file

@ -12,16 +12,15 @@ class Auth
if res_body["ok"]
return res_body["token"]
else
STDERR.puts "There was a problem with your request:"
puts res_body
exit 1
STDERR.puts "There was a problem with your request:\n#{res_body}"
return nil
end
end
def self.delete_token(verbose, url, user, password, token)
if token.nil?
STDERR.puts 'You did not provide a token'
exit 1
return nil
end
conn = Http.get_conn_with_auth(verbose, url, user, password)
@ -31,16 +30,15 @@ class Auth
if res_body["ok"]
return res_body
else
STDERR.puts "There was a problem with your request:"
puts res_body
exit 1
STDERR.puts "There was a problem with your request:\n#{res_body}"
return nil
end
end
def self.token_status(verbose, url, token)
if token.nil?
STDERR.puts 'You did not provide a token'
exit 1
return nil
end
conn = Http.get_conn(verbose, url)
@ -51,9 +49,8 @@ class Auth
if res_body["ok"]
return res_body
else
STDERR.puts "There was a problem with your request:"
puts res_body
exit 1
STDERR.puts "There was a problem with your request:\n#{res_body}"
return nil
end
end
end

View file

@ -1,6 +1,6 @@
class Version
@version = '0.6.0'
@version = '0.6.1'
def self.get
@version