annotate src/twitter.coffee @ 5:af9f5b94c019

receive tweets
author Mathias Gebbe <mgebbe@intevation.de>
date Fri, 06 Jun 2014 14:42:28 +0200
parents f352c74a6a5b
children 2123f355ab68
rev   line source
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
1 # twitter.js
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
2 #
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
3 # data object representing twitter.com
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
4 #
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
5 # Copyright 2013, E14N (https://e14n.com/)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
6 # all changes Copyright 2014, Intevation GmbH (https://intevation.org)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
7 #
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
8 # Licensed under the Apache License, Version 2.0 (the "License");
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
9 # you may not use this file except in compliance with the License.
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
10 # You may obtain a copy of the License at
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
11 #
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
12 # http://www.apache.org/licenses/LICENSE-2.0
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
13 #
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
14 # Unless required by applicable law or agreed to in writing, software
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
15 # distributed under the License is distributed on an "AS IS" BASIS,
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
17 # See the License for the specific language governing permissions and
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
18 # limitations under the License.
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
19
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
20 _ = require("underscore")
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
21 async = require("async")
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
22 OAuth = require("oauth").OAuth
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
23 PumpIOClientApp = require("pump.io-client-app")
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
24 DatabankObject = require("databank").DatabankObject
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
25 RequestToken = PumpIOClientApp.RequestToken
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
26 Usermap = require("./usermap")
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
27 Pump = require("./pumpio")
5
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
28 FromESN = require("./fromESN")
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
29 ToESN = require("./toESN")
5
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
30 Sync = require("./sync")
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
31
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
32 module.exports = (config) ->
5
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
33 bridgeid = config.bridgeid
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
34 client_id = config.twclient_id
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
35 client_secret = config.twclient_secret
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
36 request_token_endpoint = "https://api.twitter.com/oauth/request_token"
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
37 access_token_endpoint = "https://api.twitter.com/oauth/access_token"
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
38 authorization_endpoint = "https://api.twitter.com/oauth/authorize"
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
39 whoami_endpoint = "https://api.twitter.com/1.1/account/verify_credentials.json"
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
40 hostname = "twitter.com"
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
41
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
42 Twitter =
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
43 getRequestToken: (site, callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
44 oa = Twitter.getOAuth(site)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
45 async.waterfall [
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
46 (callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
47 oa.getOAuthRequestToken callback
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
48 (token, secret, other, callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
49 RequestToken.create
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
50 token: token
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
51 secret: secret
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
52 hostname: hostname
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
53 , callback
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
54 ], callback
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
55 return
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
56
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
57 authorizeURL: (rt) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
58 separator = undefined
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
59 if _.contains(authorization_endpoint, "?")
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
60 separator = "&"
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
61 else
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
62 separator = "?"
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
63 authorization_endpoint + separator + "oauth_token=" + rt.token
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
64
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
65 getAccessToken: (site, rt, verifier, callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
66 oa = Twitter.getOAuth(site)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
67 oa.getOAuthAccessToken rt.token, rt.secret, verifier, callback
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
68 return
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
69
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
70 whoami: (site, token, secret, callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
71 oa = Twitter.getOAuth(site)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
72 async.waterfall [(callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
73 oa.get whoami_endpoint, token, secret, callback
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
74 return
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
75 ], (err, doc, response) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
76 obj = undefined
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
77 if err
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
78 callback err, null
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
79 else
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
80 try
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
81 obj = JSON.parse(doc)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
82 callback null, obj
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
83 catch e
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
84 callback e, null
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
85 return
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
86
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
87 return
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
88
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
89 sync: (user) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
90 me = user.user_pumpio
5
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
91 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@'))
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
92 token = user.oauth_token
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
93 secret = user.extra_token
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
94 util = require("util")
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
95 twitter = require("twitter")
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
96 twit = new twitter(
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
97 consumer_key: client_id
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
98 consumer_secret: client_secret
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
99 access_token_key: token
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
100 access_token_secret: secret
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
101 )
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
102
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
103 # GET PUBLIC PUMP POSTS AND POST THEM
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
104 async.waterfall [
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
105 (callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
106 Usermap.search {id: me + '_to_' + me}, callback
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
107 (user, callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
108 Pump.getUserFeed(user[0],callback)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
109 (feed, callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
110 async.eachSeries feed.items, ((post, callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
111 # do for each post
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
112 if (post.verb is "post" or post.verb is "share") and (post.object.objectType is "note" or post.object.objectType is "image") and (Pump.isPublicActivity(post)) and (typeof post.object.deleted is "undefined")
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
113 ToESN.search {uid: post.object.id + "@twitter"}, (err, result) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
114 if result.length is 0
4
f352c74a6a5b remove typeof, corrected facebooks toESN entrys
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
115 # post to twitter
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
116 text = post.object.content.replace(/<(?:.|\n)*?>/gm, '')
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
117 status = ""
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
118 if text.length <= 140
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
119 status = text
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
120 else
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
121 status = text.substr(0, 140 - (post.object.url.length + 2)) + ".." + post.object.url
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
122 twit.verifyCredentials((data) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
123 #console.log util.inspect(data)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
124 return
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
125 ).updateStatus status, (data) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
126 async.waterfall [
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
127 (callback) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
128 savePost = new ToESN()
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
129 savePost.uid = post.object.id + "@twitter"
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
130 savePost.sourceUser = post.actor.id
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
131 savePost.sourcePost = post.object.id
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
132 savePost.targetUser = user.user_ESN
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
133 savePost.targetPost = data.id
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
134 savePost.recipientUser = 'public'
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
135 savePost.updated = Date.now()
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
136 savePost.save callback
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
137 ], (err, result) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
138 #console.log util.inspect(data)
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
139 return
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
140 callback null, 'done'
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
141 ), (err) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
142 callback null, 'done'
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
143 ],(err, result) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
144
5
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
145 ######################################
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
146 # get tweets and post them to pump.io#
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
147 ######################################
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
148 twit.verifyCredentials((data) ->
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
149 #console.log util.inspect(data)
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
150 return
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
151 ).getHomeTimeline {include_rts: false}, (data) ->
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
152 #console.log util.inspect(data)
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
153 _.each data, (tweet) ->
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
154 async.waterfall [
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
155 (callback) ->
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
156 FromESN.search {uid: tweet.id + "@twitter_to_" + me, recipientUser: me}, callback
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
157 (result, callback) ->
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
158 return if result.length isnt 0 or tweet.user.id == id
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
159 Sync.postParser tweet, null, 'twitter', callback
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
160 (parsed, callback) ->
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
161 Pump.postUser bridgeid, me, parsed, callback
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
162 (pumppost, callback) ->
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
163 pumppost = JSON.parse(pumppost)
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
164 FromESN.create
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
165 postid: tweet.id + "@twitter"
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
166 sourceUser: tweet.user.id
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
167 sourcePost: 'https://twitter.com/'+tweet.user.name+"/status/" + tweet.id
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
168 pumpPost: pumppost.object.id
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
169 recipientUser: me
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
170 created: Date.now()
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
171 , callback
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
172 ], (err, result) ->
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
173 #console.log result
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
174 # end
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
175 return
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
176 return
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
177
5
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
178 return
af9f5b94c019 receive tweets
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
179
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
180 getOAuth: (site) ->
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
181 new OAuth(request_token_endpoint, access_token_endpoint, client_id, client_secret, "1.0", site.url("/authorized-for-twitter"), "HMAC-SHA1", null, # nonce size; use default
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
182 "User-Agent": site.userAgent()
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
183 )
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
184
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
185 Twitter
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)