Class: Pwnix::Api::Client::ClientManager
- Inherits:
-
Object
- Object
- Pwnix::Api::Client::ClientManager
show all
- Includes:
- HTTParty, HTTPartyTime
- Defined in:
- lib/pwnix-api-client/node/client/client_manager.rb
Instance Method Summary
collapse
#clear_errors, #errors, #has_errors?, included, #last_error, #safe_api_call
Constructor Details
10
11
12
|
# File 'lib/pwnix-api-client/node/client/client_manager.rb', line 10
def initialize
@clients = []
end
|
Instance Method Details
#client_exists?(id) ⇒ Boolean
Public: Check if the client exists in the API
API might be down, so lets make sure this returns a true or false othewise it could be an exception string
23
24
25
26
|
# File 'lib/pwnix-api-client/node/client/client_manager.rb', line 23
def client_exists?(id)
return true if safe_api_call("/node/clients/#{id}/exist") == true
false
end
|
#create(type) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/pwnix-api-client/node/client/client_manager.rb', line 28
def create(type)
id = safe_api_call("/node/clients/create", :type => type )
if client_exists?(id)
@clients << Pwnix::Api::Client::ConsoleClient.new(id)
return true
end
false
end
|
#destroy_client(id) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/pwnix-api-client/node/client/client_manager.rb', line 46
def destroy_client(id)
if client_exists?(id)
destroyable_client = @clients.select{|c| c.id == id }.first
destroyable_client.disconnect
destroyable_client.destroy @clients.delete(destroyable_client)
return true
end
false
end
|
#get_client(id) ⇒ Object
42
43
44
|
# File 'lib/pwnix-api-client/node/client/client_manager.rb', line 42
def get_client(id)
@clients.select{|c| c.id == id }.first
end
|
#list ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/pwnix-api-client/node/client/client_manager.rb', line 57
def list
@clients = []
remote_clients = safe_api_call("/node/clients/list")
if remote_clients
remote_clients.each do |remote_client_id|
unless (@clients.select{|c| c.id == remote_client_id }).count > 0
@clients << Pwnix::Api::Client::ConsoleClient.new(remote_client_id)
end
end
end
@clients
end
|
#status ⇒ Object
14
15
16
|
# File 'lib/pwnix-api-client/node/client/client_manager.rb', line 14
def status
safe_api_call("/node/clients/status")
end
|