-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-organzied methods in jsdoc and renamed ticks in sync methods to sy…
…ncToken
- Loading branch information
1 parent
2ee35cd
commit 76f4b47
Showing
18 changed files
with
187 additions
and
103 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.