Add gravity flow demo

This commit is contained in:
Almira Krdzic
2018-06-28 10:02:07 +02:00
parent 1b5076bf2f
commit 12a5066018
1106 changed files with 317603 additions and 4720 deletions

View File

@@ -0,0 +1,47 @@
//eslint disable
import CryptoJS from 'crypto-js';
import fetch from "cross-fetch";
const apiKey = '0102c9cf3b';
const privateKey = '1524cdc26dceaee';
function convertToFutureUnixTime(expirationInSeconds) {
const currentDate = new Date();
const unixTimeInSeconds = parseInt(currentDate.getTime() / 1000, 10);
return unixTimeInSeconds + expirationInSeconds;
}
export function getFullPath(method, route) {
const futureUnixTime = convertToFutureUnixTime(60);
const stringToSign = `${apiKey}:${method}:${route}:${futureUnixTime}`;
const hash = CryptoJS.HmacSHA1(stringToSign, privateKey);
const base64 = hash.toString(CryptoJS.enc.Base64);
const signature = encodeURIComponent(base64);
const fullPath = `http://localhost/gravityformsapi/${route}?api_key=${apiKey}&signature=${signature}&expires=${futureUnixTime}`;
console.log(fullPath);
return fullPath;
}
export function execute(method, path, callback) {
return fetch(getFullPath(method, path), {
method: method,
}).then(response => {
switch (response.status) {
case 401:
console.log(response.code);
break;
case 200:
response.json().then(r => {
//callback()
callback(r.response);
});
default:
console.log(response.code)
}
})
}