#268: Improve service function naming.

This commit is contained in:
Michael Jumper
2013-02-09 18:04:28 -08:00
parent c77d1413cc
commit 3a3bdb4de4
2 changed files with 74 additions and 61 deletions

View File

@@ -136,7 +136,7 @@ GuacamoleRootUI.reset = function() {
// Read connections
var connections;
try {
connections = GuacamoleService.getConnections(parameters);
connections = GuacamoleService.Connections.list(parameters);
}
catch (e) {

View File

@@ -44,29 +44,30 @@ GuacamoleService.Connection = function(protocol, id) {
};
/**
* An arbitrary Guacamole user, consisting of a username.
*
* @constructor
* @param {String} username The username associate with this user.
* Collection of service functions which deal with connections. Each function
* makes an explicit HTTP query to the server, and parses the response.
*/
GuacamoleService.User = function(username) {
GuacamoleService.Connections = {
/**
* The username associated with this user.
* Returns an array of Connections for which the current user has access.
*
* @param {String} parameters Any parameters which should be passed to the
* server for the sake of authentication
* (optional).
* @return {GuacamoleService.Connection[]} An array of Connections for
* which the current user has
* access.
*/
this.username = username;
};
GuacamoleService.getConnections = function(parameters) {
"list" : function(parameters) {
// Construct request URL
var connections_url = "connections";
if (parameters) connections_url += "?" + parameters;
var list_url = "connections";
if (parameters) list_url += "?" + parameters;
// Get connection list
var xhr = new XMLHttpRequest();
xhr.open("GET", connections_url, false);
xhr.open("GET", list_url, false);
xhr.send(null);
// If fail, throw error
@@ -86,9 +87,22 @@ GuacamoleService.getConnections = function(parameters) {
return connections;
}
};
GuacamoleService.getUsers = function(parameters) {
GuacamoleService.Users = {
/**
* Returns an array of usernames for which the current user has access.
*
* @param {String} parameters Any parameters which should be passed to the
* server for the sake of authentication
* (optional).
* @return {String[]} An array of usernames for which the current user has
* access.
*/
"list" : function(parameters) {
// Construct request URL
var users_url = "users";
@@ -107,12 +121,11 @@ GuacamoleService.getUsers = function(parameters) {
var users = new Array();
var userElements = xhr.responseXML.getElementsByTagName("user");
for (var i=0; i<userElements.length; i++) {
users.push(new GuacamoleService.User(
userElements[i].getAttribute("name")
));
}
for (var i=0; i<userElements.length; i++)
users.push(userElements[i].getAttribute("name"));
return users;
}
};