The JavaScript SDK to interact with the Barracks API
$ npm install barracks-sdkvar Barracks = require('barracks-sdk');
var barracks = new Barracks({
apiKey: 'Your user API key',
unitId: 'The unique device identifier'
});Your user api key you can be found on the Account page of the Barracks application.
barracks.checkUpdate(currentDeviceVersion, customClientData).then(function (update) {
if (update) {
// Do something with the update
} else {
// Do something when no updates are available
}
}).catch(function (err) {
// Do something with the error (See error handling section)
});barracks.checkUpdate(currentDeviceVersion, customClientData).then(function (update) {
if (update) {
return update.download();
}
return Promise.resolve();
}).then(function (file) {
if (file) {
// Do something with the file
}
}).catch(function (err) {
// Do something with the error (See error handling section)
});barracks.checkUpdate(currentDeviceVersion, customClientData).then(function (update) {
if (update) {
update.download().then(function (file) {
// Do something with the file
}).catch(function (err) {
// Do something with the download error
});
}
}).catch(function (err) {
// Do something with the error (See error handling section)
});barracks.checkUpdateAndDownload(currentDeviceVersion, customClientData).then(function (file) {
// Do something with the file
}).catch(function (err) {
// Do something with the error (See error handling section)
});All errors returned by the SDK follow the same object format:
{
type: 'ERROR_TYPE',
message: 'Details about the error'
}Error type can be one of the the following:
REQUEST_FAILED, is returned by bothBarracks.checkUpdate()andBarracks.checkUpdateAndDownload()methods if the check update request fails. The error object also contains one additional propertyrequestErrorthat is theErrorobject returned by the request library.UNEXPECTED_SERVER_RESPONSE, is returned by bothBarracks.checkUpdate()andBarracks.checkUpdateAndDownload()methods if the HTTP response code is not200(a new update is available) or204(no update available).DOWNLOAD_FAILED, is returned by bothUpdate.download()andBarracks.checkUpdateAndDownload()methods if the download of an update package fails.DELETE_FILE_FAILED, is returned by bothUpdate.download()andBarracks.checkUpdateAndDownload()methods if the SDK fail to delete an update package that did not pass the MD5 checksum verification.CHECKSUM_VERIFICATION_FAILED, is returned by bothUpdate.download()andBarracks.checkUpdateAndDownload()methods if the MD5 checksum verification of the update package downloaded fails.MD5_HASH_CREATION_FAILED, is returned by bothUpdate.download()andBarracks.checkUpdateAndDownload()methods if the SDK is not able to generate the MD5 checksum of the update package downloaded.
- Website and Documentation
- Github Organization for other official SDKs
