Class: Auth
- Inherits:
-
Object
- Object
- Auth
- Defined in:
- lib/vmfloaty/auth.rb
Class Method Summary collapse
- .delete_token(verbose, url, user, password, token) ⇒ Object
- .get_token(verbose, url, user, password) ⇒ Object
- .token_status(verbose, url, token) ⇒ Object
Class Method Details
.delete_token(verbose, url, user, password, token) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vmfloaty/auth.rb', line 20 def self.delete_token(verbose, url, user, password, token) raise TokenError, 'You did not provide a token' if token.nil? conn = Http.get_conn_with_auth(verbose, url, user, password) response = conn.delete "token/#{token}" res_body = JSON.parse(response.body) return res_body if res_body['ok'] raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}" end |
.get_token(verbose, url, user, password) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vmfloaty/auth.rb', line 9 def self.get_token(verbose, url, user, password) conn = Http.get_conn_with_auth(verbose, url, user, password) resp = conn.post 'token' res_body = JSON.parse(resp.body) return res_body['token'] if res_body['ok'] raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}" end |
.token_status(verbose, url, token) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vmfloaty/auth.rb', line 32 def self.token_status(verbose, url, token) raise TokenError, 'You did not provide a token' if token.nil? conn = Http.get_conn(verbose, url) response = conn.get "token/#{token}" res_body = JSON.parse(response.body) return res_body if res_body['ok'] raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}" end |