Skip to content

Commit

Permalink
Merge pull request #20 from jlengrand/add-nested-thumbnail
Browse files Browse the repository at this point in the history
Add support for nested key in the extraction of entries
  • Loading branch information
esteban-uo authored Feb 28, 2018
2 parents 657d8df + 427c6a0 commit d26f5ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/picasa.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function getPhotos (accessToken, options, callback) {
}

const albumSchema = {
'media$group.media$thumbnail' : 'thumbnail',
'gphoto$id' : 'id',
'gphoto$name' : 'name',
'gphoto$numphotos' : 'num_photos',
Expand Down Expand Up @@ -206,15 +207,22 @@ function parseEntry (entry, schema) {
const key = schema[schemaKey]

if (key) {
const value = checkParam(entry[schemaKey]);

const value = extractValue(entry, schemaKey, key);
photo[key] = value;
}
})

return photo
}

function extractValue(entry, schemaKey){
if(schemaKey.indexOf('.') !== -1){
const tempKey = schemaKey.split('.')[0];
return extractValue(checkParam(entry[tempKey]), schemaKey.replace(`${tempKey}.`, ''));
}
return checkParam(entry[schemaKey]);
}

function getAuthURL (config) {
const authenticationParams = {
access_type : 'offline',
Expand Down
13 changes: 11 additions & 2 deletions src/picasa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ describe('Picasa', () => {
},
"gphoto$nickname":{
"$t":"BobDeBouwer"
}
},
"media$group":{
"media$thumbnail":[
{
"url":"https://lh3.googleusercontent.com/-kyCVqkqZt3A/WA61zE/AAAAAAE0/d3cg_CP_Te41PxQJQ1ASGp4r2hGzH_TrgCHMYCg/s160-c/6401011308785",
"height":160,
"width":160
}
]
}
}
]
}
Expand Down Expand Up @@ -94,7 +103,7 @@ describe('Picasa', () => {
expect(albums[0].location).to.be.equals('Utrecht')
expect(albums[0].rights).to.be.equals('protected')
expect(albums[0].access).to.be.equals('protected')

expect(albums[0].thumbnail[0].url).to.be.equals('https://lh3.googleusercontent.com/-kyCVqkqZt3A/WA61zE/AAAAAAE0/d3cg_CP_Te41PxQJQ1ASGp4r2hGzH_TrgCHMYCg/s160-c/6401011308785')
})

it('should make a get request', () => {
Expand Down

0 comments on commit d26f5ab

Please sign in to comment.