mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 13:41:05 +00:00
Create api.websms.js
This commit is contained in:
parent
3997be2baf
commit
84ed7d854e
81
lib/api.websms.js
Normal file
81
lib/api.websms.js
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
var HTTP = require("lib/http");
|
||||||
|
|
||||||
|
var WebSMSObject = function() {
|
||||||
|
this.host = "";
|
||||||
|
this.token = "";
|
||||||
|
this.country = "any";
|
||||||
|
this.operator = "any";
|
||||||
|
this.product = "";
|
||||||
|
|
||||||
|
this.setHost = function(host) {
|
||||||
|
this.host = host;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setToken = function(token) {
|
||||||
|
this.token = token;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setCountry = function(country) {
|
||||||
|
this.country = country;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setOperator = function(operator) {
|
||||||
|
this.operator = operator;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setProduct = function(product) {
|
||||||
|
this.product = product;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.buy = function() {
|
||||||
|
try {
|
||||||
|
var response = HTTP.create()
|
||||||
|
.setBearerAuth(this.token)
|
||||||
|
.setUseCache(false)
|
||||||
|
.setHeader("Accept", "application/json")
|
||||||
|
.setParameter("country", this.country)
|
||||||
|
.setParameter("operator", this.operator)
|
||||||
|
.setParameter("product", this.product)
|
||||||
|
.open("GET", "https://" + this.host + "/v1/user/buy/activation/:country/:operator/:product")
|
||||||
|
.send(function(res) {
|
||||||
|
console.log("Got the number: " + res.phone);
|
||||||
|
}).responseBody
|
||||||
|
;
|
||||||
|
return {
|
||||||
|
"id": response.id,
|
||||||
|
"phone": response.phone
|
||||||
|
};
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get = function(id) {
|
||||||
|
try {
|
||||||
|
var response = HTTP.create()
|
||||||
|
.setBearerAuth(this.token)
|
||||||
|
.setUseCache(false)
|
||||||
|
.setHeader("Accept", "application/json")
|
||||||
|
.setParameter("id", id)
|
||||||
|
.open("GET", "https://" + this.host + "/v1/user/check/:id")
|
||||||
|
.send(function(res) {
|
||||||
|
var messages = res.sms;
|
||||||
|
messages.forEach(function(x) {
|
||||||
|
console.log("Got the code: " + x.code);
|
||||||
|
});
|
||||||
|
}).responseBody
|
||||||
|
;
|
||||||
|
return response.sms.reduce(function(cur, x) {
|
||||||
|
cur = x;
|
||||||
|
return cur;
|
||||||
|
}, null);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user