Skip to content

Commit

Permalink
Updated doc and example
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregoire Weber committed Mar 24, 2017
1 parent a2ba059 commit 8f2f114
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install barracks-sdk
### Create a Barracks SDK instance:
Get your user api key from the Account page of the [Barracks application](https://app.barracks.io/account).

#### Basic Barracks SDK instance :
#### Default Barracks SDK instance :
```js
var Barracks = require('barracks-sdk');

Expand Down Expand Up @@ -55,6 +55,13 @@ var packages = [
version: '4.5.6'
}
];
var customClientData = {
userEmail: 'email@gmail.com',
location: {
lgn: -77.695313,
lat: 40.103286
}
};

barracks.checkUpdate(packages, customClientData).then(function (packagesInfo) {
packagesInfo.available.forEach(function (package) {
Expand Down Expand Up @@ -84,7 +91,7 @@ The ```checkUpdate``` response is always as follow :
"available":[
// List of packages newly available for the device
{
package: "abc.edf",
reference: "abc.edf",
version: "0.0.1",
url: "https://app.barracks.io/path/to/package/version/",
size: 42,
Expand All @@ -95,7 +102,7 @@ The ```checkUpdate``` response is always as follow :
"changed":[
// List of packages already installed on the device that can be updated
{
package: "abc.edf",
reference: "abc.edf",
version: "0.0.1",
url: "https://app.barracks.io/path/to/package/version/",
size: 42,
Expand All @@ -106,14 +113,14 @@ The ```checkUpdate``` response is always as follow :
"unchanged":[
// List of packages already installed on the device that did not changed
{
package: "abc.edf",
reference: "abc.edf",
version: "0.0.1",
}
],
"unavailable":[
// List of packages already installed on the device that cannot be used by the device anymore
{
package: "abc.edf",
reference: "abc.edf",
}
]
}
Expand Down Expand Up @@ -143,12 +150,20 @@ var packages = [
];

barracks.checkUpdate(packages, customClientData).then(function (packagesInfo) {
packagesInfo.available.forEach(function (package) {
// Download the files using download
var promises = packagesInfo.available.map(function (package) {
// Download the files using download function within package
return package.download('/tmp/' + package.filename);
});

packagesInfo.changed.forEach(function (package) {
// Do something with the updated packages
promises.push(packagesInfo.changed.map(function (package) {
// Download the files using barracks.downloadPackage function
return barracks.downloadPackage(package, '/tmp/' + package.filename);
}));

return promises;
}).then(function (files) {
// Do something with the downloaded files
files.forEach(function (file) {
});
}).catch(function (err) {
// Do something with the error (See error handling section)
Expand Down
16 changes: 11 additions & 5 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,43 @@ var barracks = new Barracks({

function donwloadPackages(packages) {
var promises = packages.map(function (package) {
return package.download('/tmp/' + package.package + '_' + package.version + '_' + package.filename);
return package.download('/tmp/' + package.reference + '_' + package.version + '_' + package.filename);
});

return Promise.all(promises);
}

function handleAvailablePackages(packages) {
donwloadPackages(packages).then(function (files) {
console.log('new packages ready to install :', files);
console.log('new packages ready to install :');
files.forEach(function (file) {
console.log(file);
});
}).catch(function (err) {
console.error('Error while downloading packages', err);
});
}

function handleChangedPackages(packages) {
donwloadPackages(packages).then(function (files) {
console.log('updates ready to install :', files);
console.log('updates ready to install :');
files.forEach(function (file) {
console.log(file);
});
}).catch(function (err) {
console.error('Error while downloading packages', err);
});
}

function handleUnchangedPackages(packages) {
packages.forEach(function (package) {
console.log('package ' + package.package + ' did not change (version' + package.version + ')');
console.log('package ' + package.reference + ' did not change (version' + package.version + ')');
});
}

function handleUnavailablePackages(packages) {
packages.forEach(function (package) {
console.log('package ' + package.package + ' is not available anymore');
console.log('package ' + package.reference + ' is not available anymore');
});
}

Expand Down

0 comments on commit 8f2f114

Please sign in to comment.