(#1) Add token status and delete methods

This commit is contained in:
Brian Cain 2015-09-07 14:11:05 -07:00
parent 02527b9665
commit d3b1af4a06
2 changed files with 54 additions and 5 deletions

View file

@ -3,20 +3,41 @@ require 'json'
require 'vmfloaty/http'
class Auth
def self.get_token(user, url, password)
def self.get_token(url, user, password)
conn = Http.get_conn(url)
resp = conn.post do |req|
req.url '/v1/token'
req.headers['Content-Type'] = 'application/json'
req.user = user
end
# if ok: true, return token
resp_body = JSON.parse(resp.body)
resp_body
end
def self.delete_token(user, token)
def self.delete_token(url, user, pass, token)
if token.nil?
puts 'You did not provide a token'
return
end
conn = Http.get_conn(url)
response = conn.delete "/v1/token/#{token}"
res_body = JSON.parse(response)
puts res_body
end
def self.token_status(url, user, pass, token)
if token.nil?
puts 'You did not provide a token'
return
end
conn = Http.get_conn(url)
response = conn.get "/v1/token/#{token}"
res_body = JSON.parse(response.body)
puts res_body
end
end