Skip to content

Commit

Permalink
added locale and deprecated languagecode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Tahir committed Mar 23, 2021
1 parent 7118f28 commit 519e568
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 91 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const api = agility.getApi({
//make the request: get a content item with the ID '22'
api.getContentItem({
contentID: 22,
languageCode: 'en-us'
locale: 'en-us'
})
.then(function(contentItem) {
//on success
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agility/content-fetch",
"version": "1.1.1",
"version": "1.1.2",
"description": "JavaScript library for the Agility Fetch API (node and browser)",
"main": "dist/agility-content-fetch.node.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const defaultConfig = {
isPreview: false,
guid: null,
apiKey: null,
languageCode: null,
locale: null,
headers: {},
requiresGuidInHeaders: false,
debug: false,
Expand Down
11 changes: 6 additions & 5 deletions src/methods/getContentItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
* @memberof AgilityFetch.Client.Content
* @param {Object} requestParams - The paramters for the API request.
* @param {number} requestParams.contentID - The contentID of the requested item in this language.
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
* @param {string} requestParams.languageCode DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
* @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is **1**.
* @param {boolean} [requestParams.expandAllContentLinks] - Whether or not to expand entire linked content references, includings lists and items that are rendered in the CMS as Grid or Link. Default is **false**
* @returns {Promise<AgilityFetch.Types.ContentItem>} - Returns a content item object.
Expand All @@ -20,7 +21,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* api.getContentItem({
* contentID: 22,
* languageCode: 'en-us'
* locale: 'en-us'
* })
* .then(function(contentItem) {
* console.log(contentItem);
Expand All @@ -40,7 +41,7 @@ function getContentItem(requestParams) {
const req = {
url: `/item/${requestParams.contentID}?contentLinkDepth=${requestParams.contentLinkDepth}&expandAllContentLinks=${requestParams.expandAllContentLinks}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
headers: buildAuthHeader(this.config),
params:{}
};
Expand All @@ -49,8 +50,8 @@ function getContentItem(requestParams) {
}

function validateRequestParams(requestParams) {
if(!requestParams.languageCode) {
throw new TypeError('You must include a languageCode in your request params.')
if(!requestParams.languageCode && !requestParams.locale) {
throw new TypeError('You must include a locale in your request params.')
}
else if(!requestParams.contentID) {
throw new TypeError('You must include a contentID number in your request params.');
Expand Down
13 changes: 7 additions & 6 deletions src/methods/getContentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
* @memberof AgilityFetch.Client.Content
* @param {Object} requestParams - The parameters for the API request.
* @param {string} requestParams.referenceName - The unique reference name of the content list you wish to retrieve in the specified language.
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
* @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is **1**.
* @param {boolean} [requestParams.expandAllContentLinks] - Whether or not to expand entire linked content references, includings lists and items that are rendered in the CMS as Grid or Link. Default is **false**
* @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **50**.
Expand All @@ -26,7 +27,7 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* api.getContentList({
* referenceName: 'posts',
* languageCode: 'en-us',
* locale: 'en-us',
* take: 50,
* skip: 0,
* sort: 'properties.modified',
Expand All @@ -41,7 +42,7 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* api.getContentList({
* referenceName: 'posts',
* languageCode: 'en-us',
* locale: 'en-us',
* take: 50,
* skip: 0,
* filters: [
Expand Down Expand Up @@ -69,7 +70,7 @@ function getContentList(requestParams) {
const req = {
url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.contentLinkDepth, requestParams.expandAllContentLinks),
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
headers: buildAuthHeader(this.config),
params:{}
};
Expand All @@ -82,8 +83,8 @@ function sanitizeReferenceName(referenceName) {
}

function validateRequestParams(requestParams) {
if(!requestParams.languageCode) {
throw new TypeError('You must include a languageCode in your request params.')
if(!requestParams.languageCode && !requestParams.locale) {
throw new TypeError('You must include a locale in your request params.')
}
else if(!requestParams.referenceName) {
//must have a referenceName
Expand Down
11 changes: 6 additions & 5 deletions src/methods/getPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
* @memberof AgilityFetch.Client.Pages
* @param {Object} requestParams - The parameters for the API request.
* @param {number} requestParams.pageID - The unique page ID of the page you wish to retrieve in the current language.
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
* @param {boolean} [requestParams.expandAllContentLinks] - Whether or not to expand entire linked content references, includings lists and items that are rendered in the CMS as Grid or Link. Default is **false**
* @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is **2**.
* @returns {Promise<AgilityFetch.Types.Page>} - Returns a page item object.
Expand All @@ -20,7 +21,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* api.getPage({
* pageID: 1,
* languageCode: 'en-us'
* locale: 'en-us'
* })
* .then(function(page) {
* console.log(page);
Expand All @@ -39,7 +40,7 @@ function getPage(requestParams) {
const req = {
url: `/page/${requestParams.pageID}?contentLinkDepth=${requestParams.contentLinkDepth}&expandAllContentLinks=${requestParams.expandAllContentLinks}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
headers: buildAuthHeader(this.config),
params:{}
};
Expand All @@ -48,8 +49,8 @@ function getPage(requestParams) {
}

function validateRequestParams(requestParams) {
if(!requestParams.languageCode) {
throw new TypeError('You must include a languageCode in your request params.')
if(!requestParams.languageCode && !requestParams.locale) {
throw new TypeError('You must include a locale in your request params.')
} else if(!requestParams.pageID) {
throw new TypeError('You must include a pageID in your request params.');
} else if(requestParams.expandAllContentLinks && typeof requestParams.expandAllContentLinks !== 'boolean') {
Expand Down
11 changes: 6 additions & 5 deletions src/methods/getSitemapFlat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
* @memberof AgilityFetch.Client.Pages
* @param {Object} requestParams - The parameters for the API request.
* @param {number} requestParams.channelName - The reference name of the digital channel of the sitemap to return. If you only have one channel, your channel reference name is likely *website*.
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
* @returns {Promise<AgilityFetch.Types.SitemapFlat>} - The sitemap response in a flat format.
* @example
*
Expand All @@ -18,7 +19,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* api.getSitemapFlat({
* channelName: 'website',
* languageCode: 'en-us'
* locale: 'en-us'
* })
* .then(function(sitemap) {
* console.log(sitemap);
Expand All @@ -35,7 +36,7 @@ function getSitemapFlat(requestParams) {
const req = {
url: `/sitemap/flat/${requestParams.channelName}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
headers: buildAuthHeader(this.config),
params:{}
};
Expand All @@ -44,8 +45,8 @@ function getSitemapFlat(requestParams) {
}

function validateRequestParams(requestParams) {
if(!requestParams.languageCode) {
throw new TypeError('You must include a languageCode in your request params.')
if(!requestParams.languageCode && !requestParams.locale) {
throw new TypeError('You must include a locale in your request params.')
} else if(!requestParams.channelName) {
throw new TypeError('You must include a channelName in your request params.');
} else {
Expand Down
11 changes: 6 additions & 5 deletions src/methods/getSitemapNested.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
* @memberof AgilityFetch.Client.Pages
* @param {Object} requestParams - The parameters for the API request.
* @param {number} requestParams.channelName - The reference name of the digital channel of the sitemap to return. If you only have one channel, your channel reference name is likely *website*.
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
* @returns {Promise<AgilityFetch.Types.SitemapNested>} - The array of sitemap items returned.
* @example
*
Expand All @@ -18,7 +19,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* api.getSitemapNested({
* channelName: 'website',
* languageCode: 'en-us'
* locale: 'en-us'
* })
* .then(function(sitemap) {
* console.log(sitemap);
Expand All @@ -35,7 +36,7 @@ function getSitemapNested(requestParams) {
const req = {
url: `/sitemap/nested/${requestParams.channelName}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
headers: buildAuthHeader(this.config),
params:{}
};
Expand All @@ -44,8 +45,8 @@ function getSitemapNested(requestParams) {
}

function validateRequestParams(requestParams) {
if(!requestParams.languageCode) {
throw new TypeError('You must include a languageCode in your request params.')
if(!requestParams.languageCode && !requestParams.locale) {
throw new TypeError('You must include a locale in your request params.')
} else if(!requestParams.channelName) {
throw new TypeError('You must include a channelName in your request params.');
}
Expand Down
11 changes: 6 additions & 5 deletions src/methods/getSyncContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
* @memberof AgilityFetch.Client.Sync
* @param {Object} requestParams - The paramters for the API request.
* @param {number} requestParams.syncToken - The sync token provided in the response to a previous sync API call. To start a new sync, use the value of '0'.
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
* @param {number} [requestParams.pageSize] - The number of items to return back with each call. Default is 500.
* @returns {Promise<AgilityFetch.Types.SyncContent>} - Returns a list of content item objects.
* @example
Expand All @@ -19,7 +20,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* api.getSyncContent({
* syncToken: '0', //to start a new sync
* languageCode: 'en-us',
* locale: 'en-us',
* pageSize: 500
* })
* .then(function(contentList) {
Expand All @@ -39,7 +40,7 @@ function getSyncContent(requestParams) {
const req = {
url: `/sync/items?pageSize=${requestParams.pageSize}&syncToken=${requestParams.syncToken}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
headers: buildAuthHeader(this.config),
params: {}
};
Expand All @@ -48,8 +49,8 @@ function getSyncContent(requestParams) {
}

function validateRequestParams(requestParams) {
if (!requestParams.languageCode) {
throw new TypeError('You must include a languageCode in your request params.')
if (!requestParams.languageCode && !requestParams.locale) {
throw new TypeError('You must include a locale in your request params.')
}
else if (requestParams.syncToken == undefined || requestParams.syncToken == null) {
throw new TypeError('You must include a syncToken value your request params. Use zero (0) to start a new sync.');
Expand Down
11 changes: 6 additions & 5 deletions src/methods/getSyncPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
* @memberof AgilityFetch.Client.Sync
* @param {Object} requestParams - The paramters for the API request.
* @param {number} requestParams.syncToken - The sync token provided in the response to a previous sync API call. To start a new sync, use the value of '0'.
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
* @param {number} [requestParams.pageSize] - The number of items to return back with each call. Default is 1000.
* @returns {Promise<AgilityFetch.Types.Page>} - Returns a list of content item objects.
* @example
Expand All @@ -19,7 +20,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* api.getSyncPages({
* syncToken: '0', //to start a new sync
* languageCode: 'en-us',
* locale: 'en-us',
* pageSize: 500
* })
* .then(function(pages) {
Expand All @@ -39,7 +40,7 @@ function getSyncPages(requestParams) {
const req = {
url: `/sync/pages?pageSize=${requestParams.pageSize}&syncToken=${requestParams.syncToken}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
headers: buildAuthHeader(this.config),
params: {}
};
Expand All @@ -48,8 +49,8 @@ function getSyncPages(requestParams) {
}

function validateRequestParams(requestParams) {
if (!requestParams.languageCode) {
throw new TypeError('You must include a languageCode in your request params.')
if (!requestParams.languageCode && !requestParams.locale) {
throw new TypeError('You must include a locale in your request params.')
}
else if (requestParams.syncToken == undefined || requestParams.syncToken == null) {
throw new TypeError('You must include a syncToken value your request params. Use zero (0) to start a new sync.');
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function logDebug(consoleMessage) {
console.log('\x1b[33m%s\x1b[0m', consoleMessage);
}

function buildRequestUrlPath(config, languageCode) {
function buildRequestUrlPath(config, locale) {
let apiFetchOrPreview = null;

if(config.isPreview === true || config.isPreview === 'true') {
Expand All @@ -15,7 +15,7 @@ function buildRequestUrlPath(config, languageCode) {
apiFetchOrPreview = 'fetch';
}

let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${languageCode}`;
let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${locale}`;
return urlPath;
}

Expand Down
Loading

0 comments on commit 519e568

Please sign in to comment.