From d0cc3e54adbc087dcde211c81028fcb28f111e25 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 18 Nov 2014 08:41:13 -0400 Subject: [PATCH] Create actions submodule to clean app a bit --- lib/actions/app.coffee | 9 +++++++++ lib/actions/auth.coffee | 6 ++++++ lib/app.coffee | 19 +++++-------------- 3 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 lib/actions/app.coffee create mode 100644 lib/actions/auth.coffee diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee new file mode 100644 index 00000000..1b17208f --- /dev/null +++ b/lib/actions/app.coffee @@ -0,0 +1,9 @@ +server = require('../server/server') + +exports.list = -> + + # TODO: The details of requesting the API should be handled + # by the models. Make use of them once they are implemented + server.get '/ewa/application?$orderby=app_name%20asc&$expand=device', (error, response) -> + for app in response.body.d + console.log "#{app.id} - #{app.app_name}" diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee new file mode 100644 index 00000000..d61ae0fa --- /dev/null +++ b/lib/actions/auth.coffee @@ -0,0 +1,6 @@ +auth = require('../auth/auth') + +exports.login = (credentials) -> + parsedCredentials = auth.parseCredentials(credentials) + auth.login parsedCredentials, (error) -> + throw error if error? diff --git a/lib/app.coffee b/lib/app.coffee index 97ef0d7d..42d2065f 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -1,31 +1,22 @@ program = require('commander') packageJSON = require('../package.json') - -auth = require('./auth/auth') data = require('./data/data') -server = require('./server/server') config = require('./config') +auth = require('./actions/auth') +app = require('./actions/app') + program.version(packageJSON.version) program .command('login ') .description('Login with your resin.io account') - .action (credentials) -> - parsedCredentials = auth.parseCredentials(credentials) - auth.login parsedCredentials, (error) -> - throw error if error? + .action(auth.login) program .command('apps') .description('Show a list of your apps') - .action -> - - # TODO: The details of requesting the API should be handled - # by the models. Make use of them once they are implemented - server.get '/ewa/application?$orderby=app_name%20asc&$expand=device', (error, response) -> - for app in response.body.d - console.log "#{app.id} - #{app.app_name}" + .action(app.list) # TODO: Check if not running on UNIX environment # and add a custom path accordingly