ibm-mfp-web-push
Version:
IBM MFP Web Push SDK
64 lines (53 loc) • 1.74 kB
JavaScript
const ACCESS_SCOPE = "push.mobileclient devices.read devices.write subscriptions.write";
const httpGET = function (action, data, headers) {
return httpDefault("GET", action, data, headers);
};
const httpPOST = function (action, data, headers) {
return httpDefault("POST", action, data, headers);
};
const httpPUT = function (action, data, headers) {
return httpDefault("PUT", action, data, headers);
};
const httpDELETE = function (action, headers) {
return httpDefault("DELETE", action, headers);
};
const httpDefault = function (method, action, data, headers = {}) {
const appId = localStorage.getItem("appId");
var url = '/imfpush/v1/apps/' + appId + action;
const WL = window.WL;
return new Promise(function (resolve, reject) {
var resourceRequest = new WL.ResourceRequest(url, method, {
scope: ACCESS_SCOPE
});
var onSuccess = function (response) {
resolve(response);
};
var onFailure = function (response) {
console.log("Failed to call the resource:" + response.errorMsg);
reject(response);
};
if (headers && typeof headers == 'object' && Object.keys(headers).length > 0) {
var keys = Object.keys(headers);
for (var key of keys) {
resourceRequest.addHeader(key, headers[key]);
}
}
if (data) {
resourceRequest.send(data).then(
onSuccess,
onFailure
);
} else {
resourceRequest.send().then(
onSuccess,
onFailure
);
}
});
};
export {
httpGET,
httpPOST,
httpPUT,
httpDELETE
};