-
Notifications
You must be signed in to change notification settings - Fork 3
API Documentation
Methods are part of the grout object you create in the getting started guide:
var options = {logLevel: 'trace'};
var grout = new Grout(options);
or in ES2015:
import Grout from 'kyper-grout';
const options = {logLevel: 'trace'};
let grout = new Grout(options);
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:
Log account in provided username/email and password.
Example:
grout.login({username: 'test', password: 'test'})
.then(function (accountData){
console.log('User logged in. Account:', accountData.Account);
});
Get a list of projects.
Example:
//Get projects
grout.Projects.get().then(function (projectsList){
console.log('Projects list:', projectsList);
}, function(err) {
console.error('Error getting projects list', err);
});
Add a project.
Example:
//Add an project
var appData = {name: 'exampleProject', template: 'default'};
grout.Projects.add(appData).then(function (newProject){
console.log('New project:', newProject);
}, function(err) {
console.error('Error creating new project:', err);
});
Get an project's data.
Example:
//Get project's metadata
grout.Project('exampleProject').get().then(function (appInfo){
console.log('Info for exampleProject:', appInfo);
});
Update a project.
Example:
//Update project's name
var newProjectData = {name: 'exampleProject2'};
grout.Project('exampleProject').update(newProjectData).then(function (appInfo){
console.log('Info for exampleProject:', appInfo);
});
Remove a project.
Example:
//Get project's metadata
grout.Project('exampleProject').remove().then(function (appInfo){
console.log('Project with name "exampleProject" deleted');
});
An project's groups work the same way that Groups works (documentation in Groups section below), just capitalized, which denotes the model instead of the project's parameter (Project('exampleProject').Groups
vs Project('exampleProject').groups
which is the project's groups array).
Examples:
//Add a group
var newGroup = {name: 'admin', accounts:[]};
grout.Project('exampleProject').Groups.add().then(function(groupData){
console.log('Admin group of example app loaded:', groupData);
});
//Load a specific group
grout.Project('exampleProject').Group('admin').then(function(groupData){
console.log('Admin group of example app loaded:', groupData);
});
Get a project's files in array format.
Example:
//Get array of project's files
grout.Project('exampleProject').Files.get().then(function (appFiles){
console.log('Files for exampleProject:', appFiles);
});
Add file to project's files and upload/publish.
Example:
//Publish all of project's files
var fileData = {content: '<h2>Some html content</h2>', path: '/templates/random.html'};
grout.Project('exampleProject').Files.add(fileData).then(function (addedFile){
console.log('File added successfully:', addedFile);
});
Get a project's file contents and metadata.
Example:
//Get array of project's files
var fileData = {content: '<h2>Some html content</h2>', path: '/templates/random.html'};
grout.Project('exampleProject').File(fileData).get().then(function (loadedFile){
console.log('File added successfully:', loadedFile);
});
Useful for displaying folder/file structure and children contents
Example:
//Get project's file in structure format
grout.Project('exampleProject').Files.structure.then(function(structureFormat){
console.log('Example app files in structure format:', structureFormat);
});
Groups are equivalent to roles
A group is a set of accounts 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 "accounts" group can not.
Get accounts.
Examples:
//Get accounts
grout.Accounts.get().then(function(groupData){
console.log('Admin group of example app loaded:', groupData);
});
Add a account.
Examples:
//Add a account
var newAccount = {username: 'test', password: 'testtest', name: 'John Smith'};
grout.Accounts.add(newAccount).then(function(accountData){
console.log('New account added: ', accountData);
});
Get a specific account's data.
Examples:
//Get account with username "test"
grout.Account('test').get().then(function(accountData){
console.log('User with username test: ', accountData);
});
Update a account.
Examples:
var updateData = {username: 'newusername1', name: 'Jim Smith'};
//Update account with new username and name
grout.Account('testuser').update(updateData).then(function(groupData){
console.log('Admin group of example app loaded:', groupData);
});
Groups are equivalent to "roles".
A group is a set of accounts 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 "accounts" group can not.
Get groups.
Examples:
//Get groups
grout.Groups.get().then(function(groupData){
console.log('Admin group of example app loaded:', groupData);
});
Add a group.
Examples:
//Add a group
var newGroup = {name: 'admin', accounts:[], project: 123};
grout.Groups.add(newGroup).then(function(groupData){
console.log('Admin group of example app loaded:', groupData);
});
WARNING: CURRENTLY GETS FROM ALL GROUPS WHICH WILL BE CHANGED
Get a specific group's data.
Examples:
//Get group with name 'admin'
grout.Group('admin').get().then(function(groupData){
console.log('Admin group of example app loaded:', groupData);
});
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);
});