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
43 changes: 31 additions & 12 deletions 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.5.5",
"version": "0.5.6",
"description": "JavaScript library for the Agility Fetch API (node and browser)",
"main": "dist/agility-content-fetch.node.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import getSitemapNested from './methods/getSitemapNested'
import getContentItem from './methods/getContentItem'
import getContentList from './methods/getContentList'
import getPage from './methods/getPage'
import getGallery from './methods/getGallery'
import FilterOperators from './types/FilterOperator'
import FilterLogicOperators from './types/FilterLogicOperator'
import SortDirections from './types/SortDirection'
Expand Down Expand Up @@ -78,6 +79,7 @@ export default function createClient(userConfig) {
getContentItem: getContentItem,
getContentList: getContentList,
getPage: getPage,
getGallery: getGallery,
types: {
FilterOperators: FilterOperators,
FilterLogicOperators: FilterLogicOperators,
Expand Down
59 changes: 59 additions & 0 deletions src/methods/getGallery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { buildRequestUrlPath, buildAuthHeader } from '../utils'

/**
* Gets the details of a gallery by their Gallery ID.
* @memberof AgilityFetch.Client
* @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.
* @example
*
* import agility from '@agility/content-fetch'
*
* const api = agility.getApi({
* guid: 'ade6cf3c',
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
* });
*
* api.getGallery({
* galleryID: 22
* })
* .then(function(gallery) {
* console.log(gallery);
* })
* .catch(function(error) {
* console.log(error);
* });
*
*/
function getGallery(requestParams) {

validateRequestParams(requestParams);

//merge default params with request params
requestParams = {...defaultParams, ...requestParams};

const req = {
url: `/${requestParams.galleryID}`,
method: 'get',
baseURL: buildRequestUrlPath(this.config, 'gallery'),
headers: buildAuthHeader(this.config),
params:{}
};

return this.makeRequest(req);
}

function validateRequestParams(requestParams) {
if(!requestParams.galleryID) {
throw new TypeError('You must include a galleryID number in your request params.');
} else {
return;
}
}

const defaultParams = {
contentLinkDepth: 1
}

export default getGallery;
11 changes: 11 additions & 0 deletions src/types/Gallery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Defines a **Gallery** in the CMS
* @typedef Gallery
* @memberof AgilityFetch.Types
* @property {number} galleryID - The unique ID of the gallery.
* @property {string} name - The name of the gallery.
* @property {string} description - The description of the gallery.
* @property {number} count - The count of media items in the gallery.
* @property {Array<AgilityFetch.Types.MediaItem>} media - Array of media items in the gallery.
*/

12 changes: 12 additions & 0 deletions src/types/MediaItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Defines a **MediaItem** in the CMS
* @typedef MediaItem
* @memberof AgilityFetch.Types
* @property {number} mediaID - The unique ID of the media item.
* @property {string} fileName - The file name of the media item.
* @property {string} url - The url of the media item.
* @property {number} size - The size of the media item in bytes.
* @property {date} modifiedOn - The last modified date and time of the media item.
* @property {AgilityFetch.Types.MediaItemMetaData} metaData - Meta data for the media item.
*/

11 changes: 11 additions & 0 deletions src/types/MediaItemMetaData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Defines a **MediaItemMetaData** in the CMS
* @typedef MediaItemMetaData
* @memberof AgilityFetch.Types
* @property {string} Title - The title meta data of the media item.
* @property {string} Description - The description meta data of the media item.
* @property {string} LinkUrl - The link url meta data of the media item.
* @property {string} pixelHeight - The height in pixels of the media item.
* @property {string} pixelWidth - The width in pixels of the media item.
*/

3 changes: 1 addition & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function buildRequestUrlPath(config, languageCode) {
let urlPath = null;
let apiFetchOrPreview = null;

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

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

Expand Down
33 changes: 33 additions & 0 deletions test/getGallery.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import chai from 'chai'
const assert = chai.assert;
const expect = chai.expect;

import { createApiClient } from './apiClients.config'

/*
This file contains static references to content from the instance configured in the apiClient.config file.
*/



/* GET GALLERY *********************************************************/


describe('getGallery:', function() {

this.timeout('120s');

it('should retrieve a Gallery in live mode', function(done) {
var api = createApiClient();
api.getGallery({
galleryID: 1
})
.then(function(gallery) {
assert.strictEqual(gallery.galleryID, 1);
done();
})
.catch(done);
});


});