Mercurial > pumpbridge > pumpbridge
comparison src/pumpio.coffee @ 31:8238d312e281
var checks
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Tue, 30 Sep 2014 07:30:54 +0200 |
parents | 3e3fa35e3ce2 |
children |
comparison
equal
deleted
inserted
replaced
30:3e3fa35e3ce2 | 31:8238d312e281 |
---|---|
28 # get tokens and ask pump.io api for userinformation then update userdb | 28 # get tokens and ask pump.io api for userinformation then update userdb |
29 async.waterfall [ | 29 async.waterfall [ |
30 (callback) -> | 30 (callback) -> |
31 Host.search {hostname: server}, callback | 31 Host.search {hostname: server}, callback |
32 (host,callback) -> | 32 (host,callback) -> |
33 # get host from db | 33 return if not (host?) |
34 host = JSON.stringify(host) | 34 # get host from db |
35 host = JSON.parse(host) | 35 host = JSON.stringify(host) |
36 host = JSON.parse(host) | |
37 return if not (host[0]?) | |
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") | 38 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") |
37 oauth.get "https://" + server + "/api/user/"+id, token, secret, callback | 39 oauth.get "https://" + server + "/api/user/"+id, token, secret, callback |
38 ], (err,result) -> | 40 ], (err,result) -> |
39 #console.log 'PUMP BODY:' + result | 41 #console.log 'PUMP BODY:' + result |
40 try | 42 try |
59 token = bridgeuser[0].oauth_token.substr(0,bridgeuser[0].oauth_token.indexOf(';')) | 61 token = bridgeuser[0].oauth_token.substr(0,bridgeuser[0].oauth_token.indexOf(';')) |
60 secret = bridgeuser[0].oauth_token.substr(bridgeuser[0].oauth_token.indexOf(';')+1,bridgeuser[0].oauth_token.length) | 62 secret = bridgeuser[0].oauth_token.substr(bridgeuser[0].oauth_token.indexOf(';')+1,bridgeuser[0].oauth_token.length) |
61 Host.search {hostname: server}, callback | 63 Host.search {hostname: server}, callback |
62 (host,callback) -> | 64 (host,callback) -> |
63 # get host from db | 65 # get host from db |
64 host = JSON.stringify(host) | 66 return if not (host?) |
65 host = JSON.parse(host) | 67 host = JSON.stringify(host) |
68 host = JSON.parse(host) | |
69 return if not (host[0]?) | |
66 activity = | 70 activity = |
67 verb: "post" | 71 verb: "post" |
68 #cc: [ | 72 #cc: [ |
69 # id: "http://activityschema.org/collection/public" | 73 # id: "http://activityschema.org/collection/public" |
70 # objectType: "collection" | 74 # objectType: "collection" |
96 async.waterfall [ | 100 async.waterfall [ |
97 (callback) -> | 101 (callback) -> |
98 Host.search {hostname: server}, callback | 102 Host.search {hostname: server}, callback |
99 (host,callback) -> | 103 (host,callback) -> |
100 # get host from db | 104 # get host from db |
101 host = JSON.stringify(host) | 105 return if not (host?) |
102 host = JSON.parse(host) | 106 host = JSON.stringify(host) |
107 host = JSON.parse(host) | |
108 return if not (host[0]?) | |
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") | 109 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") |
104 oauth.get "https://" + server + "/api/user/"+id+"/feed", token, secret, callback | 110 oauth.get "https://" + server + "/api/user/"+id+"/feed", token, secret, callback |
105 ], (err,result) -> | 111 ], (err,result) -> |
106 #console.log 'PUMP BODY:' + result | 112 #console.log 'PUMP BODY:' + result |
107 try | 113 try |
124 # get tokens and ask pump.io api for userinformation then update userdb | 130 # get tokens and ask pump.io api for userinformation then update userdb |
125 async.waterfall [ | 131 async.waterfall [ |
126 (callback) -> | 132 (callback) -> |
127 Host.search {hostname: server}, callback | 133 Host.search {hostname: server}, callback |
128 (host,callback) -> | 134 (host,callback) -> |
129 # get host from db | 135 return if not (host?) |
130 host = JSON.stringify(host) | 136 # get host from db |
131 host = JSON.parse(host) | 137 host = JSON.stringify(host) |
138 host = JSON.parse(host) | |
139 return if not (host[0]?) | |
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") | 140 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") |
133 oauth.get noteurl, token, secret, callback | 141 oauth.get noteurl, token, secret, callback |
134 ], (err,result) -> | 142 ], (err,result) -> |
135 #console.log 'PUMP BODY:' + result | 143 #console.log 'PUMP BODY:' + result |
136 if err | 144 if err |
139 result = JSON.parse(result) | 147 result = JSON.parse(result) |
140 callback null, result | 148 callback null, result |
141 return | 149 return |
142 | 150 |
143 getLikes = (user, callback) -> | 151 getLikes = (user, callback) -> |
152 return if not (user?) | |
144 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) | 153 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) |
145 server = user.user_ESN.substr(user.user_ESN.indexOf('@')+1,user.user_ESN.length) | 154 server = user.user_ESN.substr(user.user_ESN.indexOf('@')+1,user.user_ESN.length) |
146 token = user.oauth_token.substr(0,user.oauth_token.indexOf(';')) | 155 token = user.oauth_token.substr(0,user.oauth_token.indexOf(';')) |
147 secret = user.oauth_token.substr(user.oauth_token.indexOf(';')+1,user.oauth_token.length) | 156 secret = user.oauth_token.substr(user.oauth_token.indexOf(';')+1,user.oauth_token.length) |
148 # https://io.intevation.de/api/user/mgebbe/favorites | 157 # https://io.intevation.de/api/user/mgebbe/favorites |
151 async.waterfall [ | 160 async.waterfall [ |
152 (callback) -> | 161 (callback) -> |
153 Host.search {hostname: server}, callback | 162 Host.search {hostname: server}, callback |
154 (host,callback) -> | 163 (host,callback) -> |
155 # get host from db | 164 # get host from db |
156 host = JSON.stringify(host) | 165 return if not (host?) |
157 host = JSON.parse(host) | 166 host = JSON.stringify(host) |
167 host = JSON.parse(host) | |
168 return if not (host[0]?) | |
158 #console.log JSON.stringify host | 169 #console.log JSON.stringify host |
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") | 170 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") |
160 oauth.get url, token, secret, callback | 171 oauth.get url, token, secret, callback |
161 ], (err,result) -> | 172 ], (err,result) -> |
162 if err | 173 if err |