Implement get account names function.

This commit is contained in:
Valverde Antonio
2014-07-30 16:05:17 +09:00
parent fe05777e9b
commit 4c5ca95396
8 changed files with 69 additions and 1 deletions

View File

@@ -14,6 +14,28 @@ module.exports = syrup.serial()
.define(function(options, service, identity, touch, router, push, adb) {
var log = logger.createLogger('device:plugins:account')
router.on(wire.AccountGetMessage, function(channel, message){
var reply = wireutil.reply(options.serial)
log.info('Getting account(s) of type "%s"', message.type)
service.getAccounts(message.type)
.timeout(30000)
.then(function(accounts) {
push.send([
channel
, reply.okay('success',accounts)
])
})
.catch(function(err) {
log.error('Account get failed', err.stack)
push.send([
channel
, reply.fail(err.message)
])
})
})
router.on(wire.AccountRemoveMessage, function(channel, message) {
var reply = wireutil.reply(options.serial)

View File

@@ -490,6 +490,21 @@ module.exports = syrup.serial()
})
}
plugin.getAccounts = function(type) {
return runServiceCommand(
apk.wire.MessageType.GET_ACCOUNTS
, new apk.wire.GetAccountsRequest(type)
)
.timeout(15000)
.then(function(data) {
var response = apk.wire.GetAccountsResponse.decode(data)
if (response.success) {
return response.accounts
}
throw new Error('No accounts returned')
})
}
plugin.removeAccount = function(data) {
return runServiceCommand(
apk.wire.MessageType.DO_REMOVE_ACCOUNT