Document all models

This commit is contained in:
Juan Cruz Viotti 2014-12-08 08:48:19 -04:00
parent ad74cbaec0
commit 68f3d601cb
3 changed files with 134 additions and 4 deletions

View File

@ -1,9 +1,20 @@
_ = require('lodash')
_ = require('lodash-contrib')
canvas = require('./_canvas')
errors = require('../errors/errors')
server = require('../server/server')
settings = require('../settings')
# Get all applications
#
# @param {Function} callback callback(error, applications)
#
# @throw {NotAny} Will throw if no applications were found
#
# @example Get all applications
# resin.models.application.getAll (error, applications) ->
# throw error if error?
# console.log(applications)
#
exports.getAll = (callback) ->
return canvas.get
resource: 'application'
@ -19,6 +30,18 @@ exports.getAll = (callback) ->
.catch (error) ->
return callback(error)
# Get a single application
#
# @param {String, Number} id application id
# @param {Function} callback callback(error, application)
#
# @throw {NotFound} Will throw if application was not found
#
# @example Find application
# resin.models.application.get 51, (error, application) ->
# throw error if error?
# console.log(application)
#
exports.get = (id, callback) ->
return canvas.get
resource: 'application'
@ -33,6 +56,19 @@ exports.get = (id, callback) ->
.catch (error) ->
return callback(error)
# Create an application
#
# @param {String} name application name
# @param {String} deviceType device type (slug form)
# @param {Function} callback callback(error, id)
#
# @throw {NotFound} Will throw if the request doesn't returns an id
#
# @example Create an application
# resin.models.application.create 'My App', 'raspberry-pi', (error, id) ->
# throw error if error?
# console.log(id)
#
exports.create = (name, deviceType, callback) ->
return canvas.post
resource: 'application'
@ -51,6 +87,15 @@ exports.create = (name, deviceType, callback) ->
.catch (error) ->
return callback(error)
# Remove application
#
# @param {String, Number} id application id
# @param {Function} callback callback(error)
#
# @example Remove application
# resin.models.application.remove 51, (error) ->
# throw error if error?
#
exports.remove = (id, callback) ->
return canvas.delete
resource: 'application'
@ -60,6 +105,15 @@ exports.remove = (id, callback) ->
.catch (error) ->
return callback(error)
# Restart application
#
# @param {String, Number} id application id
# @param {Function} callback callback(error)
#
# @example Restart application
# resin.models.application.restart 51, (error) ->
# throw error if error?
#
exports.restart = (id, callback) ->
url = _.template(settings.get('urls.applicationRestart'), { id })
server.post(url, callback)
server.post(url, _.unary(callback))

View File

@ -1,9 +1,20 @@
canvas = require('./_canvas')
_ = require('lodash')
_ = require('lodash-contrib')
errors = require('../errors/errors')
server = require('../server/server')
settings = require('../settings')
# Get all devices
#
# @param {Function} callback callback(error, devices)
#
# @throw {NotAny} Will throw if no devices were found
#
# @example Get all devices
# resin.models.devices.getAll (error, devices) ->
# throw error if error?
# console.log(devices)
#
exports.getAll = (callback) ->
return canvas.get
resource: 'device'
@ -19,6 +30,18 @@ exports.getAll = (callback) ->
.catch (error) ->
return callback(error)
# Get all devices by application
#
# @param {String, Number} applicationId application id
# @param {Function} callback callback(error, devices)
#
# @throw {NotAny} Will throw if no devices were found
#
# @example Get all devices by application
# resin.models.devices.getAllByApplication (error, devices) ->
# throw error if error?
# console.log(devices)
#
exports.getAllByApplication = (applicationId, callback) ->
return canvas.get
resource: 'device'
@ -36,6 +59,18 @@ exports.getAllByApplication = (applicationId, callback) ->
.catch (error) ->
return callback(error)
# Get a single device
#
# @param {String, Number} id device id
# @param {Function} callback callback(error, device)
#
# @throw {NotFound} Will throw if device was not found
#
# @example Find device
# resin.models.device.get 51, (error, device) ->
# throw error if error?
# console.log(device)
#
exports.get = (deviceId, callback) ->
return canvas.get
resource: 'device'
@ -52,6 +87,15 @@ exports.get = (deviceId, callback) ->
.catch (error) ->
return callback(error)
# Remove device
#
# @param {String, Number} id device id
# @param {Function} callback callback(error)
#
# @example Remove device
# resin.models.device.remove 51, (error) ->
# throw error if error?
#
exports.remove = (id, callback) ->
return canvas.delete
resource: 'device'
@ -61,5 +105,14 @@ exports.remove = (id, callback) ->
.catch (error) ->
return callback(error)
# Identify device
#
# @param {String} uuid device uuid
# @param {Function} callback callback(error)
#
# @example Identify device
# resin.models.device.identify '23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a21369ac0f00db828', (error) ->
# throw error if error?
#
exports.identify = (uuid, callback) ->
server.post(settings.get('urls.identify'), { uuid }, callback)
server.post(settings.get('urls.identify'), { uuid }, _.unary(callback))

View File

@ -1,6 +1,20 @@
canvas = require('./_canvas')
errors = require('../errors/errors')
# Get all environment variables by application
#
# @param {String, Number} applicationId application id
# @param {Function} callback callback(error, environmentVariables)
#
# @throw {NotFound} Will throw if no environment variable was found
#
# @todo Rename this to getAllByApplication
#
# @example Get all environment variables by application
# resin.models.environmentVariables.getAll (error, environmentVariables) ->
# throw error if error?
# console.log(environmentVariables)
#
exports.getAll = (applicationId, callback) ->
return canvas.get
resource: 'environment_variable'
@ -18,6 +32,15 @@ exports.getAll = (applicationId, callback) ->
.catch (error) ->
return callback(error)
# Remove environment variable
#
# @param {String, Number} id environment variable id
# @param {Function} callback callback(error)
#
# @example Remove environment variable
# resin.models.environmentVariables.remove 51, (error) ->
# throw error if error?
#
exports.remove = (id, callback) ->
return canvas.delete
resource: 'environment_variable'