Class: Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/vmfloaty/auth.rb

Class Method Summary collapse

Class Method Details

.delete_token(verbose, url, user, password, token) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vmfloaty/auth.rb', line 21

def self.delete_token(verbose, url, user, password, token)
  if token.nil?
    STDERR.puts 'You did not provide a token'
    exit 1
  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"]
    puts res_body
  else
    STDERR.puts "There was a problem with your request:"
    puts res_body
    exit 1
  end
end

.get_token(verbose, url, user, password) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vmfloaty/auth.rb', line 6

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
    STDERR.puts "There was a problem with your request:"
    puts res_body
    exit 1
  end
end

.token_status(verbose, url, user, password, token) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vmfloaty/auth.rb', line 40

def self.token_status(verbose, url, user, password, token)
  if token.nil?
    STDERR.puts 'You did not provide a token'
    exit 1
  end

  conn = Http.get_conn_with_auth(verbose, url, user, password)

  response = conn.get "/token/#{token}"
  res_body = JSON.parse(response.body)

  if res_body["ok"]
    puts res_body
  else
    STDERR.puts "There was a problem with your request:"
    puts res_body
    exit 1
  end
end