Skip to content

Commit

Permalink
feat: Allow locale in single item entry/asset methods
Browse files Browse the repository at this point in the history
  • Loading branch information
trodrigues committed Mar 23, 2016
1 parent 13ef98e commit e14d75a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/create-cda-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ export default function createCdaApi (http, resolveLinksGlobalSetting) {
* Gets an Entry
* @memberof CDAClient
* @param {string} id
* @param {Object=} query - Object with search parameters. In this method it's only useful for `locale`.
* @return {Promise<Entities.Entry>} Promise for an Entry
* @example
* client.getEntry('entryId')
* .then(entry => console.log(entry))
*/
function getEntry (id) {
return http.get('entries/' + id)
function getEntry (id, query = {}) {
return http.get('entries/' + id, createRequestConfig({query: query}))
.then(response => wrapEntry(response.data), errorHandler)
}

Expand All @@ -127,13 +128,14 @@ export default function createCdaApi (http, resolveLinksGlobalSetting) {
* Gets an Asset
* @memberof CDAClient
* @param {string} id
* @param {Object=} query - Object with search parameters. In this method it's only useful for `locale`.
* @return {Promise<Entities.Asset>} Promise for an Asset
* @example
* client.getAsset('assetId')
* .then(asset => console.log(asset))
*/
function getAsset (id) {
return http.get('assets/' + id)
function getAsset (id, query = {}) {
return http.get('assets/' + id, createRequestConfig({query: query}))
.then(response => wrapAsset(response.data), errorHandler)
}

Expand Down
20 changes: 20 additions & 0 deletions test/integration/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ test('Gets entry', t => {
})
})

test('Gets an entry with a specific locale', t => {
t.plan(1)
return client.getEntry('nyancat', {
locale: 'tlh'
})
.then(entry => {
t.equal(entry.sys.locale, 'tlh')
})
})

test('Gets entries', t => {
t.plan(1)
return client.getEntries()
Expand Down Expand Up @@ -327,6 +337,16 @@ test('Gets asset', t => {
})
})

test('Gets an asset with a specific locale', t => {
t.plan(1)
return client.getEntry('jake', {
locale: 'tlh'
})
.then(asset => {
t.equal(asset.sys.locale, 'tlh')
})
})

test('Gets assets', t => {
t.plan(1)
return client.getAssets()
Expand Down

0 comments on commit e14d75a

Please sign in to comment.