From 8616397c8ece394343474347cc10cf9fdfd0913c Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Mon, 14 Sep 2015 22:23:55 -0700 Subject: [PATCH] Properly handle token requests --- lib/vmfloaty/auth.rb | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/vmfloaty/auth.rb b/lib/vmfloaty/auth.rb index eff9d8e..ac262e5 100644 --- a/lib/vmfloaty/auth.rb +++ b/lib/vmfloaty/auth.rb @@ -12,7 +12,13 @@ class Auth end resp_body = JSON.parse(resp.body) - resp_body + if resp_body["ok"] + return resp_body["token"] + else + STDERR.puts "There was a problem with your request:" + puts resp_body + exit 1 + end end def self.delete_token(verbose, url, user, password, token) @@ -25,7 +31,13 @@ class Auth response = conn.delete "/token/#{token}" res_body = JSON.parse(response) - puts res_body + if resp_body["ok"] + puts resp_body + else + STDERR.puts "There was a problem with your request:" + puts resp_body + exit 1 + end end def self.token_status(verbose, url, user, password, token) @@ -38,6 +50,13 @@ class Auth response = conn.get "/token/#{token}" res_body = JSON.parse(response.body) - puts res_body + + if resp_body["ok"] + puts resp_body + else + STDERR.puts "There was a problem with your request:" + puts resp_body + exit 1 + end end end