-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract SDK helper fucntions from client
- Loading branch information
Grégoire Weber
committed
Apr 16, 2017
1 parent
9205059
commit e57305a
Showing
4 changed files
with
374 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const BarracksSDK = require('barracks-sdk'); | ||
const logger = require('../utils/logger'); | ||
|
||
class BarracksSDKProxy { | ||
|
||
constructor(options) { | ||
this.options = options; | ||
} | ||
|
||
checkUpdate(apiKey, device) { | ||
return new Promise((resolve, reject) => { | ||
logger.debug('checking update:', device); | ||
const sdk = new BarracksSDK({ | ||
baseURL: this.options.baseUrl, | ||
apiKey, | ||
unitId: device.unitId | ||
}); | ||
|
||
sdk.checkUpdate(device.versionId, device.customClientData).then(update => { | ||
if (update) { | ||
resolve(update); | ||
} else { | ||
resolve('No update available'); | ||
} | ||
}).catch(err => { | ||
logger.debug('check update failed:', err); | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
checkUpdateAndDownload(apiKey, device, path) { | ||
return new Promise((resolve, reject) => { | ||
logger.debug('check and download update:', device, path); | ||
const sdk = new BarracksSDK({ | ||
baseURL: this.options.baseUrl, | ||
apiKey, | ||
unitId: device.unitId, | ||
downloadFilePath: path | ||
}); | ||
|
||
sdk.checkUpdate(device.versionId, device.customClientData).then(update => { | ||
if (update) { | ||
update.download().then(file => { | ||
resolve(file); | ||
}); | ||
} else { | ||
resolve('No update available'); | ||
} | ||
}).catch(err => { | ||
logger.debug('check and download update failed:', err); | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = BarracksSDKProxy; |
Oops, something went wrong.