Mercurial > pumpbridge
comparison src/facebook.coffee @ 3:98a070c98982
add Twitter support
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Thu, 05 Jun 2014 18:02:25 +0200 |
parents | b73191efc65b |
children | f352c74a6a5b |
comparison
equal
deleted
inserted
replaced
2:e942a968cb52 | 3:98a070c98982 |
---|---|
1 # Copyright (C) 2014 by Intevation GmbH | 1 # Copyright (C) 2014 by Intevation GmbH |
2 # Author: Mathias Gebbe <mgebbe@intevation.de> | 2 # Author: Mathias Gebbe <mgebbe@intevation.de> |
3 # | 3 # |
4 # This file is Free Software under the Apache License, Version 2.0 | 4 # This file is Free Software under the Apache License, Version 2.0; |
5 # (the "License"); and comes with ABSOLUTELY NO WARRANTY! | 5 # and comes with NO WARRANTY! |
6 # You may not use this file except in compliance with the License. | 6 # See the documentation coming with pumpbridge for details. |
7 # See LICENSE for details. | |
8 | 7 |
9 https = require("https") | 8 https = require("https") |
10 async = require("async") | 9 async = require("async") |
11 _ = require("underscore") | 10 _ = require("underscore") |
12 Routes = require("./routes") | 11 Routes = require("./routes") |
274 token = user.oauth_token | 273 token = user.oauth_token |
275 | 274 |
276 FB.setAccessToken token | 275 FB.setAccessToken token |
277 | 276 |
278 return if typeof post.object.content is "undefined" or post.object.content is "" | 277 return if typeof post.object.content is "undefined" or post.object.content is "" |
279 ToESN.search {uid: post.object.id }, (err, result) -> | 278 ToESN.search {uid: post.object.id + "@twitter"}, (err, result) -> |
280 if result.length is 0 | 279 if result.length is 0 |
281 body = post.object.content.replace(/<(?:.|\n)*?>/gm, '') + " " + post.object.url | 280 body = post.object.content.replace(/<(?:.|\n)*?>/gm, '') + " " + post.object.url |
282 | 281 |
283 FB.api "me/feed", "post", | 282 FB.api "me/feed", "post", |
284 message: body | 283 message: body |
288 return | 287 return |
289 | 288 |
290 async.waterfall [ | 289 async.waterfall [ |
291 (callback) -> | 290 (callback) -> |
292 savePost = new ToESN() | 291 savePost = new ToESN() |
293 savePost.uid = post.object.id | 292 savePost.uid = post.object.id + "@twitter" |
294 savePost.sourceUser = post.actor.id | 293 savePost.sourceUser = post.actor.id |
295 savePost.sourcePost = post.object.id | 294 savePost.sourcePost = post.object.id |
296 savePost.targetUser = user.user_ESN | 295 savePost.targetUser = user.user_ESN |
297 savePost.targetPost = res.id | 296 savePost.targetPost = res.id |
298 savePost.recipientUser = 'public' | 297 savePost.recipientUser = 'public' |