Adding photos properties

This commit is contained in:
Esteban Uscanga
2016-01-09 23:56:03 +01:00
parent e456c0c220
commit 73dc6a1dc1
2 changed files with 43 additions and 3 deletions

View File

@@ -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',

View File

@@ -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()
})