Skip to content

Commit e14d75a

Browse files
committed
feat: Allow locale in single item entry/asset methods
1 parent 13ef98e commit e14d75a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/create-cda-api.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ export default function createCdaApi (http, resolveLinksGlobalSetting) {
9797
* Gets an Entry
9898
* @memberof CDAClient
9999
* @param {string} id
100+
* @param {Object=} query - Object with search parameters. In this method it's only useful for `locale`.
100101
* @return {Promise<Entities.Entry>} Promise for an Entry
101102
* @example
102103
* client.getEntry('entryId')
103104
* .then(entry => console.log(entry))
104105
*/
105-
function getEntry (id) {
106-
return http.get('entries/' + id)
106+
function getEntry (id, query = {}) {
107+
return http.get('entries/' + id, createRequestConfig({query: query}))
107108
.then(response => wrapEntry(response.data), errorHandler)
108109
}
109110

@@ -127,13 +128,14 @@ export default function createCdaApi (http, resolveLinksGlobalSetting) {
127128
* Gets an Asset
128129
* @memberof CDAClient
129130
* @param {string} id
131+
* @param {Object=} query - Object with search parameters. In this method it's only useful for `locale`.
130132
* @return {Promise<Entities.Asset>} Promise for an Asset
131133
* @example
132134
* client.getAsset('assetId')
133135
* .then(asset => console.log(asset))
134136
*/
135-
function getAsset (id) {
136-
return http.get('assets/' + id)
137+
function getAsset (id, query = {}) {
138+
return http.get('assets/' + id, createRequestConfig({query: query}))
137139
.then(response => wrapAsset(response.data), errorHandler)
138140
}
139141

test/integration/tests.js

+20
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ test('Gets entry', t => {
5151
})
5252
})
5353

54+
test('Gets an entry with a specific locale', t => {
55+
t.plan(1)
56+
return client.getEntry('nyancat', {
57+
locale: 'tlh'
58+
})
59+
.then(entry => {
60+
t.equal(entry.sys.locale, 'tlh')
61+
})
62+
})
63+
5464
test('Gets entries', t => {
5565
t.plan(1)
5666
return client.getEntries()
@@ -327,6 +337,16 @@ test('Gets asset', t => {
327337
})
328338
})
329339

340+
test('Gets an asset with a specific locale', t => {
341+
t.plan(1)
342+
return client.getEntry('jake', {
343+
locale: 'tlh'
344+
})
345+
.then(asset => {
346+
t.equal(asset.sys.locale, 'tlh')
347+
})
348+
})
349+
330350
test('Gets assets', t => {
331351
t.plan(1)
332352
return client.getAssets()

0 commit comments

Comments
 (0)