annotate src/google.coffee @ 18:c552faae9c1c

removed unnecessary parts, fixed getFriends async.each
author Mathias Gebbe <mgebbe@intevation.de>
date Fri, 13 Jun 2014 16:37:20 +0200
parents a52b5b244e51
children 6b3f38af3fa4
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
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
4 # This file is Free Software under the Apache License, Version 2.0;
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
5 # and comes with NO WARRANTY!
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
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 Sync = require("./sync")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
12 Routes = require("./routes")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
13 querystring = require("querystring")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
14 EdgeControl = require("./edgecontrol")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
15 Edge = require("./edge")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
16 Pump = require("./pumpio")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
17 FromESN = require("./fromESN")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
18 Config = require("./config")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
19 querystring = require('querystring')
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 config = Config.config
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 bridgeid = config.bridgeid
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
24 interval = config.interval
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
25 CLIENTID = config.gpCLIENTID
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
26 CLIENTSECRET = config.gpCLIENTSECRET
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
27
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
28 ###############
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
29 # google sync #
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
30 ###############
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
31 sync = (user) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
32 return if not (user?)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
33 me = user.user_pumpio
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
34 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@'))
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
35 if not (interval?)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
36 interval = 15 * 60 * 1000 # 900 000 ms (15min)
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
37
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
38 async.waterfall [
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
39 (callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
40 updateToken(user,callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
41 (updateuser,callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
42 user = updateuser
18
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
43 #getUser(user)
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
44 getFriends(user,callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
45 ], (err, friends) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
46 # für jeden Freunde tue dies: hier bewusst von async.eachSeries friends, ((friend, callback) -> auf async.each gewechselt
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
47 async.each friends, ((friend, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
48 async.waterfall [
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
49 (callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
50 getStream(user, friend, callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
51 (stream, callback) ->
18
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
52 return if not stream?
17
a52b5b244e51 removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents: 10
diff changeset
53 async.each stream.items, ((post, cb) ->
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
54 async.waterfall [
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
55 (callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
56 FromESN.search {uid: post.id + "@google_to_" + me, recipientUser: me}, callback
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
57 (result, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
58 return if result.length isnt 0
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
59 ti = new Date().getTime() - interval
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
60 ts = Date.parse(post.published)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
61 if (ts >= ti)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
62 Sync.postParser post, null, 'google', callback
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
63 else
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 4
diff changeset
64 return
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
65 (parsed, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
66 Pump.postUser bridgeid, me, parsed, callback
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
67 (pumppost, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
68 pumppost = JSON.parse(pumppost)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
69 FromESN.create
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
70 postid: post.id + "@google"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
71 sourceUser: post.actor.id
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
72 sourcePost: post.url
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
73 pumpPost: pumppost.object.id
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
74 recipientUser: me
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
75 created: Date.now()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
76 , callback
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
77 ], (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
78 #console.log err
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
79 #console.log result
17
a52b5b244e51 removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents: 10
diff changeset
80 cb()
18
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
81 return
17
a52b5b244e51 removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents: 10
diff changeset
82 ), (err) ->
a52b5b244e51 removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents: 10
diff changeset
83 callback null, 'done'
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
84 ], (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
85 #console.log 'done.'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
86 callback null, 'done'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
87 ), (err) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
88 if err
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
89 console.log 'one post fail to process'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
90 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
91 console.log 'all google friends processed'
18
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
92 return
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
93 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
94
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
95
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
96 #######################################
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
97 ###### get user info googleplus ######
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
98 #######################################
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
99 getUser = (user) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
100 data = ""
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
101 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
102 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
103 options =
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
104 host: "www.googleapis.com"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
105 port: 443
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
106 path: "/plus/v1/people/" + id + '?access_token=' + token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
107
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
108 https.get(options, (res) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
109 #console.log "Got response: " + res.statusCode
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
110 res.on "data", (chunk) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
111 data += chunk
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
112 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
113
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
114 res.on "end", () ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
115 user = JSON.parse(data)
4
f352c74a6a5b remove typeof, corrected facebooks toESN entrys
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
116 Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url) if user.id?
0
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 ).on "error", (e) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
119 console.log "Got error: " + e.message
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
120 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
121 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
122
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 #######################################
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
125 ###### get google friends ######
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
126 #######################################
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
127 getFriends = (user, callback) ->
4
f352c74a6a5b remove typeof, corrected facebooks toESN entrys
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
128 return if not user?
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
129 data = ""
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
130 friends = new Array()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
131 me = user.user_pumpio
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
132 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
133 if user.oauth_token.indexOf(';') isnt -1
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
134 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
135 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
136 token = user.oauth_token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
137 options =
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
138 host: "www.googleapis.com"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
139 port: 443
10
ccf1d9e741bd corrected google apikey query, removed facebook query language
Mathias Gebbe <mgebbe@intevation.de>
parents: 7
diff changeset
140 path: "/plus/v1/people/me/people/visible?key=" + CLIENTID + "&"
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
141 headers:
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
142 "Authorization": "Bearer " + token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
143
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
144 https.get(options, (res) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
145 #console.log "Got response: " + res.statusCode
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
146 res.on "data", (chunk) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
147 data +=chunk
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
148
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
149 res.on "end", () ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
150 async.waterfall [
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
151 (callback) ->
18
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
152 users = JSON.parse(decodeURI(data))
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
153 return if (users.error?)
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
154 callback null,users
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
155 (users, callback) ->
18
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
156 #EdgeControl.removeEdges(me,'@google')
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
157 async.each users.items, ((user,cb) ->
4
f352c74a6a5b remove typeof, corrected facebooks toESN entrys
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
158 if user.id?
f352c74a6a5b remove typeof, corrected facebooks toESN entrys
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
159 friends.push(user.id)
18
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
160 #Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url)
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
161 #EdgeControl.addEdge(me,user.id+'@google')
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
162 cb()
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
163 ), (err) ->
c552faae9c1c removed unnecessary parts, fixed getFriends async.each
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
164 callback null, friends
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
165 ], (err, friends) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
166 callback null, friends
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
167 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
168
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
169 ).on "error", (e) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
170 console.log "Got error: " + e.message
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
171
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
172 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
173
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
174 #######################################
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
175 ###### get google stream ######
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
176 #######################################
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
177 getStream = (user, targetid, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
178 data = ""
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
179 max_results = 3
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
180 me = user.user_pumpio
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
181 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
182 if user.oauth_token.indexOf(';') isnt -1
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
183 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
184 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
185 token = user.oauth_token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
186 options =
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
187 host: "www.googleapis.com"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
188 port: 443
10
ccf1d9e741bd corrected google apikey query, removed facebook query language
Mathias Gebbe <mgebbe@intevation.de>
parents: 7
diff changeset
189 path: "/plus/v1/people/" + targetid + "/activities/public?maxResults="+max_results+"&key=" + CLIENTID
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
190 headers:
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
191 "Authorization": "Bearer " + token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
192
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
193 https.get(options, (res) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
194 #console.log "Got response: " + res.statusCode
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
195 res.on "data", (chunk) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
196 data +=chunk
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
197
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
198 res.on "end", () ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
199 data = JSON.parse(data)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
200 callback null, data
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
201
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
202 ).on "error", (e) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
203 console.log "Got error: " + e.message
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
204
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
205 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
206
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
207 getRefreshToken = (user, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
208 if user.oauth_token.indexOf(';') isnt -1
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
209 token = user.oauth_token.substr(0,user.oauth_token.indexOf(';'))
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
210 code = user.oauth_token.substr(user.oauth_token.indexOf(';')+1 ,user.oauth_token.length)
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
211 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
212 token = user.oauth_token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
213 data = ""
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
214 post_data = querystring.stringify(
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
215 "code": code
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
216 "client_id": CLIENTID
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
217 "client_secret": CLIENTSECRET
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
218 "grant_type": "authorization_code"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
219 "redirect_uri": "postmessage"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
220 )
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
221
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
222 headers =
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
223 "Authorization": "Bearer " + token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
224 "Content-Type": "application/x-www-form-urlencoded"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
225 'Content-Length': post_data.length
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
226
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
227 options =
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
228 host: "accounts.google.com"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
229 port: 443
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
230 path: "/o/oauth2/token"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
231 method: "POST"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
232 headers: headers
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
233
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
234 req = https.request(options, (res) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
235 res.setEncoding "utf8"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
236 res.on "data", (d) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
237 data += d
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
238
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
239 res.on "end", () ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
240 #console.log data
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
241 data = decodeURI(data)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
242 data = JSON.parse(data)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
243 callback null, data
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
244 #console.log '\n\n' + JSON.stringify(data.refresh_token)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
245 # usermap updaten und später mit extra arbeiten
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
246 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
247 )
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
248 req.write post_data
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
249 req.end()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
250
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
251
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
252 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
253
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
254 updateToken = (user, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
255 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
256 extra = user.extra_token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
257 data = ""
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
258 post_data = querystring.stringify(
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
259 "refresh_token": extra
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
260 "client_id": CLIENTID
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
261 "client_secret": CLIENTSECRET
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
262 "grant_type": "refresh_token"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
263 )
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
264
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
265 headers =
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
266 "Authorization": "Bearer " + token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
267 "Content-Type": "application/x-www-form-urlencoded"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
268 'Content-Length': post_data.length
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
269
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
270 options =
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
271 host: "accounts.google.com"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
272 port: 443
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
273 path: "/o/oauth2/token"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
274 method: "POST"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
275 headers: headers
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
276
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
277 req = https.request(options, (res) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
278 res.setEncoding "utf8"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
279 res.on "data", (d) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
280 data += d
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
281
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
282 res.on "end", () ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
283 data = decodeURI(data)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
284 data = JSON.parse(data)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
285 Routes.saveUsermap(user.user_pumpio,user.user_ESN,data.access_token, user.extra_token, callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
286 #console.log '\n\n' + JSON.stringify(data.refresh_token)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
287 # usermap updaten und später mit extra arbeiten
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
288 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
289 )
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
290 req.write post_data
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
291 req.end()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
292
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
293
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
294 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
295
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
296 exports.sync = sync
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
297 exports.getUser = getUser
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
298 exports.getRefreshToken = getRefreshToken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
299 exports.getFriends = getFriends
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)