Skip to content

Commit

Permalink
Merge branch 'chen-fb-twitter'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostlilunan committed Apr 28, 2017
2 parents c502552 + af8345e commit bb3594a
Show file tree
Hide file tree
Showing 95 changed files with 6,384 additions and 13 deletions.
153 changes: 153 additions & 0 deletions API/flickrAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
var config = require('../config');
var Promise = require('promise');
var Flickr = require("node-flickr")
var keys = {
"api_key": config.flickr.consumer_key,
"secret": config.flickr.consumer_secret,
"user_id": config.flickr.user_id,
"access_token": config.flickr.access_token,
"access_token_secret": config.flickr.access_token_secret
};
var flickr = new Flickr(keys);

function flickrAPI(endpoint,addon,args,resolveName){
Object.assign(args,addon);
return new Promise((resolve,reject) =>{
flickr.get(endpoint, args, function(err, result){
if (err) {
console.error(err);
reject(err);
}else{
switch(resolveName){
case 'searchPhotos':
case 'recentPhotos':
case 'interestingPhotos':
case 'popular':
case 'photo':
case 'photoOf':
case 'favoritePhotos':
resolve(result.photos.photo);
break;

case 'searchGroups':
case 'group':
resolve(result.groups.group);
break;

case 'searchPlaces':
case 'boundingBox':
case 'topPlaces':
resolve(result.places.place);
break;

case'searchUsers':
resolve(result.user);
break;

case 'hotTags':
resolve(result.hottags.tag);
break;

case 'photosInSet':
resolve(result.photoset.photo);
break;

case 'photoset':
resolve(result.photosets.photoset);
break;

case 'photosetComments':
case 'comments':
resolve(result.comments.comment);
break;

case 'photosInGallery':
case 'gallery':
case 'galleriesOf':
//console.log(JSON.stringify(result));
resolve(result.galleries.gallery);
break;

case 'groupInfo':
resolve(result.group);
break;

case 'topics':
resolve(result.topics.topic);
break;

case 'placeInfo':
resolve(result.place);
break;

case 'tagClusters':
resolve(result.clusters.cluster);
break;

case 'relatedTags':
resolve(result.tags.tag);
break;

case 'profile':
resolve(result.profile);
break;

case 'personInfo':
//console.log(result.person);
resolve(result.person);
break;

case 'tree':
//console.log(JSON.stringify(result));
resolve(result.collections.collection);
break;

case 'contact':
resolve(result.contacts.contact);
break;

case 'tagList':
case 'popularTags':
resolve(result.who.tags.tag);
break;

case 'streamContext':
resolve(result);
break;

case 'exif':
resolve(result.photo.exif);
break;

case 'favoritePeople':
//console.log(JSON.stringify(result));
resolve(result.photo.person);
break;

case 'people':
//console.log(JSON.stringify(result));
resolve(result.people.person);
break;

case 'photoInfo':
resolve(result.photo);
break;

case 'size':
resolve(result.sizes.size);
break;

case 'locations':
resolve(result.photo.location);
break;

default:
console.log('sorry we can\'t find matching resolve type:' + resolveName);
resolve(null);
}
}
});
});
}

module.exports = flickrAPI;
Loading

0 comments on commit bb3594a

Please sign in to comment.