From 66d6fc52a737e0feaab5bcc36d4d700aab01a586 Mon Sep 17 00:00:00 2001 From: longshuicy Date: Sat, 22 Apr 2017 13:16:05 -0500 Subject: [PATCH] tumblr done --- API/tumblrAPI.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 API/tumblrAPI.js diff --git a/API/tumblrAPI.js b/API/tumblrAPI.js new file mode 100644 index 0000000..7e056d7 --- /dev/null +++ b/API/tumblrAPI.js @@ -0,0 +1,68 @@ +var Promise = require('promise'); +var config = require('../config'); +var tumblr = require('tumblr.js'); +var client = tumblr.createClient({ + credentials:{ + consumer_key: config.tumblr.consumer_key, + consumer_secret: config.tumblr.consumer_secret, + token: config.tumblr.access_token, + token_secret: config.tumblr.access_token_secret + }, + returnPromises:true, +}); + +function tumblrAPI(resolveName, id, args){ + return new Promise((resolve,reject) =>{ + switch(resolveName){ + case 'tagged': + client.taggedPosts(args['tag'],args).then(function(resp){ + //console.log(resp) + resolve(resp); + }) + .catch(function(err){ + console.log(err); + reject(err); + }); + break; + + case 'blogInfo': + client.blogInfo(id).then(function(resp){ + //console.log(resp.blog); + resolve(resp.blog); + }) + .catch(function(err){ + console.log(err); + reject(err); + }); + break; + + case 'blogLikes': + client.blogLikes(id,args).then(function(resp){ + //console.log(resp.blog); + resolve(resp.liked_posts); + }) + .catch(function(err){ + console.log(err); + reject(err); + }); + break; + + case 'blogPosts': + client.blogPosts(id,args).then(function(resp){ + //console.log(resp.blog); + resolve(resp.posts); + }) + .catch(function(err){ + console.log(err); + reject(err); + }); + break; + + default: + console.log('sorry we can\'t find matching resolve type:' + resolveName); + resolve(null); + } + }); +} + +module.exports = tumblrAPI; \ No newline at end of file