diff --git a/lib/api.websms.js b/lib/api.websms.js index a165434..6c5ab72 100644 --- a/lib/api.websms.js +++ b/lib/api.websms.js @@ -1,3 +1,4 @@ +var RAND = require("lib/rand"); var HTTP = require("lib/http"); var WebSMSObject = function() { @@ -6,6 +7,7 @@ var WebSMSObject = function() { this.country = "any"; this.operator = "any"; this.product = ""; + this.profiles = []; this.setHost = function(host) { this.host = host; @@ -31,9 +33,25 @@ var WebSMSObject = function() { this.product = product; return this; }; + + this.addProfile = function(product, country, operator) { + this.profiles.push({ + "product": product, + "country": country, + "operator": operator + }); + return this; + }; this.buy = function() { try { + if (this.profiles.length > 0) { + var pf = RAND.one(this.profiles); + this.setProduct(pf.product); + this.setOperator(pf.operator); + this.setCountry(pf.country); + } + var response = HTTP.create() .setBearerAuth(this.token) .setUseCache(false)