Create actions submodule to clean app a bit

This commit is contained in:
Juan Cruz Viotti 2014-11-18 08:41:13 -04:00
parent 2b8313da74
commit d0cc3e54ad
3 changed files with 20 additions and 14 deletions

9
lib/actions/app.coffee Normal file
View File

@ -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}"

6
lib/actions/auth.coffee Normal file
View File

@ -0,0 +1,6 @@
auth = require('../auth/auth')
exports.login = (credentials) ->
parsedCredentials = auth.parseCredentials(credentials)
auth.login parsedCredentials, (error) ->
throw error if error?

View File

@ -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 <username:password>')
.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