n8n-nodes-base
Version:
Base nodes of n8n
51 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ghostApiRequest = ghostApiRequest;
exports.ghostApiRequestAllItems = ghostApiRequestAllItems;
exports.validateJSON = validateJSON;
async function ghostApiRequest(method, endpoint, body = {}, query = {}, uri) {
const source = this.getNodeParameter('source', 0);
let version;
let credentialType;
if (source === 'contentApi') {
//https://ghost.org/faq/api-versioning/
version = 'v3';
credentialType = 'ghostContentApi';
}
else {
version = 'v2';
credentialType = 'ghostAdminApi';
}
const credentials = await this.getCredentials(credentialType);
const options = {
method,
qs: query,
uri: uri || `${credentials.url}/ghost/api/${version}${endpoint}`,
body,
json: true,
};
return await this.helpers.requestWithAuthentication.call(this, credentialType, options);
}
async function ghostApiRequestAllItems(propertyName, method, endpoint, body = {}, query = {}) {
const returnData = [];
let responseData;
query.limit = 50;
query.page = 1;
do {
responseData = await ghostApiRequest.call(this, method, endpoint, body, query);
query.page = responseData.meta.pagination.next;
returnData.push.apply(returnData, responseData[propertyName]);
} while (query.page !== null);
return returnData;
}
function validateJSON(json) {
let result;
try {
result = JSON.parse(json);
}
catch (exception) {
result = undefined;
}
return result;
}
//# sourceMappingURL=GenericFunctions.js.map