Skip to content
Scott Prue edited this page Sep 8, 2015 · 2 revisions

API Documentation

Methods are part of the grout object you create in the getting started guide:

var grout = new Grout();

Authentication/Utils/Token/Storage

Grout extends Matter, which means that is has all of the same methods for Authentication, Basic Utils, and Token/Storage handling.

Here is an example of the login method (from Matter) that is used from grout:

login()

Log user in provided username/email and password.

Example:

grout.login({username: 'test', password: 'test'})
.then(function(userData){ 
  console.log('User logged in. Account:', userData.account);
});

Applications

apps.get()

Get a list of applications.

Example:

//Get applications
grout.apps.get().then(function(appsList){
  console.log('Applications:', appsList);
});

apps.add()

Add an application.

Example:

//Add an application
var appData = {name: 'exampleApp', template: 'default'};
grout.apps.add(appData).then(function(newApp){
  console.log('New application:', newApp);
});

app('exampleApp').get()

Get an application's data.

Example:

//Get application's metadata
grout.app('exampleApp').get().then(function(appInfo){
  console.log('Info for exampleApp:', appInfo);
});

app('exampleApp').update()

Update an application.

Example:

//Update application's name
var appData = {name: 'exampleApp2'};
grout.app('exampleApp').update(appData).then(function(appInfo){
  console.log('Info for exampleApp:', appInfo);
});

app('exampleApp').del()

Delete an application.

Example:

//Get application's metadata
grout.app('exampleApp').del().then(function(appInfo){
  console.log('Info for exampleApp:', appInfo);
});

Application's Files

app('exampleApp').files.get()

Get an application's files in array format.

Example:

//Get array of application's files
grout.app('exampleApp').files.get().then(function(appFiles){
  console.log('Files for exampleApp:', appFiles);
});

app('exampleApp').files.add()

Add file to application's files and upload/publish.

Example:

//Publish all of application's files
var fileData = {content: '<h2>Some html content</h2>', path: '/templates/random.html'};
grout.app('exampleApp').files.add(fileData).then(function(addedFile){
  console.log('File added successfully:', addedFile);
});

app('exampleApp').file(fileData).get()

Get an application's file contents and metadata.

Example:

//Get array of application's files
var fileData = {content: '<h2>Some html content</h2>', path: '/templates/random.html'};
grout.app('exampleApp').files.get().then(function(addedFile){
  console.log('File added successfully:', addedFile);
});

app('exampleApp').files.publish()

WARNING: METHOD STILL UNDER CONSTRUCTION

Publish all of application's files at one time.

Example:

//Publish all of application's files
grout.app('exampleApp').files.publish().then(function(structureFormat){
  console.log('Example app files in structure format:', structureFormat);
});

app('exampleApp').structure

Useful for displaying folder/file structure and children contents

Example:

//Get application's file in structure format
grout.app('exampleApp').structure.then(function(structureFormat){
  console.log('Example app files in structure format:', structureFormat);
});

Application's Groups

An application's groups work the same way that Groups works (documentation in Groups section below), just attached to app('appName').

Examples:

//Add a group
var newGroup = {name: 'admin', accounts:[]};
grout.app('exampleApp').groups().add().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

//Load a specific group
grout.app('exampleApp').group('admin').then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

Application's Directories

An application's groups work the same way that Groups works (documentation in Groups section below), just attached to app('appName').

Examples:

//Add a group
var newDirectory = {name: 'admin', accounts:[13411234523,32412234523], groups:[1241234]};
grout.app('exampleApp').directories().add().then(function(addedDirectory){
  console.log('Admin group of example app loaded:', addedDirectory);
});

//Load a specific group
grout.app('exampleApp').directory('exampleApp-testers').then(function(directoryData){
  console.log('exampleApp-tests directory of example app loaded:', directoryData);
});

Groups

Groups are equivalent to "roles". A group is a set of users accounts that can be assigned a capability all at once. For example, if you create a group called "admin" and accounts to that group, those "admins" can then be given capabilities to do things that a "users" group can not.

users.get()

Get users.

Examples:

//Get users
grout.users.get().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

users.add()

Add a group.

Examples:

//Add a group
var newUser = {username: 'test', password: 'testtest', name: 'Test user'};
grout.users().add(newUser).then(function(userData){
  console.log('New user added: ', userData);
});

user(username).get()

Get a specific user's data.

Examples:

//Get user with username "test"
grout.user('test').get().then(function(userData){
  console.log('User with username test: ', userData);
});

user(username).update()

Update a user.

Examples:

//Get users
grout.user('test').update().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

Groups

Groups are equivalent to "roles". A group is a set of users accounts that can be assigned a capability all at once. For example, if you create a group called "admin" and accounts to that group, those "admins" can then be given capabilities to do things that a "users" group can not.

groups.get()

Get groups.

Examples:

//Get groups
grout.groups.get().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

groups.add()

Add a group.

Examples:

//Add a group
var newGroup = {name: 'admin', accounts:[], application: 123};
grout.groups().add(newGroup).then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

group(groupName).get()

WARNING: CURRENTLY GETS FROM ALL GROUPS WHICH WILL BE CHANGED

Get a specific group's data.

Examples:

//Get groups
grout.group('admin').get().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

group(groupName).update()

WARNING: CURRENTLY UPDATES FROM ALL GROUPS WHICH WILL BE CHANGED

Get a specific group's data.

Examples:

//Get groups
grout.group('admin').update().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

Directories

Directories include Groups and Accounts

directories.get()

List of directories.

Example:

//Get directory named exampleApp-testers
grout.directories.add().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

directories.add()

Add a directory.

Example:

//Get directory named exampleApp-testers
grout.directories.add().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});

directory(directoryName).get()

WARNING: CURRENTLY UPDATES FROM ALL GROUPS WHICH WILL BE CHANGED

Get a specific directory's data.

Example:

//Update directories accounts by id
var updateData = {accounts:[1u98qu9wer, 2a87987, 323482398]}
grout.directory('exampleApp-testers').update().then(function(directoryData){
  console.log('exampleApp-testers directory loaded:', directoryData);
});

directory(directoryName).update()

WARNING: CURRENTLY UPDATES FROM ALL GROUPS WHICH WILL BE CHANGED

Get a specific directory's data.

Example:

//Get directory named exampleApp-testers
grout.directory('exampleApp-testers').update().then(function(groupData){
  console.log('Admin group of example app loaded:', groupData);
});
Clone this wiki locally