/*! msg91 2015-11-27 */ function validateMobileNos(a){if(null==a||""==a)throw new Error("MSG91 : Mobile No is not provided.");return a instanceof Array&&(a=a.join(",")),a}function validateMessage(a){if(null==a||""==a)throw new Error("MSG91 : message is not provided.");return a}function modifyCallbackIfNull(a){return a||function(){}}function isUnicodeString(a){for(var b=0,c=a.length;c>b;b++)if(a.charCodeAt(b)>255)return!0;return!1}function makeHttpRequest(a,b,c){var d=require("http"),e="",f=d.request(a,function(a){a.setEncoding("utf8"),a.on("data",function(a){e+=a}),a.on("end",function(){c(null,e)})});f.on("error",function(a){c(a)}),null!=b&&f.write(b),f.end()}module.exports=function(a,b,c){if(null==a||""==a)throw new Error("MSG91 Authorization Key not provided.");if(null==b||""==b)throw new Error("MSG91 Sender Id is not provided.");if(null==c||""==c)throw new Error("MSG91 router Id is not provided.");return this.send=function(d,e,f){f=modifyCallbackIfNull(f),d=validateMobileNos(d),e=validateMessage(validateMessage);var g=isUnicodeString(e),h="authkey="+a+"&sender="+b+"&mobiles="+d+"&message="+e+"&route="+c;g&&(h="&unicode=1");var i={hostname:"control.msg91.com",port:80,path:"/api/sendhttp.php",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","Content-Length":h.length}};makeHttpRequest(i,h,function(a,b){f(a,b)})},this.getBalance=function(b,d){1==arguments.length&&(d=b,b=null),d=modifyCallbackIfNull(d);var e=b||c,f={hostname:"control.msg91.com",port:80,path:"/api/balance.php?authkey="+a+"&type="+e,method:"GET"};makeHttpRequest(f,null,function(a,b){d(a,b)})},this};