serwersms
Version:
serwersms.pl API library
65 lines (53 loc) • 1.75 kB
JavaScript
/*!
*
* Copyright 2015 DoctorLex under the terms of the MIT
* license found at http://github.com/kriskowal/q/raw/master/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var _ = require("lodash"),
xml2js = require("xml2js").parseString,
rest = require("restler");
var serwersms = function serwersms () {
var smsServer = "https://api1.serwersms.pl/zdalnie/index.php",
smsconfig = {
login: "demo",
haslo: "demo",
akcja: "wyslij_sms",
numer: "",
wiadomosc: "demo"
};
this.setup = function (args) {
_.merge(smsconfig, args);
};
this.sendSMSCallback = function (data, result, callback) {
xml2js(data, function (err, xmlResult) {
callback(xmlResult.SerwerSMS);
});
};
this.queue = function (args, callback) {
var data = {}, that = this;
_.merge(data, smsconfig, args);
rest.post(smsServer, {
data: data
}).on('complete', function (data, result) {
that.sendSMSCallback(data, result, callback);
});
};
if(serwersms.caller !== serwersms.getInstance){
throw new Error("This object cannot be instanciated");
}
};
serwersms.instance = null;
serwersms.getInstance = function () {
if(this.instance === null){
this.instance = new serwersms();
}
return this.instance;
};
module.exports = serwersms.getInstance();