Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added ability to return error instead of token while initializing lib…
…rary
  • Loading branch information
Tymur Valiiev committed Feb 4, 2019
1 parent 4ad2c57 commit 4f5495c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
8 changes: 1 addition & 7 deletions api/sendpulse.js
Expand Up @@ -133,13 +133,7 @@ function sendRequest(path, method, data, useToken, callback){
function(response) {
var str = '';
response.on('data', function (chunk) {
if (response.statusCode==401) {
getToken(function() {
sendRequest(path, method, data, true, callback);
});
} else {
str += chunk;
}
str += chunk;
});

response.on('end', function () {
Expand Down
16 changes: 10 additions & 6 deletions example.js
Expand Up @@ -11,13 +11,17 @@ var sendpulse = require("sendpulse-api");
* https://login.sendpulse.com/settings/#api
*/

var API_USER_ID="USER_ID"
var API_SECRET="USER_SECRET"
var API_USER_ID="USER_ID";
var API_SECRET="USER_SECRET";

var TOKEN_STORAGE="/tmp/"
var TOKEN_STORAGE="/tmp/";

sendpulse.init(API_USER_ID,API_SECRET,TOKEN_STORAGE,function(token) {
console.log('your token: ' + token)
sendpulse.init(API_USER_ID, API_SECRET, TOKEN_STORAGE, function(token) {
if (token && token.is_error) {
// error handling
}

console.log('your token: ' + token);

/**
* Function to process response data
Expand Down Expand Up @@ -127,4 +131,4 @@ sendpulse.init(API_USER_ID,API_SECRET,TOKEN_STORAGE,function(token) {
sendpulse.smsCancelCampaign(answerGetter, 123456);
sendpulse.smsGetCampaignCost(answerGetter, 'sender_test', 'body_test', null, ['111111111']);
sendpulse.smsDeleteCampaign(answerGetter, 123456);
});
});

0 comments on commit 4f5495c

Please sign in to comment.