diff --git a/src/picasa.js b/src/picasa.js index 3a285f0..31eb2ea 100644 --- a/src/picasa.js +++ b/src/picasa.js @@ -27,12 +27,50 @@ function getPhotos (accessToken, options, callback) { this.picasaRequest(accessToken, 'get', 'photo', options, (error, body) => { if (error) return callback(error) - const photos = body.feed.entry.map(entry => { return entry.content }) + const photoSchema = { + 'gphoto$id' : 'id', + 'gphoto$albumid' : 'album_id', + 'gphoto$access' : 'access', + 'gphoto$width' : 'width', + 'gphoto$height' : 'height', + 'gphoto$size' : 'size' , + 'gphoto$checksum' : 'checksum', + 'gphoto$timestamp' : 'timestamp', + 'gphoto$imageVersion' : 'image_version', + 'gphoto$commentingEnabled' : 'commenting_enabled', + 'gphoto$commentCount' : 'comment_count', + 'content' : 'content', + 'title' : 'title', + 'summary' : 'summary' + } + + const photos = body.feed.entry.map(entry => { + let photo = {} + + Object.keys(photoSchema).forEach(schemaKey => { + const key = photoSchema[schemaKey] + + if (key) photo[key] = checkParam(entry[schemaKey]) + }) + + return photo + }) callback(null, photos) }) } +function checkParam (param) { + if (!param) return '' + if (isValidType(param)) return param + else if (isValidType(param['$t'])) return param['$t'] + else return param +} + +function isValidType (value) { + return typeof value === 'string' || typeof value === 'number' +} + function getAuthURL () { const authenticationParams = { access_type : 'offline', diff --git a/src/picasa.test.js b/src/picasa.test.js index d902d3c..f1f9029 100644 --- a/src/picasa.test.js +++ b/src/picasa.test.js @@ -68,8 +68,10 @@ describe('Picasa', () => { picasa.getPhotos(accessToken, { maxResults : 1 }, (error, photos) => { expect(error).to.be.equals(null) - expect(photos[0].src).to.contain('IMG_0327.JPG') - expect(photos[0].type).to.be.equals('image/jpeg') + + expect(photos[0].title).to.be.equals('IMG_0327.JPG') + expect(photos[0].content.src).to.contain('IMG_0327.JPG') + expect(photos[0].content.type).to.be.equals('image/jpeg') done() })