contensis-sync-api
v1.0.7
Published
Allows you to Query Contensis with relevant credentials in order to sync files
Downloads
5
Readme
Usage
You will need Contensis 9 to use this plugin, to get started, install contensis-sync-api
as a development dependency:
npm install --save-dev contensis-sync-api
Now create an instance of the API
var contensisSyncAPI = require('contensis-sync-api');
var ContensisSyncApiInstance = contensisSyncAPI.create({
"user": "user",
"password": "pass",
"cmsUrl": "http://contensis-cms-url",
"project": "Project Name"
});
API
contensisSyncApi.create(Config)
Creates an instance of the Sync API to interact with
The Config object is used to create a REST connection to Contensis, you should ideally add your contensis credentials to a json file:
{
"user": "user",
"password": "pass",
"cmsUrl": "http://full-cms-url",
"project": "Project Name"
}
You can then read it in with:
var fs = require('fs')
//Remember to add your contensis-credentials.json to your .gitignore, so no one else can use your details!
var credentials = JSON.parse(fs.readFileSync('../contensis-credentials.json', 'utf8'))
//Now you can create the object using the credentials
var ContensisSyncApiInstance = contensisSyncAPI.create(credentials);
contensisSyncApi.getObject([options], callback)
Get an object from contensis along with its ETag.
- options:
- path: path of the object you wish to retrieve info for
ContensisSyncApiInstance.getObject({ path: 'foo/bar.txt' }, function(err, rsp){
// The return object is very lightweight, because we are just interested in syncing files we really only care
// about the MD5 hash of the file.
var ETag = rsp.ETag;
var success = rsp.Success
//Do something
});
contensisSyncApi.listObjects([options], callback)
List all files on a particular path that exist.
- options:
- prefix: path of the files inside the specified project you wish to retrieve such as foo. You can add a slash to the end or start, if not added it will handle this for you.
function listObjects(cb){
listItems = ContensisSyncApiInstance.listObjects({ Prefix: 'foo' }, function(err, paths){
if(err){ return cb(err); }
for (let path of paths) {
console.log(path)
}
return cb();
});
}
contensisSyncApi.deleteObjects([options], callback)
List all files on a particular path that exist.
- options:
- prefix: path of the files inside the specified project you wish to retrieve such as foo. You can add a slash to the end or start, if not added it will handle this for you.
function deleteObjects(cb){
deleteItems = ContensisSyncApiInstance.deleteObjects(['foo/1.txt', 'foo/2.txt'], function(err, rsp){
if(err){ return cb(err); }
return cb(null, rsp.Success)
});
});
}
contensisSyncApi.putObject(file, callback)
This method allows you to upload a file to Contensis, It will overwrite existing files. Most file types are supported other than complex non file like content such as Forms, Templates and Databases.
- File
- path This is the destination path of the file
- body This is a Vinyl contents object see: https://www.npmjs.com/package/vinyl