Skip to content

Commit

Permalink
Allow payloads to be sent to device runCommands. Set up Pushover to a…
Browse files Browse the repository at this point in the history
…ccept an image payload to be passed along.
  • Loading branch information
imbrianj committed Feb 18, 2018
1 parent 2184437 commit b86048f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cache/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1518675480694
1518939337696
24 changes: 16 additions & 8 deletions devices/pushover/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ module.exports = (function () {
* @fileoverview Basic control of Pushover notification API.
*/
return {
version : 20150921,
version : 20180217,

inputs : ['text'],

/**
* Prepare a request for command execution.
*/
postPrepare : function (config) {
var type = config.payload ? 'multipart/form-data' : 'application/x-www-form-urlencoded';

return {
host : config.host,
port : config.port,
Expand All @@ -46,7 +48,7 @@ module.exports = (function () {
'Accept' : 'application/json',
'Accept-Charset' : 'utf-8',
'User-Agent' : 'node-switchBoard',
'Content-Type' : 'application/x-www-form-urlencoded',
'Content-Type' : type,
'Content-Length' : config.postRequest.length
}
};
Expand All @@ -56,13 +58,18 @@ module.exports = (function () {
* Prepare the POST data to be sent.
*/
postData : function (pushover) {
var querystring = require('querystring');
var querystring = require('querystring'),
data = {
token : pushover.token,
user : pushover.userKey,
message : pushover.text
};

if (pushover.payload) {
data.attachment = pushover.payload;
}

return querystring.stringify({
token : pushover.token,
user : pushover.userKey,
message : pushover.text
});
return querystring.stringify(data);
},

/**
Expand All @@ -87,6 +94,7 @@ module.exports = (function () {
pushover.port = config.port || 443;
pushover.method = config.method || 'POST';
pushover.text = config.text || '';
pushover.payload = config.payload || null;
pushover.callback = config.callback || function () {};
pushover.postRequest = this.postData(pushover);

Expand Down
4 changes: 2 additions & 2 deletions js/combo.min.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions lib/runCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = (function () {
var Controllers = {};

return {
version : 20180107,
version : 20180216,

/**
* As we want to keep controllers private, but we also want to make them
Expand Down Expand Up @@ -318,11 +318,12 @@ module.exports = (function () {
},

/**
* Takes a given command and sends it to the appropriate controller, along
* with a callback that will generically set the device state if the
* command is successfully executed.
* Accepts a deviceId, command, name of the command issuer, http request,
* http response, optional callback, endResponse (noting a REST-like command
* that should return a JSON output) and an optional unvalidated payload for
* the command to be executed with (such as an image).
*/
runCommand : function (deviceId, command, source, request, response, callback, endResponse) {
runCommand : function (deviceId, command, source, request, response, callback, endResponse, payload) {
var apps = require(__dirname + '/../lib/apps'),
message = 'invalid',
commandType = this.getCommandType(command),
Expand Down Expand Up @@ -425,6 +426,7 @@ module.exports = (function () {
config.config = controllers.config;
config.device = controller.config;
config.source = source;
config.payload = payload;
config.issuer = request ? request.connection.remoteAddress : 'localhost';
config[commandType] = this.stripTypePrefix(command, commandType);

Expand Down

0 comments on commit b86048f

Please sign in to comment.