Skip to content
Scott Prue edited this page Dec 22, 2015 · 2 revisions

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);

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(loginData)

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);
});

Projects

Projects.get()

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);
});

Projects.add()

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);
});

Project('exampleProject').get()

Get an project's data.

Example:

//Get project's metadata
grout.Project('exampleProject').get().then(function (appInfo){
  console.log('Info for exampleProject:', appInfo);
});

Project('exampleProject').update(updateData)

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);
});

Project('exampleProject').del()

Remove a project.

Example:

//Get project's metadata
grout.Project('exampleProject').remove().then(function (appInfo){
  console.log('Project with name "exampleProject" deleted');
});

Project's Groups

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);
});

Projectlication's Files

Project('exampleProject').Files.get()

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);
});

Project('exampleProject').Files.add()

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);
});

Project('exampleProject').File(fileData).get()

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);
});

Project('exampleProject').structure

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

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.

Accounts.get()

Get accounts.

Examples:

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

Accounts.add(newAccount)

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);
});

Account(username).get()

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);
});

Account(username).update(updateData)

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

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.

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:[], project: 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 group with name 'admin'
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);
});