Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import agility from '@agility/content-fetch'
//initialize the api client
const api = agility.getApi({
guid: '191309ca-e675-4be2-bb29-351879528707',
accessToken: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411'
apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411'
});

//make the request: get a content item with the ID '22'
Expand Down
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.4.7",
"version": "0.5.0",
"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 @@ -13,7 +13,7 @@ const defaultConfig = {
baseUrl: null,
isPreview: false,
guid: null,
accessToken: null,
apiKey: null,
languageCode: null,
headers: {},
requiresGuidInHeaders: false,
Expand Down
6 changes: 3 additions & 3 deletions src/content-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { isHttps } from './utils'
* @memberof AgilityFetch
* @param {Object} config - API intialization params.
* @param {string} config.guid - The guid that represents your instance.
* @param {string} config.accessToken - The secret token that represents your application.
* @param {string} config.apiKey - The secret token that represents your application.
* @param {boolean} [config.isPreview] - If your access token is for preview, then set this to true.
* @param {Object} [config.caching] - Optional Caching options. Caching is disabled by default.
* @param {number} [config.caching.maxAge] - In miliseconds. Default value is *0* (disabled). Recommeded value is *180000* (3 mins). Requests are cached in memory only (node or browser).
Expand All @@ -37,7 +37,7 @@ import { isHttps } from './utils'
*
* const api = agility.getApi({
* guid: '191309ca-e675-4be2-bb29-351879528707',
* accessToken: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* isPreview: false
* });
*/
Expand All @@ -51,7 +51,7 @@ function validateConfigParams(configParams) {

if(!configParams.guid || configParams.guid.length == 0) {
throw new TypeError('You must provide an guid.');
} else if(!configParams.accessToken || configParams.accessToken.length == 0) {
} else if(!configParams.apiKey || configParams.apiKey.length == 0) {
throw new TypeError('You must provide an access token.');
} else if(configParams.caching && isNaN(configParams.caching.maxAge)) {
throw new TypeError('When specifying a cache maxAge, you must set a number value in miliseconds, i.e. 180000 (3 mins).');
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getContentItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* const api = agility.getApi({
* guid: '191309ca-e675-4be2-bb29-351879528707',
* accessToken: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* });
*
* api.getContentItem({
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getContentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* const api = agility.getApi({
* guid: '191309ca-e675-4be2-bb29-351879528707',
* accessToken: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* });
*
* api.getContentList({
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* const api = agility.getApi({
* guid: '191309ca-e675-4be2-bb29-351879528707',
* accessToken: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* });
*
* api.getPage({
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getSitemapFlat.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* const api = agility.getApi({
* guid: '191309ca-e675-4be2-bb29-351879528707',
* accessToken: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* });
*
* api.getSitemapFlat({
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getSitemapNested.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
*
* const api = agility.getApi({
* guid: '191309ca-e675-4be2-bb29-351879528707',
* accessToken: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
* });
*
* api.getSitemapNested({
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function buildPathUrl(contentType, referenceName, sort, direction, filters, filt

function buildAuthHeader(config) {
let defaultAuthHeaders = {
'APIKey': config.accessToken
'APIKey': config.apiKey
};

if(config.requiresGuidInHeaders) {
Expand Down
10 changes: 5 additions & 5 deletions test/apiClients.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import agility from '../src/content-fetch'

// Agility Instance = 'Headless Integration Testing' [Dev]
const guid = 'c741222b-1080-45f6-9a7f-982381c5a485';
const accessTokenFetch = 'UnitTestsFetch.2ace650991363fbcffa6776d411d1b0d616b8e3424ce842b81cba7af0039197e';
const accessTokenPreview = 'UnitTestsPreview.69e6bca345ced0b7ca5ab358b351ea5c870790a5945c25d749a865332906b124';
const apiKeyFetch = 'UnitTestsFetch.2ace650991363fbcffa6776d411d1b0d616b8e3424ce842b81cba7af0039197e';
const apiKeyPreview = 'UnitTestsPreview.69e6bca345ced0b7ca5ab358b351ea5c870790a5945c25d749a865332906b124';

function createApiClient() {
var api = agility.getApi({
guid: guid,
accessToken: accessTokenFetch
apiKey: apiKeyFetch
});
return api;
}
Expand All @@ -17,7 +17,7 @@ function createApiClient() {
function createCachedApiClient() {
var api = agility.getApi({
guid: guid,
accessToken: accessTokenFetch,
apiKey: apiKeyFetch,
caching: {
maxAge: 5 * 60 * 1000 //==5mins
}
Expand All @@ -28,7 +28,7 @@ function createCachedApiClient() {
function createPreviewApiClient() {
var api = agility.getApi({
guid: guid,
accessToken: accessTokenPreview,
apiKey: apiKeyPreview,
isPreview: true
});
return api;
Expand Down
24 changes: 12 additions & 12 deletions test/getApi.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('getApi:', function() {
it('should return an api client object with required params', function(done) {
const api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token'
apiKey: 'some-access-token'
});
assert.strictEqual(typeof(api), "object");
done();
Expand All @@ -22,7 +22,7 @@ describe('getApi:', function() {
it('should return an api client object in preview mode', function(done) {
const api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token',
apiKey: 'some-access-token',
isPreview: true
});
assert.strictEqual(api.config.isPreview, true);
Expand All @@ -32,7 +32,7 @@ describe('getApi:', function() {
it('should contain method for getContentItem', function(done) {
const api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token'
apiKey: 'some-access-token'
});
assert.strictEqual(typeof(api.getContentItem), "function");
done();
Expand All @@ -41,7 +41,7 @@ describe('getApi:', function() {
it('should contain method for getContentList', function(done) {
const api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token'
apiKey: 'some-access-token'
});
assert.strictEqual(typeof(api.getContentList), "function");
done();
Expand All @@ -50,7 +50,7 @@ describe('getApi:', function() {
it('should contain method for getPage', function(done) {
const api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token'
apiKey: 'some-access-token'
});
assert.strictEqual(typeof(api.getPage), "function");
done();
Expand All @@ -59,7 +59,7 @@ describe('getApi:', function() {
it('should contain method for getSitemapFlat', function(done) {
const api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token'
apiKey: 'some-access-token'
});
assert.strictEqual(typeof(api.getSitemapFlat), "function");
done();
Expand All @@ -68,7 +68,7 @@ describe('getApi:', function() {
it('should contain method for getSitemapNested', function(done) {
const api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token'
apiKey: 'some-access-token'
});
assert.strictEqual(typeof(api.getSitemapNested), "function");
done();
Expand All @@ -78,7 +78,7 @@ describe('getApi:', function() {
const baseUrl = 'https://fake-url.agilitycms.com';
const api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token',
apiKey: 'some-access-token',
baseUrl: baseUrl
});
assert.strictEqual(api.config.baseUrl, baseUrl);
Expand All @@ -90,15 +90,15 @@ describe('getApi:', function() {
it('should throw an error if guid is not passed-in', function(done) {
expect(function() {
var api = agility.getApi({
accessToken: 'some-access-token'
apiKey: 'some-access-token'
});
assert.strictEqual(typeof(api), "object");
done();
}).to.throw( TypeError );
done();
});

it('should throw an error if accessToken is not passed-in', function(done) {
it('should throw an error if apiKey is not passed-in', function(done) {
expect(function() {
var api = agility.getApi({
guid: 'some-guid',
Expand All @@ -113,7 +113,7 @@ describe('getApi:', function() {
expect(function() {
var api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token',
apiKey: 'some-access-token',
caching: {
maxAge: 'ten thousand miliseconds'
}
Expand All @@ -129,7 +129,7 @@ describe('getApi:', function() {
expect(function() {
var api = agility.getApi({
guid: 'some-guid',
accessToken: 'some-access-token',
apiKey: 'some-access-token',
baseUrl: 'http://insecuresite.com'
});
assert.strictEqual(typeof(api), "object");
Expand Down