Skip to content

Commit

Permalink
re-organzied methods in jsdoc and renamed ticks in sync methods to sy…
Browse files Browse the repository at this point in the history
…ncToken
  • Loading branch information
jamesvidler committed Jan 17, 2020
1 parent 2ee35cd commit 76f4b47
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 103 deletions.
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": "0.7.1",
"version": "0.8.0",
"description": "JavaScript library for the Agility Fetch API (node and browser)",
"main": "dist/agility-content-fetch.node.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions src/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import getContentItem from './methods/getContentItem'
import getContentList from './methods/getContentList'
import getPage from './methods/getPage'
import getGallery from './methods/getGallery'
import syncContentItems from './methods/syncContentItems'
import syncPageItems from './methods/syncPageItems'
import getSyncContent from './methods/getSyncContent'
import getSyncPages from './methods/getSyncPages'
import FilterOperators from './types/FilterOperator'
import FilterLogicOperators from './types/FilterLogicOperator'
import SortDirections from './types/SortDirection'
Expand Down Expand Up @@ -93,8 +93,8 @@ export default function createClient(userConfig) {
getContentList: getContentList,
getPage: getPage,
getGallery: getGallery,
syncContentItems: syncContentItems,
syncPageItems: syncPageItems,
getSyncContent: getSyncContent,
getSyncPages: getSyncPages,
types: {
FilterOperators: FilterOperators,
FilterLogicOperators: FilterLogicOperators,
Expand Down
24 changes: 23 additions & 1 deletion src/content-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,33 @@
*/

/**
* Agility Fetch API JS SDK for retrieving content from the Agility CMS
* Agility Fetch API JS SDK client for Agility CMS
* @namespace AgilityFetch.Client
*/


/**
* Agility Fetch API JS SDK for retrieving content from the Agility CMS
* @namespace AgilityFetch.Client.Content
*/

/**
* Agility Fetch API JS SDK for retrieving pages from the Agility CMS
* @namespace AgilityFetch.Client.Pages
*/

/**
* Agility Fetch API JS SDK for retrieving media from the Agility CMS
* @namespace AgilityFetch.Client.Media
*/


/**
* Agility Fetch API JS SDK for synchronizing content from Agility CMS
* @namespace AgilityFetch.Client.Sync
*/


/**
* Types returned by the the Fetch API
* @namespace AgilityFetch.Types
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getContentItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* Gets the details of a content item by their Content ID.
* @memberof AgilityFetch.Client
* @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.
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getContentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* Retrieves a list of content items by reference name.
* @memberof AgilityFetch.Client
* @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.
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* Gets the details of a gallery by their Gallery ID.
* @memberof AgilityFetch.Client
* @memberof AgilityFetch.Client.Media
* @param {Object} requestParams - The parameters for the API request.
* @param {number} requestParams.galleryID - The galleryID of the requested item in this language.
* @returns {Promise<AgilityFetch.Types.Gallery>} - Returns a gallery object.
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* Gets the details of a page by its Page ID.
* @memberof AgilityFetch.Client
* @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.
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getSitemapFlat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* The sitemap, returned in a flat list, where the dictionary key is the page path. This method is ideal for page routing.
* @memberof AgilityFetch.Client
* @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.
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getSitemapNested.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* Gets the sitemap as an array in a nested format, ideal for generating menus.
* @memberof AgilityFetch.Client
* @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.
Expand Down
62 changes: 62 additions & 0 deletions src/methods/getSyncContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* Retrieves a list of content items that need to be synced based on the provided sync content items token, and returns the next sync token.
* @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 {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
*
* import agility from '@agility/content-fetch'
*
* const api = agility.getApi({
* guid: 'ade6cf3c',
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
* });
*
* api.getSyncContent({
* syncToken: '0', //to start a new sync
* languageCode: 'en-us',
* pageSize: 500
* })
* .then(function(contentList) {
* console.log(contentList.items);
*
* //the next sync token to use, continue to call this method (loop) until no sync token is provided in the response. This indicates your are up to date.
* console.log(contentList.syncToken);
* })
* .catch(function(error) {
* console.log(error);
* });
*/
function getSyncContent(requestParams) {

validateRequestParams(requestParams);

const req = {
url: `/sync/items?pageSize=${requestParams.pageSize}&syncToken=${requestParams.syncToken}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
headers: buildAuthHeader(this.config),
params: {}
};

return this.makeRequest(req);
}

function validateRequestParams(requestParams) {
if (!requestParams.languageCode) {
throw new TypeError('You must include a languageCode 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.');
} else {
return;
}
}


export default getSyncContent;
62 changes: 62 additions & 0 deletions src/methods/getSyncPages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* Retrieves a list of pages that need to be synced based on the provided sync pages token, and returns the next sync token.
* @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 {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
*
* import agility from '@agility/content-fetch'
*
* const api = agility.getApi({
* guid: 'ade6cf3c',
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
* });
*
* api.getSyncPages({
* syncToken: '0', //to start a new sync
* languageCode: 'en-us',
* pageSize: 500
* })
* .then(function(pages) {
* console.log(pages.items);
*
* //the next sync token to use, continue to call this method (loop) until no sync token is provided in the response. This indicates your are up to date.
* console.log(pages.syncToken);
* })
* .catch(function(error) {
* console.log(error);
* });
*/
function getSyncPages(requestParams) {

validateRequestParams(requestParams);

const req = {
url: `/sync/pages?pageSize=${requestParams.pageSize}&syncToken=${requestParams.syncToken}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
headers: buildAuthHeader(this.config),
params: {}
};

return this.makeRequest(req);
}

function validateRequestParams(requestParams) {
if (!requestParams.languageCode) {
throw new TypeError('You must include a languageCode 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.');
} else {
return;
}
}


export default getSyncPages;
39 changes: 0 additions & 39 deletions src/methods/syncContentItems.js

This file was deleted.

39 changes: 0 additions & 39 deletions src/methods/syncPageItems.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/types/SyncContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Defines **Sync Content** response.
* @typedef SyncContent
* @memberof AgilityFetch.Types
* @property {number} syncToken - The sync token to be used in the next call as a continuation token for syncing content. If this is empty, you are up to date.
* @property {Array.<AgilityFetch.Types.ContentItem>} items - The paginated array of items returned by the request.
*/

8 changes: 8 additions & 0 deletions src/types/SyncPages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Defines **Sync Pages** response.
* @typedef SyncPages
* @memberof AgilityFetch.Types
* @property {number} syncToken - The sync token to be used in the next call as a continuation token for syncing content. If this is empty, you are up to date.
* @property {Array.<AgilityFetch.Types.Page>} items - The paginated array of items returned by the request.
*/

Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ const ref = {
updatesMadeToPublishedContentItemID: 15
}

describe('syncContentItems:', function () {
describe('getSyncContent:', function () {

this.timeout('120s');

it('should retrieve the oldest content items and ticks', function (done) {
it('should retrieve the oldest content items and next sync token', function (done) {
var api = createApiClient();

let ticks = 0;
let syncToken = 0;

//sync from scratch
api.syncContentItems({
ticks: ticks,
api.getSyncContent({
syncToken: syncToken,
pageSize: 100,
languageCode: 'en-us'
})
.then(function (syncRet) {

assert.isTrue(syncRet.ticks > 0, "should return a ticks value.")
assert.isTrue(syncRet.syncToken > 0, "should return a syncToken value.")
assert.isTrue(syncRet.items.length > 0, "should return items.")
done();
})
Expand Down
Loading

0 comments on commit 76f4b47

Please sign in to comment.