Mercurial > pumpbridge
annotate 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 |
rev | line source |
---|---|
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
1 # Copyright (C) 2014 by Intevation GmbH |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
2 # Author: Mathias Gebbe <mgebbe@intevation.de> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
3 # |
3 | 4 # This file is Free Software under the Apache License, Version 2.0; |
5 # and comes with NO WARRANTY! | |
6 # See the documentation coming with pumpbridge for details. | |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
7 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
8 https = require("https") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
9 async = require("async") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
10 _ = require("underscore") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
11 Routes = require("./routes") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
12 querystring = require("querystring") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
13 EdgeControl = require("./edgecontrol") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
14 Edge = require("./edge") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
15 Host = require("../node_modules/pump.io-client-app/lib/models/host") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
16 OAuth = require('oauth') |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
17 Usermap = require("./usermap") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
18 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
19 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
20 ####################################### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
21 ##### get user info pumpio ##### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
22 ####################################### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
23 getUser = (user) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
24 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
25 server = user.user_ESN.substr(user.user_ESN.indexOf('@')+1,user.user_ESN.length) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
26 token = user.oauth_token.substr(0,user.oauth_token.indexOf(';')) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
27 secret = user.oauth_token.substr(user.oauth_token.indexOf(';')+1,user.oauth_token.length) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
28 # get tokens and ask pump.io api for userinformation then update userdb |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
29 async.waterfall [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
30 (callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
31 Host.search {hostname: server}, callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
32 (host,callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
33 # get host from db |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
34 host = JSON.stringify(host) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
35 host = JSON.parse(host) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
36 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") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
37 oauth.get "https://" + server + "/api/user/"+id, token, secret, callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
38 ], (err,result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
39 #console.log 'PUMP BODY:' + result |
17
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
40 try |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
41 result = JSON.parse(result) |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
42 id = result.profile.id.substr(result.profile.id.indexOf(':')+1,result.profile.id.length) |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
43 Routes.updateUserDB(id,result.profile.preferredUsername,result.profile.displayName,result.profile.url,result.profile.image.url) |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
44 catch err |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
45 console.log 'pumpio getUser error' + err |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
46 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
47 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
48 postUser = (bridgeid, to, text, callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
49 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
50 bridgename = bridgeid.substr(0,bridgeid.indexOf('@')) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
51 server = bridgeid.substr(bridgeid.indexOf('@')+1,bridgeid.length) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
52 token=undefined |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
53 secret=undefined |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
54 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
55 async.waterfall [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
56 (callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
57 Usermap.search {id: bridgeid+'_to_'+bridgeid}, callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
58 (bridgeuser, callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
59 token = bridgeuser[0].oauth_token.substr(0,bridgeuser[0].oauth_token.indexOf(';')) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
60 secret = bridgeuser[0].oauth_token.substr(bridgeuser[0].oauth_token.indexOf(';')+1,bridgeuser[0].oauth_token.length) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
61 Host.search {hostname: server}, callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
62 (host,callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
63 # get host from db |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
64 host = JSON.stringify(host) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
65 host = JSON.parse(host) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
66 activity = |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
67 verb: "post" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
68 #cc: [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
69 # id: "http://activityschema.org/collection/public" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
70 # objectType: "collection" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
71 #] |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
72 to: [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
73 id: "acct:" + to |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
74 objectType: "person" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
75 ] |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
76 object: |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
77 objectType: "note" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
78 content: text |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
79 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") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
80 oauth.post "https://" + server + "/api/user/" + bridgename + "/feed", token, secret, JSON.stringify(activity), 'application/json', callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
81 ], (err,result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
82 #console.log 'PUMP BODY:' + result |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
83 callback null, result |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
84 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
85 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
86 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
87 ####################################### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
88 ##### get user pumpio feed ##### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
89 ####################################### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
90 getUserFeed = (user, callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
91 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
92 server = user.user_ESN.substr(user.user_ESN.indexOf('@')+1,user.user_ESN.length) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
93 token = user.oauth_token.substr(0,user.oauth_token.indexOf(';')) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
94 secret = user.oauth_token.substr(user.oauth_token.indexOf(';')+1,user.oauth_token.length) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
95 # get tokens and ask pump.io api for userinformation then update userdb |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
96 async.waterfall [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
97 (callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
98 Host.search {hostname: server}, callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
99 (host,callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
100 # get host from db |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
101 host = JSON.stringify(host) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
102 host = JSON.parse(host) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
103 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") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
104 oauth.get "https://" + server + "/api/user/"+id+"/feed", token, secret, callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
105 ], (err,result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
106 #console.log 'PUMP BODY:' + result |
17
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
107 try |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
108 result = JSON.parse(result) |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
109 callback null, result |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
110 catch err |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
111 console.log "pump.io Error" |
a52b5b244e51
removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents:
8
diff
changeset
|
112 callback null, null |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
113 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
114 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
115 ####################################### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
116 ##### get user pumpio note ##### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
117 ####################################### |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
118 getNote = (user, noteurl, callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
119 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
120 server = user.user_ESN.substr(user.user_ESN.indexOf('@')+1,user.user_ESN.length) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
121 token = user.oauth_token.substr(0,user.oauth_token.indexOf(';')) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
122 secret = user.oauth_token.substr(user.oauth_token.indexOf(';')+1,user.oauth_token.length) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
123 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
124 # get tokens and ask pump.io api for userinformation then update userdb |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
125 async.waterfall [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
126 (callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
127 Host.search {hostname: server}, callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
128 (host,callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
129 # get host from db |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
130 host = JSON.stringify(host) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
131 host = JSON.parse(host) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
132 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") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
133 oauth.get noteurl, token, secret, callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
134 ], (err,result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
135 #console.log 'PUMP BODY:' + result |
8
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
136 if err |
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
137 callback null, null |
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
138 else |
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
139 result = JSON.parse(result) |
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
140 callback null, result |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
141 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
142 |
30
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
143 getLikes = (user, callback) -> |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
144 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
145 server = user.user_ESN.substr(user.user_ESN.indexOf('@')+1,user.user_ESN.length) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
146 token = user.oauth_token.substr(0,user.oauth_token.indexOf(';')) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
147 secret = user.oauth_token.substr(user.oauth_token.indexOf(';')+1,user.oauth_token.length) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
148 # https://io.intevation.de/api/user/mgebbe/favorites |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
149 url = "https://" + server + "/api/user/" + id + "/favorites" |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
150 # get tokens and ask pump.io api for userinformation then update userdb |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
151 async.waterfall [ |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
152 (callback) -> |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
153 Host.search {hostname: server}, callback |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
154 (host,callback) -> |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
155 # get host from db |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
156 host = JSON.stringify(host) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
157 host = JSON.parse(host) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
158 #console.log JSON.stringify host |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
159 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") |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
160 oauth.get url, token, secret, callback |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
161 ], (err,result) -> |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
162 if err |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
163 callback null, null |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
164 else |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
165 callback null, (result) |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
166 return |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
167 |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
168 |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
169 |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
170 isPublicActivity = (act) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
171 recip = [] |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
172 _.each [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
173 "to" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
174 "cc" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
175 "bto" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
176 "bcc" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
177 ], (prop) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
178 recip = recip.concat(act[prop]) if _.isArray(act[prop]) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
179 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
180 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
181 _.some recip, (rec) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
182 rec.objectType is "collection" and rec.id is "http://activityschema.org/collection/public" |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
183 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
184 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
185 exports.isPublicActivity = isPublicActivity |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
186 exports.getUserFeed = getUserFeed |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
187 exports.getUser = getUser |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
188 exports.getNote = getNote |
30
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
17
diff
changeset
|
189 exports.getLikes = getLikes |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
190 exports.postUser = postUser |