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 31 32 33 34 |
# File 'lib/vmfloaty/auth.rb', line 20 def self.delete_token(verbose, url, user, password, token) if token.nil? raise TokenError, 'You did not provide a token' end conn = Http.get_conn_with_auth(verbose, url, user, password) response = conn.delete "token/#{token}" res_body = JSON.parse(response.body) if res_body["ok"] return res_body else raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}" end end |
.get_token(verbose, url, user, password) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vmfloaty/auth.rb', line 7 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) if res_body["ok"] return res_body["token"] else raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}" end end |
.token_status(verbose, url, token) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vmfloaty/auth.rb', line 36 def self.token_status(verbose, url, token) if token.nil? raise TokenError, 'You did not provide a token' end conn = Http.get_conn(verbose, url) response = conn.get "token/#{token}" res_body = JSON.parse(response.body) if res_body["ok"] return res_body else raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}" end end |