Realtime Cloud Storage

StorageRef

class StorageRef

Class with the definition of a storage reference.

Methods

StorageRef authenticate(String authenticationToken, Number timeout, [Role[] roles], [Policy[] policies], function(Boolean data) success, [function(String message) error])

Authenticate a token with the given permissions.

Parameters

String authenticationToken

The token to authenticate.

Number timeout

The time (in seconds) that the token is valid.

Role[] roles optional

An array with the name of existent roles.

Policy[] policies optional

An object with additional policies. Override policies defined by specified roles.

function(Boolean data) success

Function called when the operation completes successfully.

Arguments

Boolean data

Indicates if the token was successfully authenticated.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	privateKey: "myPrivateKey",
	authenticationToken: "myAuthenticationToken"
});

// Authenticate the token
storageRef.authenticate({
	authenticationToken: "myAuthenticationToken",
	roles:["AdminRole"],
	timeout: 3600 // in seconds	
}, 
function success(data) { 
	console.log(data); 
}, 
function error(data) { 
	console.error("Error:", data); 
});

StorageRef deleteRole(String role, function(Boolean data) success, [function(String message) error])

Removes a role associated with the subscription.

Parameters

String role

The name of the role to delete.

function(Boolean data) success

Function called when the operation completes successfully.

Arguments

Boolean data

Indicates if the role was successfully deleted. If false, no role was found to delete.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Retrieve the specified role
storageRef.deleteRole(
	"AdminRole",
	function success(role) {
		console.log(role);
	}, 
	function error(data) {
		console.error(data);		
	}
);

StorageRef getRole(String role, function(Role role) success, [function(String message) error])

Retrieves the policies that compose the role.

Parameters

String role

The name of the role to retrieve.

function(Role role) success

Function called when the operation completes successfully.

Arguments

Role role

The retrieved role.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Retrieve the specified role
storageRef.getRole(
	"AdminRole",
	function success(role) {
		console.log(role);
	}, 
	function error(data) {
		console.error(data);		
	}
);

StorageRef getRoles(String[] roles, function(Role[] roles) success, [function(String message) error])

Retrieves the specified roles policies associated with the subscription.

Parameters

String[] roles

The names of roles to retrieve.

function(Role[] roles) success

Function called when the operation completes successfully and for each existing role.

Arguments

Role[] roles

The retrieved roles.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Retrieve the specified roles
storageRef.getRoles(
	["AdminRole","EmployeeRole"],
	function success(roles) {
		console.log(roles);
	}, 
	function error(data) {
		console.error(data);		
	}
);

StorageRef getTables(function(String[] tableNames) success, [function(String message) error])

Retrieves a list of the names of the tables created by the user’s application.

Parameters

function(String[] tableNames) success

Function called when the operation completes successfully and for each existing table.

Arguments

String[] tableNames

The names of the tables.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Retrieve the metadata of all the tables
storageRef.getTables(
	function success(tableSnapshot) {
		// called for each table
		console.log(tableSnapshot.val());
	}, 
	function error(data) {
		console.error(data);		
	}
);

StorageRef isAuthenticated(String authenticationToken, function(Boolean data) callback, [function(String message) error])

Verifies if the specified token is authenticated.

Parameters

String authenticationToken

The token to verify.

function(Boolean data) callback

Function called when the operation completes successfully.

Arguments

Boolean data

Indicates if the token is authenticated.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Check if the token is authenticated
storageRef.isAuthenticated(
	"myAuthenticationToken", 
	function sucess(data) {
		console.log(data);
	}, 
	function error(data) { 
		console.error(data); 
	}
);

StorageRef listRoles(function(String[] roleNames) success, [function(String message) error])

Retrieves a list of the names of the roles created by the user’s application.

Parameters

function(String[] roleNames) success

Function called when the operation completes successfully and for each existing role.

Arguments

String[] roleNames

The names of the roles.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Retrieve all the roles
storageRef.listRoles(
	function success(roles) {
		console.log(roles);
	}, 
	function error(data) {
		console.error(data);		
	}
);

StorageRef setRole(String role, Policy policies, function(Boolean data) success, [function(String message) error])

Stores a set of rules that control access to the Storage database.

Parameters

String role

The name of the role to set.

Policy policies

An object with access rules.

function(Boolean data) success

Function called when the operation completes successfully.

Arguments

Boolean data

Indicates if role was successfully inserted.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Create a role
storageRef.setRole(
	"AdminRole",
	{
		database: {
			// allow listing all the existing tables
			listTables: ["*"],
			// allow the creation of tables		
			createTable: true
		},
		tables: {
			tests: {
				// allow all types of operations (Create, Read, Update, Delete) over the table 'tests'
				allow: "CRUD"
			}
		}
	},
	function success(data) {
		console.log(data);
	}, 
	function error(data) {
		console.error(data);		
	}
);

TableRef table(String name, [function(String message) error])

Creates a new table reference.

Parameters

String name

The table name.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Create a reference to a table called 'myTable'
var tableRef = storageRef.table("myTable");

StorageRef updateRole(String role, Policy policies, function(Boolean data) success, [function(String message) error])

Modifies a set of existing rules that control access to the Storage database.

Parameters

String role

The name of the role to set.

Policy policies

An object with access rules.

function(Boolean data) success

Function called when the operation completes successfully.

Arguments

Boolean data

Indicates if role was successfully inserted.

function(String message) error optional

Response if client side validation failed or if an error was returned from the server.

Arguments

String message

The message detailing the error.

Sample

// Create a storage reference
var storageRef = Realtime.Storage.create({
	applicationKey: "myApplicationKey",
	authenticationToken: "myAuthenticationToken"
});

// Create a role
storageRef.setRole(
	"AdminRole",
	{
		database: {
			// allow listing all the existing tables
			listTables: ["*"],
			// allow the creation of tables		
			createTable: true
		},
		tables: {
			tests: {
				// allow all types of operations (Create, Read, Update, Delete) over the table 'tests'
				allow: "CRUD"
			}
		}
	},
	function success(data) {
		console.log(data);
	}, 
	function error(data) {
		console.error(data);		
	}
);

Objects

Policy

Defines a set of rules that control access to the Storage database.

Properties

Object database

Rules regarding the use of operations

Object tables

Rules regarding the access to tables and their keys.

Role

Defines a role which is a set of rules that control access to the Storage database.

Properties

String name

The name of the role.

Policy policies

Contains the storage access rules.