Skip to content

Commit

Permalink
Added option to skip response formatting in Content/Admin API
Browse files Browse the repository at this point in the history
   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
  • Loading branch information
phawazzzy committed May 8, 2020
1 parent 4f3610b commit aa3be9d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/admin-api/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function GhostAdminAPI(options) {
// makeRequest (method)
// using es5 destructured parameters
// params and headers are optional parameters with an empty object as default value
makeRequest({url, method, data, params = {}, headers = {}}) {
makeRequest({ url, method, data, params = {}, headers = {} }) {
// axios: Promise based HTTP client for the browser and node.js
// Requests can be made by passing the relevant config to axios i.e axios(config)
return axios({
Expand All @@ -47,7 +47,7 @@ module.exports = function GhostAdminAPI(options) {
const config = Object.assign({}, defaultConfig, options);

// new GhostAdminAPI({host: '...'}) is deprecated

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

return makeResourceRequest('themes', {}, {}, 'PUT', {id: `${name}/activate`});
return makeResourceRequest('themes', {}, {}, 'PUT', { id: `${name}/activate` });
}
};

Expand All @@ -322,7 +322,7 @@ module.exports = function GhostAdminAPI(options) {
if (!Array.isArray(data[resourceType])) {
return data[resourceType];
}

if (data[resourceType].length === 1 && !data.meta) {
return data[resourceType][0];
}
Expand All @@ -346,7 +346,7 @@ module.exports = function GhostAdminAPI(options) {
return data;
}
if (config.formatResponse === true) {
// return data[resourceType] if it is not an array
// return data[resourceType] if it is not an array
if (!Array.isArray(data[resourceType])) {
return data[resourceType];
}
Expand All @@ -355,17 +355,17 @@ module.exports = function GhostAdminAPI(options) {
return data[resourceType][0];
}
//copy the values of all of the enumerable own properties from data.meta as meta data[resourceType]. Returns data[resourceType]
return Object.assign(data[resourceType], {meta: data.meta});
return Object.assign(data[resourceType], { meta: data.meta });
} else {
return Object.assign(data, {meta: data.meta});
return Object.assign(data, { meta: data.meta });
}
});
}

// function endpointFor: returns an endpoint for api request
function endpointFor(resource, {id, slug, email} = {}) {
function endpointFor(resource, { id, slug, email } = {}) {
// destructure values from config
const {ghostPath, version} = config;
const { ghostPath, version } = config;
// default endpoint
let endpoint = `/${ghostPath}/api/${version}/admin/${resource}/`;

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

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

headers = Object.assign({}, headers, {
Expand Down

0 comments on commit aa3be9d

Please sign in to comment.