diff src/pumpio.coffee @ 30:3e3fa35e3ce2

twitter sync likes, recommend mongodb configure pump2twitter, twitter2pump in webui
author Mathias Gebbe <mgebbe@intevation.de>
date Thu, 28 Aug 2014 18:40:39 +0200
parents a52b5b244e51
children 8238d312e281
line wrap: on
line diff
--- a/src/pumpio.coffee	Tue Jul 29 16:06:05 2014 +0200
+++ b/src/pumpio.coffee	Thu Aug 28 18:40:39 2014 +0200
@@ -140,6 +140,33 @@
       callback null, result
   return
 
+getLikes = (user, callback) ->
+  id = user.user_ESN.substr(0,user.user_ESN.indexOf('@'))
+  server = user.user_ESN.substr(user.user_ESN.indexOf('@')+1,user.user_ESN.length)
+  token = user.oauth_token.substr(0,user.oauth_token.indexOf(';'))
+  secret = user.oauth_token.substr(user.oauth_token.indexOf(';')+1,user.oauth_token.length)
+  # https://io.intevation.de/api/user/mgebbe/favorites
+  url = "https://" + server + "/api/user/" + id + "/favorites"
+  # get tokens and ask pump.io api for userinformation then update userdb
+  async.waterfall [
+   (callback) ->
+     Host.search {hostname: server}, callback
+   (host,callback)  ->
+     # get host from db
+     host = JSON.stringify(host)
+     host = JSON.parse(host)
+     #console.log JSON.stringify host
+     oauth = new OAuth.OAuth(host[0].request_token_endpoint, host[0].access_token_endpoint, host[0].client_id, host[0].client_secret, "1.0A", null, "HMAC-SHA1")
+     oauth.get url, token, secret, callback
+  ], (err,result) ->
+    if err
+      callback null, null
+    else
+      callback null, (result)
+  return
+
+
+
 isPublicActivity = (act) ->
   recip = []
   _.each [
@@ -159,4 +186,5 @@
 exports.getUserFeed = getUserFeed
 exports.getUser = getUser
 exports.getNote = getNote
+exports.getLikes = getLikes
 exports.postUser = postUser
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)