Skip to content

Commit a8fcb5e

Browse files
author
James Vidler
authored
Merge pull request #13 from agility/dev
0.2.1
2 parents add09db + ab00c58 commit a8fcb5e

File tree

10 files changed

+171
-72
lines changed

10 files changed

+171
-72
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ import agility from '@agility/content-fetch'
4040
//initialize the api client
4141
const api = agility.getApi({
4242
instanceID: '1234-1234',
43-
accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg==',
44-
languageCode: 'en-us'
43+
accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg=='
4544
});
4645

4746
//make the request: get a content item with the ID '22'
4847
api.getContentItem({
49-
contentID: 22
48+
contentID: 22,
49+
languageCode: 'en-us'
5050
})
5151
.then(function(contentItem) {
5252
//on success

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agility/content-fetch",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "JavaScript library for the Agility Fetch API (node and browser)",
55
"main": "dist/agility-content-fetch.node.js",
66
"scripts": {

src/content-fetch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import createClient from './api-client'
2323
* @name getApi
2424
* @memberof AgilityFetch
2525
* @param {Object} config - API intialization params
26-
* @param {string} config.instanceID - The guid that represents your instance
27-
* @param {string} config.accessToken - The secret token that represents your application
28-
* @param {string} config.languageCode - The language you want to retreive content for
29-
* @param {boolean} [config.isPreview] - If your access token is for preview, then set this to true
26+
* @param {string} config.instanceID - The guid that represents your instance.
27+
* @param {string} config.accessToken - The secret token that represents your application.
28+
* @param {string} config.languageCode - The language you want to retreive content for.
29+
* @param {boolean} [config.isPreview] - If your access token is for preview, then set this to true.
3030
* @return {AgilityFetch.Client}
3131
* @example
3232
*

src/methods/getContentItem.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import utils from '../utils'
55
* @memberof AgilityFetch.Client
66
* @param {Object} requestParams - The paramters for the API request.
77
* @param {number} requestParams.contentID - The contentID of the requested item in this language.
8+
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
89
* @returns {Promise<AgilityFetch.Types.ContentItem>} - Returns a content item object.
910
* @example
1011
*
@@ -13,11 +14,11 @@ import utils from '../utils'
1314
* const api = agility.getApi({
1415
* instanceID: '1234-1234',
1516
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg==',
16-
* languageCode: 'en-us'
1717
* });
1818
*
1919
* api.getContentItem({
20-
* contentID: 22
20+
* contentID: 22,
21+
* languageCode: 'en-us'
2122
* })
2223
* .then(function(contentItem) {
2324
* console.log(contentItem);
@@ -35,7 +36,7 @@ function getContentItem(requestParams) {
3536
const req = {
3637
url: `/item/${requestParams.contentID}`,
3738
method: 'get',
38-
baseURL: utils.buildRequestUrlPath(this.config),
39+
baseURL: utils.buildRequestUrlPath(this.config, requestParams.languageCode),
3940
headers: utils.buildAuthHeader(this.config),
4041
params:{}
4142
};
@@ -44,7 +45,10 @@ function getContentItem(requestParams) {
4445
}
4546

4647
function validateRequestParams(requestParams) {
47-
if(!requestParams.contentID) {
48+
if(!requestParams.languageCode) {
49+
throw new TypeError('You must include a languageCode in your request params.')
50+
}
51+
else if(!requestParams.contentID) {
4852
throw new TypeError('You must include a contentID number in your request params.');
4953
} else {
5054
return;

src/methods/getContentList.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import utils from '../utils'
44
* Retrieves a list of content items by reference name.
55
* @memberof AgilityFetch.Client
66
* @param {Object} requestParams - The parameters for the API request.
7-
* @param {string} requestParams.referenceName - The unique reference name of the content list you wish to retrieve in the current language.
7+
* @param {string} requestParams.referenceName - The unique reference name of the content list you wish to retrieve in the specified language.
8+
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
89
* @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **50**.
910
* @param {number} [requestParams.skip] - The number of items to skip from the list. Default is **0**. Used for implementing pagination.
1011
* @param {number} [requestParams.sort] - The field to sort the results by. Example *fields.title* or *properties.created*.
@@ -17,16 +18,16 @@ import utils from '../utils'
1718
*
1819
* const api = agility.getApi({
1920
* instanceID: '1234-1234',
20-
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg==',
21-
* languageCode: 'en-us'
21+
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg=='
2222
* });
2323
*
2424
* api.getContentList({
2525
* referenceName: 'posts',
26+
* languageCode: 'en-us',
2627
* take: 50,
2728
* skip: 0,
2829
* sort: 'properties.created',
29-
* direction: 'asc'
30+
* direction: 'asc'
3031
* })
3132
* .then(function(contentList) {
3233
* console.log(contentList);
@@ -44,7 +45,7 @@ function getContentList(requestParams) {
4445
const req = {
4546
url: `/list/${requestParams.referenceName}`,
4647
method: 'get',
47-
baseURL: utils.buildRequestUrlPath(this.config),
48+
baseURL: utils.buildRequestUrlPath(this.config, requestParams.languageCode),
4849
headers: utils.buildAuthHeader(this.config),
4950
params:{}
5051
};
@@ -53,7 +54,10 @@ function getContentList(requestParams) {
5354
}
5455

5556
function validateRequestParams(requestParams) {
56-
if(!requestParams.referenceName) {
57+
if(!requestParams.languageCode) {
58+
throw new TypeError('You must include a languageCode in your request params.')
59+
}
60+
else if(!requestParams.referenceName) {
5761
//must have a referenceName
5862
throw new TypeError('You must include a content referenceName in your request params.');
5963
} else if(requestParams.take && isNaN(requestParams.take)) {

src/methods/getPage.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ import utils from '../utils'
55
* @memberof AgilityFetch.Client
66
* @param {Object} requestParams - The parameters for the API request.
77
* @param {number} requestParams.pageID - The unique page ID of the page you wish to retrieve in the current language.
8+
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
89
* @returns {Promise<AgilityFetch.Types.Page>} - Returns a page item object.
910
* @example
1011
*
1112
* import agility from '@agility/content-fetch'
1213
*
1314
* var api = agility.getApi({
1415
* instanceID: '1234-1234',
15-
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg==',
16-
* languageCode: 'en-us'
16+
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg=='
1717
* });
1818
*
1919
* api.getPage({
20-
* pageID: 1
20+
* pageID: 1,
21+
* languageCode: 'en-us'
2122
* })
2223
* .then(function(page) {
2324
* console.log(page);
@@ -35,7 +36,7 @@ function getPage(requestParams) {
3536
const req = {
3637
url: `/page/${requestParams.pageID}`,
3738
method: 'get',
38-
baseURL: utils.buildRequestUrlPath(this.config),
39+
baseURL: utils.buildRequestUrlPath(this.config, requestParams.languageCode),
3940
headers: utils.buildAuthHeader(this.config),
4041
params:{}
4142
};
@@ -44,7 +45,9 @@ function getPage(requestParams) {
4445
}
4546

4647
function validateRequestParams(requestParams) {
47-
if(!requestParams.pageID) {
48+
if(!requestParams.languageCode) {
49+
throw new TypeError('You must include a languageCode in your request params.')
50+
} else if(!requestParams.pageID) {
4851
throw new TypeError('You must include a pageID in your request params.');
4952
} else {
5053
return;

src/methods/getSitemapFlat.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@ import utils from '../utils'
55
* @memberof AgilityFetch.Client
66
* @param {Object} requestParams - The parameters for the API request.
77
* @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*.
8+
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
89
* @returns {Promise<AgilityFetch.Types.SitemapFlat>} - The sitemap response in a flat format.
910
* @example
1011
*
1112
* import agility from '@agility/content-fetch'
1213
*
1314
* var api = agility.getApi({
1415
* instanceID: '1234-1234',
15-
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg==',
16-
* languageCode: 'en-us'
16+
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg=='
1717
* });
1818
*
1919
* api.getSitemapFlat({
20-
* channelName: 'website'
20+
* channelName: 'website',
21+
* languageCode: 'en-us'
2122
* })
2223
* .then(function(sitemap) {
23-
* console.log(sitemap);
24+
* console.log(sitemap);
2425
* })
2526
* .catch(function(error) {
26-
* console.log(error);
27+
* console.log(error);
2728
* });
2829
*/
2930

@@ -34,7 +35,7 @@ function getSitemapFlat(requestParams) {
3435
const req = {
3536
url: `/Sitemap/Flat/${requestParams.channelName}`,
3637
method: 'get',
37-
baseURL: utils.buildRequestUrlPath(this.config),
38+
baseURL: utils.buildRequestUrlPath(this.config, requestParams.languageCode),
3839
headers: utils.buildAuthHeader(this.config),
3940
params:{}
4041
};
@@ -43,7 +44,9 @@ function getSitemapFlat(requestParams) {
4344
}
4445

4546
function validateRequestParams(requestParams) {
46-
if(!requestParams.channelName) {
47+
if(!requestParams.languageCode) {
48+
throw new TypeError('You must include a languageCode in your request params.')
49+
} else if(!requestParams.channelName) {
4750
throw new TypeError('You must include a channelName in your request params.');
4851
} else {
4952
return;

src/methods/getSitemapNested.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@ import utils from '../utils'
55
* @memberof AgilityFetch.Client
66
* @param {Object} requestParams - The parameters for the API request.
77
* @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*.
8+
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
89
* @returns {Promise<AgilityFetch.Types.SitemapNested>} - The array of sitemap items returned.
910
* @example
1011
*
1112
* import agility from '@agility/content-fetch'
1213
*
1314
* var api = agility.getApi({
1415
* instanceID: '1234-1234',
15-
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg==',
16-
* languageCode: 'en-us'
16+
* accessToken: 'fEpTcRnWO3EahHbojDCeY3PwGwAzpw2gveDuPn2l0nuqFbQYVcWrQ+a3/DHcWgCgn7UL2tgbSOS0AqrEOiXkTg=='
1717
* });
1818
*
1919
* api.getSitemapNested({
20-
* channelName: 'website'
20+
* channelName: 'website',
21+
* languageCode: 'en-us'
2122
* })
2223
* .then(function(sitemap) {
23-
* console.log(sitemap);
24+
* console.log(sitemap);
2425
* })
2526
* .catch(function(error) {
26-
* console.log(error);
27+
* console.log(error);
2728
* });
2829
*/
2930

@@ -34,7 +35,7 @@ function getSitemapNested(requestParams) {
3435
const req = {
3536
url: `/Sitemap/Nested/${requestParams.channelName}`,
3637
method: 'get',
37-
baseURL: utils.buildRequestUrlPath(this.config),
38+
baseURL: utils.buildRequestUrlPath(this.config, requestParams.languageCode),
3839
headers: utils.buildAuthHeader(this.config),
3940
params:{}
4041
};
@@ -43,7 +44,9 @@ function getSitemapNested(requestParams) {
4344
}
4445

4546
function validateRequestParams(requestParams) {
46-
if(!requestParams.channelName) {
47+
if(!requestParams.languageCode) {
48+
throw new TypeError('You must include a languageCode in your request params.')
49+
} else if(!requestParams.channelName) {
4750
throw new TypeError('You must include a channelName in your request params.');
4851
}
4952
}

src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
function buildRequestUrlPath(config) {
1+
function buildRequestUrlPath(config, languageCode) {
22
let urlPath = null;
33
if(config.isPreview) {
44
urlPath = config.previewBaseUrl
55
} else {
66
urlPath = config.fetchBaseUrl
77
}
8-
urlPath = `${urlPath}/${config.instanceID}/${config.languageCode}`;
8+
urlPath = `${urlPath}/${config.instanceID}/${languageCode}`;
99
return urlPath;
1010
}
1111

0 commit comments

Comments
 (0)