Skip to content

Commit 0763536

Browse files
author
Ali Tahir
committed
Added gallery functionality
1 parent c738faa commit 0763536

File tree

8 files changed

+160
-14
lines changed

8 files changed

+160
-14
lines changed

package-lock.json

Lines changed: 31 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api-client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import getSitemapNested from './methods/getSitemapNested'
55
import getContentItem from './methods/getContentItem'
66
import getContentList from './methods/getContentList'
77
import getPage from './methods/getPage'
8+
import getGallery from './methods/getGallery'
89
import FilterOperators from './types/FilterOperator'
910
import FilterLogicOperators from './types/FilterLogicOperator'
1011
import SortDirections from './types/SortDirection'
@@ -78,6 +79,7 @@ export default function createClient(userConfig) {
7879
getContentItem: getContentItem,
7980
getContentList: getContentList,
8081
getPage: getPage,
82+
getGallery: getGallery,
8183
types: {
8284
FilterOperators: FilterOperators,
8385
FilterLogicOperators: FilterLogicOperators,

src/methods/getGallery.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { buildRequestUrlPath, buildAuthHeader } from '../utils'
2+
3+
/**
4+
* Gets the details of a gallery by their Gallery ID.
5+
* @memberof AgilityFetch.Client
6+
* @param {Object} requestParams - The parameters for the API request.
7+
* @param {number} requestParams.galleryID - The galleryID of the requested item in this language.
8+
* @returns {Promise<AgilityFetch.Types.Gallery>} - Returns a gallery object.
9+
* @example
10+
*
11+
* import agility from '@agility/content-fetch'
12+
*
13+
* const api = agility.getApi({
14+
* guid: 'ade6cf3c',
15+
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
16+
* });
17+
*
18+
* api.getGallery({
19+
* galleryID: 22
20+
* })
21+
* .then(function(gallery) {
22+
* console.log(gallery);
23+
* })
24+
* .catch(function(error) {
25+
* console.log(error);
26+
* });
27+
*
28+
*/
29+
function getGallery(requestParams) {
30+
31+
validateRequestParams(requestParams);
32+
33+
//merge default params with request params
34+
requestParams = {...defaultParams, ...requestParams};
35+
36+
const req = {
37+
url: `/${requestParams.galleryID}`,
38+
method: 'get',
39+
baseURL: buildRequestUrlPath(this.config, 'gallery'),
40+
headers: buildAuthHeader(this.config),
41+
params:{}
42+
};
43+
44+
return this.makeRequest(req);
45+
}
46+
47+
function validateRequestParams(requestParams) {
48+
if(!requestParams.galleryID) {
49+
throw new TypeError('You must include a galleryID number in your request params.');
50+
} else {
51+
return;
52+
}
53+
}
54+
55+
const defaultParams = {
56+
contentLinkDepth: 1
57+
}
58+
59+
export default getGallery;

src/types/Gallery.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Defines a **Gallery** in the CMS
3+
* @typedef Gallery
4+
* @memberof AgilityFetch.Types
5+
* @property {number} galleryID - The unique ID of the gallery.
6+
* @property {string} name - The name of the gallery.
7+
* @property {string} description - The description of the gallery.
8+
* @property {number} count - The count of media items in the gallery.
9+
* @property {Array<AgilityFetch.Types.MediaItem>} media - Array of media items in the gallery.
10+
*/
11+

src/types/MediaItem.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Defines a **MediaItem** in the CMS
3+
* @typedef MediaItem
4+
* @memberof AgilityFetch.Types
5+
* @property {number} mediaID - The unique ID of the media item.
6+
* @property {string} fileName - The file name of the media item.
7+
* @property {string} url - The url of the media item.
8+
* @property {number} size - The size of the media item in bytes.
9+
* @property {date} modifiedOn - The last modified date and time of the media item.
10+
* @property {MediaItemMetaData} metaData - Meta data for the media item.
11+
*/
12+

src/types/MediaItemMetaData.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Defines a **MediaItemMetaData** in the CMS
3+
* @typedef MediaItemMetaData
4+
* @memberof AgilityFetch.Types
5+
* @property {string} Title - The title meta data of the media item.
6+
* @property {string} Description - The description meta data of the media item.
7+
* @property {string} LinkUrl - The link url meta data of the media item.
8+
* @property {string} pixelHeight - The height in pixels of the media item.
9+
* @property {string} pixelWidth - The width in pixels of the media item.
10+
*/
11+

src/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
function buildRequestUrlPath(config, languageCode) {
2-
let urlPath = null;
32
let apiFetchOrPreview = null;
43

54
if(config.isPreview) {
@@ -8,7 +7,7 @@ function buildRequestUrlPath(config, languageCode) {
87
apiFetchOrPreview = 'fetch';
98
}
109

11-
urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${languageCode}`;
10+
let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${languageCode}`;
1211
return urlPath;
1312
}
1413

test/getGallery.tests.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import chai from 'chai'
2+
const assert = chai.assert;
3+
const expect = chai.expect;
4+
5+
import { createApiClient } from './apiClients.config'
6+
7+
/*
8+
This file contains static references to content from the instance configured in the apiClient.config file.
9+
*/
10+
11+
12+
13+
/* GET GALLERY *********************************************************/
14+
15+
16+
describe('getGallery:', function() {
17+
18+
this.timeout('120s');
19+
20+
it('should retrieve a Gallery in live mode', function(done) {
21+
var api = createApiClient();
22+
api.getGallery({
23+
galleryID: 1
24+
})
25+
.then(function(gallery) {
26+
assert.strictEqual(gallery.galleryID, 1);
27+
done();
28+
})
29+
.catch(done);
30+
});
31+
32+
33+
});

0 commit comments

Comments
 (0)