From 6011ad3d2ed7aac7e0574a865e21618af2fff2ed Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 2 Nov 2015 23:55:15 +0100 Subject: [PATCH] The HTTP accessory now supports a body value. --- accessories/Http.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/accessories/Http.js b/accessories/Http.js index 96d8846..24d01df 100644 --- a/accessories/Http.js +++ b/accessories/Http.js @@ -11,7 +11,9 @@ function HttpAccessory(log, config) { // url info this.on_url = config["on_url"]; + this.on_body = config["on_body"]; this.off_url = config["off_url"]; + this.off_body = config["off_body"]; this.brightness_url = config["brightness_url"]; this.http_method = config["http_method"]; this.username = config["username"]; @@ -23,9 +25,10 @@ function HttpAccessory(log, config) { HttpAccessory.prototype = { - httpRequest: function(url, method, username, password, callback) { + httpRequest: function(url, body, method, username, password, callback) { request({ url: url, + body: body, method: method, auth: { user: username, @@ -40,16 +43,19 @@ HttpAccessory.prototype = { setPowerState: function(powerOn, callback) { var url; + var body; if (powerOn) { url = this.on_url; + body = this.on_body; this.log("Setting power state to on"); } else { url = this.off_url; + body = this.off_body; this.log("Setting power state to off"); } - this.httpRequest(url, this.http_method, this.username, this.password, function(error, response, body) { + this.httpRequest(url, body, this.http_method, this.username, this.password, function(error, response, body) { if (error) { this.log('HTTP power function failed: %s', error.message); callback(error); @@ -69,7 +75,7 @@ HttpAccessory.prototype = { this.log("Setting brightness to %s", level); - this.httpRequest(url, this.http_method, this.username, this.password, function(error, response, body) { + this.httpRequest(url, "", this.http_method, this.username, this.password, function(error, response, body) { if (error) { this.log('HTTP brightness function failed: %s', error); callback(error);