Skip to content

Commit

Permalink
remove comments and return the URL from login
Browse files Browse the repository at this point in the history
  • Loading branch information
Blair Anderson authored and Blair Anderson committed Aug 18, 2014
1 parent 7fc48eb commit 8822b5b
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions lib/exacttarget/exacttarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ var WSDLS = {
test: "https://webservice.test.exacttarget.com/etframework.wsdl", //(S7 instance)
};

var URLS = [];
Object.keys(WSDLS).forEach(function (WSDL) {
URLS.push(WSDLS[WSDL]);
});


function ExactTarget(opts) {
this.version = "1.0.0";
this.DEBUG = opts.DEBUG || false;
// TODO: Possibly iterate over WSDL urls to find the right one.
// Likely that not everyone will be on this endpoint.
// TODO iterate through all endpoints to confirm correct one.
this.WSDL = "https://webservice.s7.exacttarget.com/etframework.wsdl";
this.WSDL = opts.WSDL || WSDLS.s7;

if (opts.token || opts.fueloauth) {

this.token = opts.token || opts.fueloauth;

} else {

if (!opts.username) {
Expand All @@ -33,14 +37,15 @@ function ExactTarget(opts) {
if (!opts.password) {
throw new Error("Missing Password");
}

this.username = opts.username;
this.password = opts.password;
}

}

module.exports = ExactTarget;


ExactTarget.prototype.last = function (callback) {
return callback(null, this.client.lastRequest);
};
Expand All @@ -64,52 +69,40 @@ ExactTarget.prototype.last = function (callback) {
//}


throw new Error("Start HERE");

ExactTarget.prototype.init = function (opts, callback) {
ExactTarget.prototype.login = function (opts, callback) {
var self = this;

var urls = [];
Object.keys(WSDLS).forEach(function (WSDL) {
urls.push(WSDLS[WSDL]);
});

// TODO ITERATE OVER URLS TO FIND THE RIGHT ONE!
if (self.isInit && self.client) {
return callback(null, {client: self.client});
}

soap.createClient(this.WSDL, function (err, client) {
if (err) {
return callback(err, null);
}

// Add Authentication - oauth if available, then username/pw
if (self.token) {

client.addSoapHeader({
fueloauth: self.token,
xmlns: "http://exacttarget.com"
});

client.addSoapHeader({fueloauth: self.token,xmlns: "http://exacttarget.com"});
} else {
client.setSecurity(new soap.WSSecurity(self.username, self.password));
}


// Make a Call to confirm the user is logged in.
client.GetSystemStatus({}, function (err, resp) {
client.GetSystemStatus({}, function (err, res) {
if (err) {
return callback(err, null);
}

if (!resp.status === "OK") {
return callback("Authentication Failed",null)
if (!res.status === "OK") {
return callback(res, null)
}

self.isInit = true;
self.client = client;
return callback(null, resp);
return callback(null , {res: res, WSDL: self.WSDL});
});
});
};


ExactTarget.prototype.retrieve = function (options, callback) {
var self = this;

Expand Down Expand Up @@ -243,7 +236,6 @@ ExactTarget.prototype.BounceEvent = function (opts, callback) {
}, callback);
};


// Retrieve Click Events http://help.exacttarget.com/en/technical_library/web_service_guide/objects/clickevent/
ExactTarget.prototype.ClickEvent = function (opts, callback) {
return this.retrieve({
Expand Down Expand Up @@ -290,7 +282,6 @@ ExactTarget.prototype.ForwardedEmailEvent = function (opts, callback) {
}, callback);
};


// http://help.exacttarget.com/en/technical_library/web_service_guide/objects/forwardedemailoptinevent/
ExactTarget.prototype.ForwardedEmailOptInEvent = function (opts, callback) {
return this.retrieve({
Expand Down

0 comments on commit 8822b5b

Please sign in to comment.