Skip to content

Commit aa3be9d

Browse files
committed
Added option to skip response formatting in Content/Admin API
closes TryGhost#73 - Added formatResponse option to the parameter that would be passed in the GhostAdminApi/GhostContentAPi -the formatResponse is default to true when not specified by consumer
1 parent 4f3610b commit aa3be9d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/admin-api/lib/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function GhostAdminAPI(options) {
2121
// makeRequest (method)
2222
// using es5 destructured parameters
2323
// params and headers are optional parameters with an empty object as default value
24-
makeRequest({url, method, data, params = {}, headers = {}}) {
24+
makeRequest({ url, method, data, params = {}, headers = {} }) {
2525
// axios: Promise based HTTP client for the browser and node.js
2626
// Requests can be made by passing the relevant config to axios i.e axios(config)
2727
return axios({
@@ -47,7 +47,7 @@ module.exports = function GhostAdminAPI(options) {
4747
const config = Object.assign({}, defaultConfig, options);
4848

4949
// new GhostAdminAPI({host: '...'}) is deprecated
50-
50+
5151
if (config.host) {
5252
// eslint-disable-next-line
5353
console.warn(`${name}: The 'host' parameter is deprecated, please use 'url' instead`);
@@ -295,7 +295,7 @@ module.exports = function GhostAdminAPI(options) {
295295
return Promise.reject(new Error('Missing theme name'));
296296
}
297297

298-
return makeResourceRequest('themes', {}, {}, 'PUT', {id: `${name}/activate`});
298+
return makeResourceRequest('themes', {}, {}, 'PUT', { id: `${name}/activate` });
299299
}
300300
};
301301

@@ -322,7 +322,7 @@ module.exports = function GhostAdminAPI(options) {
322322
if (!Array.isArray(data[resourceType])) {
323323
return data[resourceType];
324324
}
325-
325+
326326
if (data[resourceType].length === 1 && !data.meta) {
327327
return data[resourceType][0];
328328
}
@@ -346,7 +346,7 @@ module.exports = function GhostAdminAPI(options) {
346346
return data;
347347
}
348348
if (config.formatResponse === true) {
349-
// return data[resourceType] if it is not an array
349+
// return data[resourceType] if it is not an array
350350
if (!Array.isArray(data[resourceType])) {
351351
return data[resourceType];
352352
}
@@ -355,17 +355,17 @@ module.exports = function GhostAdminAPI(options) {
355355
return data[resourceType][0];
356356
}
357357
//copy the values of all of the enumerable own properties from data.meta as meta data[resourceType]. Returns data[resourceType]
358-
return Object.assign(data[resourceType], {meta: data.meta});
358+
return Object.assign(data[resourceType], { meta: data.meta });
359359
} else {
360-
return Object.assign(data, {meta: data.meta});
360+
return Object.assign(data, { meta: data.meta });
361361
}
362362
});
363363
}
364364

365365
// function endpointFor: returns an endpoint for api request
366-
function endpointFor(resource, {id, slug, email} = {}) {
366+
function endpointFor(resource, { id, slug, email } = {}) {
367367
// destructure values from config
368-
const {ghostPath, version} = config;
368+
const { ghostPath, version } = config;
369369
// default endpoint
370370
let endpoint = `/${ghostPath}/api/${version}/admin/${resource}/`;
371371

@@ -383,8 +383,8 @@ module.exports = function GhostAdminAPI(options) {
383383
return endpoint;
384384
}
385385

386-
function makeApiRequest({endpoint, method, body, queryParams = {}, headers = {}}) {
387-
const {url: apiUrl, key, version, makeRequest} = config;
386+
function makeApiRequest({ endpoint, method, body, queryParams = {}, headers = {} }) {
387+
const { url: apiUrl, key, version, makeRequest } = config;
388388
const url = `${apiUrl}${endpoint}`;
389389

390390
headers = Object.assign({}, headers, {

0 commit comments

Comments
 (0)