From c2ebe0e355038290defda53d8356d5e4000e39ab Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 13 Mar 2017 22:37:41 +0300 Subject: [PATCH] generalize IguanaJumblr.js --- assets/scripts/iguana_api/IguanaJumblr.js | 61 +++++++++++------------ 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/assets/scripts/iguana_api/IguanaJumblr.js b/assets/scripts/iguana_api/IguanaJumblr.js index 97a8ad9..16ba489 100644 --- a/assets/scripts/iguana_api/IguanaJumblr.js +++ b/assets/scripts/iguana_api/IguanaJumblr.js @@ -1,42 +1,37 @@ +function Generic_Iguana_Jumblr(ajax_data, resolve) { + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + + ajax_data.userpass = tmpIguanaRPCAuth; + $.ajax({ + data: JSON.stringify(ajax_data), + url: 'http://127.0.0.1:' + config.iguanaPort, + type: 'POST', + dataType: 'json' + }) + .done(function(data) { + resolve(data); + }); +} + function Iguana_Jumblr_SetPassphrase(data) { - return new Promise((resolve) => { - var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - ajax_data = { - 'userpass': tmpIguanaRPCAuth, - 'agent': 'jumblr', - 'method': 'setpassphrase', - 'passphrase': data.passphrase - }; + var ajax_data = { + 'agent': 'jumblr', + 'method': 'setpassphrase', + 'passphrase': data.passphrase + }; - $.ajax({ - data: JSON.stringify(ajax_data), - url: 'http://127.0.0.1:' + config.iguanaPort, - type: 'POST', - dataType: 'json' - }) - .done(function(data) { - resolve(data); - }); + return new Promise((resolve) => { + Generic_Iguana_Jumblr(ajax_data, resolve); }); } function Iguana_Jumblr_Status() { - return new Promise((resolve) => { - var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - ajax_data = { - 'userpass': tmpIguanaRPCAuth, - 'agent': 'jumblr', - 'method': 'status' - }; + var ajax_data = { + 'agent': 'jumblr', + 'method': 'status' + }; - $.ajax({ - data: JSON.stringify(ajax_data), - url: 'http://127.0.0.1:' + config.iguanaPort, - type: 'POST', - dataType: 'json' - }) - .done(function(data) { - resolve(data); - }); + return new Promise((resolve) => { + Generic_Iguana_Jumblr(ajax_data, resolve); }); } \ No newline at end of file