Skip to content

Commit

Permalink
feat: Add support for namespaces as requested in #6
Browse files Browse the repository at this point in the history
  • Loading branch information
batje committed Aug 2, 2018
1 parent eb20164 commit 3f09039
Show file tree
Hide file tree
Showing 9 changed files with 2,191 additions and 2,091 deletions.
47 changes: 35 additions & 12 deletions dist/jcognos.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ var CognosRequest = (function() {
var me = this;
var cookieJar = false;
var firstheaders = {};
this.axios = axios.create({});
this.axios = axios.create({
timeout: 60000,

maxRedirects: 10,

maxContentLength: 50 * 1000 * 1000
});
if (Utils.isNode()) {
axiosCookieJarSupport(this.axios);
var cookieJar = new tough.CookieJar();
Expand Down Expand Up @@ -166,6 +172,7 @@ var CognosRequest = (function() {
typeof err.response === 'undefined' ||
err.response.status !== 441
) {
me.log('Unexpected Error in initialise', err);
throw err.message;
}
me.log('Expected Error in initialise');
Expand Down Expand Up @@ -487,6 +494,7 @@ var Cognos = (function() {
this.debug = debug;
this.username = '';
this.password = '';
this.namespace = '';
this.retrycount = 0;
this.loginrequest = false;
this.resetting = false;
Expand Down Expand Up @@ -520,6 +528,11 @@ var Cognos = (function() {
{
key: 'login',
value: function login(user, password) {
var namespace =
arguments.length > 2 && arguments[2] !== undefined
? arguments[2]
: '';

var me = this;
me.log('login: Starting to login');
if (me.loginrequest !== false) {
Expand All @@ -530,11 +543,18 @@ var Cognos = (function() {
return me.loginrequest;
}

if (namespace == '') {
namespace = me.requester.namespace;
}
if (!namespace) {
throw 'Namespace not known.';
}

var params = {
parameters: [
{
name: 'CAMNamespace',
value: me.requester.namespace
value: namespace
},
{
name: 'h_CAM_action',
Expand All @@ -557,6 +577,7 @@ var Cognos = (function() {
me.loggedin = true;
me.username = user;
me.password = password;
me.namespace = namespace;
me.loginrequest = false;
me.log('Successfully logged in');
return body;
Expand Down Expand Up @@ -645,7 +666,7 @@ var Cognos = (function() {
.then(function(cRequest) {
me.requester = cRequest;
me.log('going to login again');
var result = me.login(me.username, me.password);
var result = me.login(me.username, me.password, me.namespace);
me.log('login promise', result);
return result;
})
Expand Down Expand Up @@ -830,7 +851,7 @@ var Cognos = (function() {
return me
.handleError(err)
.then(function() {
me.log('We have been reset, list add the folder again');
me.log('We have been reset, lets add the folder again');
me.resetting = false;
return me.addFolder(parentid, name);
})
Expand Down Expand Up @@ -956,14 +977,16 @@ function getCognos(url) {
reset = true;
}
if (typeof jCognos == 'undefined') {
var myRequest = getCognosRequest(url, debug, reset).then(function(
cRequest
) {
jCognos = new Cognos(debug);
jCognos.requester = cRequest;
jCognos.url = url;
return jCognos;
});
var myRequest = getCognosRequest(url, debug, reset)
.then(function(cRequest) {
jCognos = new Cognos(debug);
jCognos.requester = cRequest;
jCognos.url = url;
return jCognos;
})
.catch(function(err) {
throw err;
});
return myRequest;
} else {
return Promise.resolve(jCognos);
Expand Down
47 changes: 35 additions & 12 deletions dist/jcognos.js
Original file line number Diff line number Diff line change
Expand Up @@ -16138,7 +16138,13 @@
var me = this;
var cookieJar = false;
var firstheaders = {};
this.axios = axios.create({});
this.axios = axios.create({
timeout: 60000,

maxRedirects: 10,

maxContentLength: 50 * 1000 * 1000
});
if (Utils.isNode()) {
noop$1(this.axios);
var cookieJar = new cookie.CookieJar();
Expand Down Expand Up @@ -16204,6 +16210,7 @@
typeof err.response === 'undefined' ||
err.response.status !== 441
) {
me.log('Unexpected Error in initialise', err);
throw err.message;
}
me.log('Expected Error in initialise');
Expand Down Expand Up @@ -17989,6 +17996,7 @@
this.debug = debug;
this.username = '';
this.password = '';
this.namespace = '';
this.retrycount = 0;
this.loginrequest = false;
this.resetting = false;
Expand Down Expand Up @@ -18022,6 +18030,11 @@
{
key: 'login',
value: function login(user, password) {
var namespace =
arguments.length > 2 && arguments[2] !== undefined
? arguments[2]
: '';

var me = this;
me.log('login: Starting to login');
if (me.loginrequest !== false) {
Expand All @@ -18032,11 +18045,18 @@
return me.loginrequest;
}

if (namespace == '') {
namespace = me.requester.namespace;
}
if (!namespace) {
throw 'Namespace not known.';
}

var params = {
parameters: [
{
name: 'CAMNamespace',
value: me.requester.namespace
value: namespace
},
{
name: 'h_CAM_action',
Expand All @@ -18059,6 +18079,7 @@
me.loggedin = true;
me.username = user;
me.password = password;
me.namespace = namespace;
me.loginrequest = false;
me.log('Successfully logged in');
return body;
Expand Down Expand Up @@ -18147,7 +18168,7 @@
.then(function(cRequest) {
me.requester = cRequest;
me.log('going to login again');
var result = me.login(me.username, me.password);
var result = me.login(me.username, me.password, me.namespace);
me.log('login promise', result);
return result;
})
Expand Down Expand Up @@ -18332,7 +18353,7 @@
return me
.handleError(err)
.then(function() {
me.log('We have been reset, list add the folder again');
me.log('We have been reset, lets add the folder again');
me.resetting = false;
return me.addFolder(parentid, name);
})
Expand Down Expand Up @@ -18458,14 +18479,16 @@
reset = true;
}
if (typeof jCognos == 'undefined') {
var myRequest = getCognosRequest(url, debug, reset).then(function(
cRequest
) {
jCognos = new Cognos(debug);
jCognos.requester = cRequest;
jCognos.url = url;
return jCognos;
});
var myRequest = getCognosRequest(url, debug, reset)
.then(function(cRequest) {
jCognos = new Cognos(debug);
jCognos.requester = cRequest;
jCognos.url = url;
return jCognos;
})
.catch(function(err) {
throw err;
});
return myRequest;
} else {
return Promise.resolve(jCognos);
Expand Down
Loading

0 comments on commit 3f09039

Please sign in to comment.