1 /* Holds User Credentials for Requests */ 2 function Credentials( username, password, siteIds, type ) { 3 this.username = username; 4 this.password = password; 5 this.siteIds = []; 6 7 if ( siteIds ) { 8 this.siteIds = this.siteIds.concat( siteIds ); 9 } 10 11 if ( type === 'source' ) { 12 this.type = 'source'; 13 } 14 else { 15 this.type = 'user'; 16 } 17 } 18 19 Credentials.prototype.addSiteIds = function( ids ) { 20 this.siteIds = this.siteIds.concat( ids ); 21 22 var uniqueIds = []; 23 this.siteIds.forEach( function( id ) { 24 if ( uniqueIds.indexOf( id ) === -1 ) { 25 uniqueIds.push( id ); 26 } 27 } ); 28 29 this.siteIds = uniqueIds; 30 }; 31 32 Credentials.prototype.toSOAP = function() { 33 var soap = { 34 Password: this.password 35 }; 36 37 if ( this.type === 'source' ) { 38 soap.SourceName = this.username; 39 } 40 else { 41 soap.Username = this.username; 42 } 43 44 soap.SiteIDs = { 45 int: this.siteIds 46 }; 47 48 return soap; 49 }; 50 51 Credentials.prototype.toString = function() { 52 return '[object Credentials] {' + 53 'type: ' + this.type + ', ' + 54 'username: ' + this.username + ', ' + 55 'password: ' + this.password + ', ' + 56 'siteIds: ' + this.siteIds + '}'; 57 }; 58 59 module.exports = Credentials;