16
16
USER_AUTH_URL = 'https://www.yammer.com/oauth/authorize'
17
17
DEFAULT_API_PREFIX = 'https://www.yammer.com/api/v1/'
18
18
DEFAULT_API_SUFFIX = '.json'
19
+ TOPIC = ''
19
20
20
21
HEADERS = {
21
22
'Content-Type' : 'application/x-www-form-urlencoded' ,
@@ -64,7 +65,7 @@ def expire_cookie(self, path='/'):
64
65
)
65
66
66
67
def get (self ):
67
-
68
+
68
69
if self .request .get ('expire_cookie' , None ) == 'now' :
69
70
logging .debug ('EXPIRING COOKIE' )
70
71
self .expire_cookie ()
@@ -73,9 +74,14 @@ def get(self):
73
74
74
75
if self .get_cookie ():
75
76
logging .debug ('GOT COOKIE! %s' % self .get_cookie ())
76
- template_values = {
77
- 'messagesUrl' : '/messages?%s' % self .get_cookie (),
78
- }
77
+ if self .request .get ("topic_id" ):
78
+ template_values = {
79
+ 'messagesUrl' : '/messages?%s%s' % (self .get_cookie (),'&topic_id=' + self .request .get ("topic_id" )),
80
+ }
81
+ else :
82
+ template_values = {
83
+ 'messagesUrl' : '/messages?%s' % self .get_cookie (),
84
+ }
79
85
path = os .path .join (os .path .dirname (__file__ ), "templates/home.html" )
80
86
self .response .out .write (template .render (path , template_values ))
81
87
return
@@ -102,10 +108,9 @@ def get(self):
102
108
}
103
109
path = os .path .join (os .path .dirname (__file__ ), "templates/login.html" )
104
110
self .response .out .write (template .render (path , template_values ))
111
+
105
112
return
106
113
107
-
108
-
109
114
def post (self ):
110
115
111
116
logging .debug ('AUTHORIZE WITH VERIFY CODE: %s' % self .request .get ('oauth_verifier' ))
@@ -122,19 +127,22 @@ def post(self):
122
127
)
123
128
124
129
logging .debug ('AUTHORIZED: %s' % result .content )
125
-
130
+
126
131
self .set_cookie (result .content )
127
132
self .redirect ('/' )
128
-
133
+
129
134
130
135
class MessagesHandler (RequestHandler ):
131
136
def get (self ):
132
137
133
138
HEADERS ['Authorization' ] = getOAuthHeaders (
134
139
token = self .request .get ('oauth_token' ),
135
140
token_secret = self .request .get ('oauth_token_secret' ))
136
- MSGS_URL = '%smessages%s' % (DEFAULT_API_PREFIX , DEFAULT_API_SUFFIX )
137
-
141
+ if self .request .get ("topic_id" ):
142
+ MSGS_URL = '%smessages/about_topic/%s%s' % (DEFAULT_API_PREFIX , self .request .get ("topic_id" ), DEFAULT_API_SUFFIX )
143
+ else :
144
+ MSGS_URL = '%smessages%s' % (DEFAULT_API_PREFIX , DEFAULT_API_SUFFIX )
145
+
138
146
result = urlfetch .fetch (
139
147
url = MSGS_URL ,
140
148
method = urlfetch .GET ,
@@ -145,6 +153,8 @@ def get(self):
145
153
146
154
#self.response.out.write(data)
147
155
156
+ logging .debug ('Got messages' )
157
+
148
158
users = {}
149
159
ref_msgs = {}
150
160
for r in data ['references' ]:
@@ -181,11 +191,12 @@ def get(self):
181
191
182
192
def main ():
183
193
logging .getLogger ().setLevel (logging .DEBUG )
194
+
184
195
application = WSGIApplication ([
185
196
('/' , MainHandler ),
186
197
('/messages' , MessagesHandler ),
187
198
], debug = True )
188
-
199
+
189
200
wsgiref .handlers .CGIHandler ().run (application )
190
201
191
202
if __name__ == '__main__' :
0 commit comments