-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pinterest API to the platform. Finish the User and Self part
See title
- Loading branch information
1 parent
0307135
commit 59bcbd7
Showing
9 changed files
with
805 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
var Promise = require('promise'); | ||
var request = require('request'); | ||
var config = require('../config'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
var request = require('request'); | ||
var config = require('../config'); | ||
|
||
var access_token = config.pinterest.access_token_key; | ||
|
||
|
||
function pinterest(args, fname){ | ||
return new Promise((resolve, reject) =>{ | ||
console.log("In PInterest API, switch functionality now"); | ||
console.log(fname); | ||
var queryUrl = "https://api.pinterest.com/v1"; | ||
switch(fname){ | ||
case "pUserRoot": | ||
queryUrl = pUserRoot(args, queryUrl); | ||
break; | ||
case "pSelfBoards": | ||
queryUrl = pSelfBoards(args, queryUrl); | ||
break; | ||
case "pSelfBoardsSuggested": | ||
queryUrl = pSelfBoardsSuggested(args, queryUrl); | ||
break; | ||
case "pSelfFollower": | ||
queryUrl = pSelfFollower(args, queryUrl); | ||
break; | ||
case "pSelfFollowingBoards": | ||
queryUrl = pSelfFollowingBoards(args, queryUrl); | ||
break; | ||
case "pSelfInterests": | ||
queryUrl = pSelfInterests(args, queryUrl); | ||
break; | ||
case "pSelfFollowing": | ||
queryUrl = pSelfFollowing(args, queryUrl); | ||
break; | ||
case "pSelfLikes": | ||
queryUrl = pSelfLikes(args, queryUrl); | ||
break; | ||
case "pSelfPins": | ||
queryUrl = pSelfPins(args, queryUrl); | ||
break; | ||
case "pSearchBoards": | ||
queryUrl = pSearchBoards(args, queryUrl); | ||
break; | ||
case "pSearchPins": | ||
queryUrl = pSearchPins(args, queryUrl); | ||
break; | ||
} | ||
|
||
var options = { | ||
method: 'GET', | ||
uri: queryUrl, | ||
}; | ||
|
||
request(options, function(error, response){ | ||
if(error) { | ||
console.log("Reuqest error") | ||
reject(error); | ||
} | ||
|
||
if(response) { | ||
console.log("send response data back") | ||
console.log(JSON.parse(response.body)) | ||
resolve(JSON.parse(response.body)); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function selfEncode(args){ | ||
var ret = '' | ||
|
||
for(var key in args){ | ||
if(args[key] && key != 'query') | ||
ret += key + '%2C'; | ||
} | ||
|
||
return ret.substring(0, ret.length-3); | ||
} | ||
|
||
function queryEncode(query){ | ||
var ret = 'query='; | ||
query = query.split(' '); | ||
for(i = 0; i < query.length; i++){ | ||
ret += query[i] + '+'; | ||
} | ||
|
||
return ret.substring(0, ret.length-1); | ||
} | ||
|
||
function pUserRoot(args, queryUrl){ | ||
queryUrl += ('/me/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSelfBoards(args, queryUrl){ | ||
queryUrl += ('/me/boards/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSelfBoardsSuggested(args, queryUrl){ | ||
queryUrl += ('/me/boards/suggested/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSelfFollower(args, queryUrl){ | ||
queryUrl += ('/me/followers/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSelfFollowingBoards(args, queryUrl){ | ||
queryUrl += ('/me/following/boards/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSelfInterests(args, queryUrl){ | ||
queryUrl += ('/me/following/interests/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSelfFollowing(args, queryUrl){ | ||
queryUrl += ('/me/following/users/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSelfLikes(args, queryUrl){ | ||
queryUrl += ('/me/likes/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSelfPins(args, queryUrl){ | ||
queryUrl += ('/me/pins/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSearchBoards(args, queryUrl){ | ||
queryUrl += ('/me/search/boards/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
query = queryEncode(args.query); | ||
queryUrl += '&' + query; | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
function pSearchPins(args, queryUrl){ | ||
queryUrl += ('/me/search/pins/?access_token=' + access_token ); | ||
var para = selfEncode(args); | ||
if(para != ''){ | ||
queryUrl += '&fields=' | ||
queryUrl += para | ||
} | ||
query = queryEncode(args.query); | ||
queryUrl += '&' + query; | ||
console.log(queryUrl); | ||
return queryUrl | ||
} | ||
|
||
module.exports = { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,9 +50,6 @@ app.use(function(err, req, res, next) { | |
res.render('error'); | ||
}); | ||
|
||
|
||
|
||
|
||
module.exports = { | ||
app | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.