hybrisspm
Version:
Hybris Marketting API connector Library
169 lines (168 loc) • 5.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var HybrisData_1 = require("./HybrisData");
var httpClient = require('request');
var o = require('odata');
/**
* @author Delly Fofie <delly.fofie@sap.com>
*
*/
var HybrisMarketing = (function () {
function HybrisMarketing(username, password, baseUrl) {
if (baseUrl === void 0) { baseUrl = "https://ccf-350.wdf.sap.corp"; }
this.auth = {
user: null,
pass: null,
sendImmediately: true
};
this.auth.user = username;
this.auth.pass = password;
this.baseUrl = baseUrl;
}
HybrisMarketing.prototype.setCredentials = function (username, password, baseUrl) {
if (baseUrl === void 0) { baseUrl = "https://ccf-350.wdf.sap.corp"; }
this.auth.user = username;
this.auth.pass = password;
this.baseUrl = baseUrl;
};
HybrisMarketing.prototype.campaigns = function () {
return new HybrisData_1.HybrisData(this.auth.user, this.auth.pass, this.baseUrl, "/sap/opu/odata/SAP/API_MKT_CAMPAIGN_SRV/Campaigns");
};
/**
* Get the Top Target groups, A promise will be returned
* @param total
* @return Array<any>
*/
HybrisMarketing.prototype.getTopTargetGroups = function (total) {
};
/**
* Get a particular Target Group
* @param id
* @return targetGroup
*/
HybrisMarketing.prototype.getTargetGroupById = function (id) {
};
/**
*
* @param targetGroup
* @return status
*/
HybrisMarketing.prototype.editOneTargetGroup = function (targetGroup) {
};
/**
* return the Top Campaigns
* @param total
*/
HybrisMarketing.prototype.getTopCampaigns = function (total) {
var _this = this;
var url = "/sap/opu/odata/SAP/API_MKT_CAMPAIGN_SRV/Campaigns?$top=" + total + "&$orderby=CampaignID desc&$format=json&$inlinecount=allpages";
return new Promise(function (resolve, reject) {
httpClient({
method: 'GET',
url: _this.baseUrl + url,
auth: _this.auth,
json: true,
strictSSL: false
}, function (err, resp, body) {
if (err) {
reject(err);
}
else {
resolve(body);
}
});
});
};
/**
* Get on campaign By ID
* @param id
*/
HybrisMarketing.prototype.getCampaignByUUID = function (uuid) {
var _this = this;
var campaign;
var url = "/sap/opu/odata/SAP/API_MKT_CAMPAIGN_SRV/Campaigns(guid'" + uuid + "')?$format=json";
return new Promise(function (resolve, reject) {
httpClient({
method: 'GET',
url: _this.baseUrl + url,
auth: _this.auth,
json: true,
strictSSL: false
}, function (err, resp, body) {
if (err) {
reject(err);
}
else {
resolve(body);
}
});
});
};
/**
* Edit one Campaign
* @param campaign
*/
HybrisMarketing.prototype.editOneCampaign = function (campaign) {
};
/**
* Create a new campaign
* @param campaign
* @param csrfToken
*/
HybrisMarketing.prototype.createCampaign = function (campaign, csrfToken) {
var _this = this;
var url = "/sap/opu/odata/SAP/API_MKT_CAMPAIGN_SRV/Campaigns?format=json";
return new Promise(function (resolve, reject) {
httpClient({
method: 'POST',
url: _this.baseUrl + url,
auth: _this.auth,
json: true,
strictSSL: false,
headers: {
"x-csrf-token": csrfToken,
"Content-Type": "application/json",
"Accept": "application/json",
},
body: campaign
}, function (err, resp, body) {
if (err) {
reject(err);
}
else {
resolve(body);
}
});
});
};
/**
* Get Token
* @returns {string}
*/
HybrisMarketing.prototype.getCampaignCreatingCSRFToken = function () {
var _this = this;
var token;
var url = "/sap/opu/odata/SAP/API_MKT_CAMPAIGN_SRV/Campaigns";
return new Promise(function (resolve, reject) {
httpClient({
method: 'HEAD',
url: _this.baseUrl + url,
auth: _this.auth,
json: true,
strictSSL: false,
headers: {
"x-csrf-token": "fetch"
}
}, function (err, resp, body) {
if (err) {
reject(err);
}
else {
resolve(resp);
}
});
});
};
return HybrisMarketing;
}());
exports.HybrisMarketing = HybrisMarketing;