Skip to content
Browse files

Api to post from other apps

  • Loading branch information...
1 parent 408851d commit 0fb6a77eda4dd0152030e9132e7eea43bf9cdcd1 @DFectuoso committed Aug 5, 2010
Showing with 60 additions and 12 deletions.
  1. +3 −0 app.yaml
  2. +1 −1 dojo_name_api.py
  3. +51 −9 main.py
  4. +2 −0 static/style.css
  5. +3 −2 templates/main.html
View
3 app.yaml
@@ -12,6 +12,9 @@ handlers:
upload: static/robots.txt
- url: /static
static_dir: static
+- url: /api
+ script: main.py
+ login: optional
- url: /notifications/notifyio/post
script: main.py
login: admin
View
2 dojo_name_api.py
@@ -20,7 +20,7 @@ def fullname(username):
fullname = memcache.get('/users/%s:fullname' % username)
if not fullname:
taskqueue.add(url='/worker/user', params={'username': username})
- memcache.set('/users/%s:fullname' % username, username, 10)
+ memcache.set('/users/%s:fullname' % username, username, 100)
return username
else:
return fullname
View
60 main.py
@@ -13,12 +13,12 @@
import dojo_name_api, keys, notify_io, logging, cgi
-
-
#CONSTANTS#
UPDATES_LIMIT = 100
DOMAIN = "@gmail.com"
SENDER_MAIL = "HD-Logs <santiago1717@gmail.com>"
+APP_NAMES = ["Kudos", "Signin","Events"]
+APP_NAMES_NO_NOTIFY = ["Signin","Events"]
# Parsing the username ourselfs because the nickname on GAE does funky stuff with non @gmail account
def username(user):
@@ -45,8 +45,15 @@ def sendEmailNotifications(update):
# Worket to handle the fullname queue request.
class UserWorker(webapp.RequestHandler):
def post(self):
- username = self.request.get('username')
month_ttl = 3600*24*28
+ username = self.request.get('username')
+ try:
+ index = APP_NAMES.index(name)
+ except ValueError:
+ index = -1
+
+ if index != -1:
+ memcache.set('/users/%s:fullname' % username, username, month_ttl)
user = dojo_name_api.dojo_name('/users/%s' % username, month_ttl)
memcache.set('/users/%s:fullname' % username, "%s %s" % (user['first_name'], user['last_name']), month_ttl)
@@ -113,15 +120,47 @@ def get(self,cursor):
class CommentHandler(webapp.RequestHandler):
def post(self, update_id):
update = Update.get_by_id(int(update_id))
- if update:
+ body = sanitizeHtml(self.request.get('body'))
+ if update and len(body) > 0 and len(body) < 500:
image = 'http://0.gravatar.com/avatar/%s' % hashlib.md5(str(users.get_current_user()) + DOMAIN).hexdigest()
comment = Comment(
- body=sanitizeHtml(self.request.get('body')),
+ body=body,
update=update,
image_url=image)
comment.put()
self.redirect('/')
+class ApiHandler(webapp.RequestHandler):
+ def post(self):
+ body = sanitizeHtml(self.request.get('body'))
+ name = sanitizeHtml(self.request.get('name'))
+ key = self.request.get('key')
+ if body == "" or name == "" or key == "":
+ self.response.out.write("body,name and key are required")
+ return
+ if key == keys.logs_key:
+ try:
+ index = APP_NAMES.index(name)
+ except ValueError:
+ index = -1
+
+ if index != -1:
+ user = users.User(name + DOMAIN)
+ update = Update(body=body,image_url="/static/dojo_icon.png",user=user)
+ update.put()
+ try:
+ index = APP_NAMES_NO_NOTIFY.index(name)
+ except ValueError:
+ index = -1
+ if index == -1:
+ sendNotifyIoNotifications(update)
+ sendEmailNotifications(update)
+ self.response.out.write("OK")
+ else:
+ self.response.out.write("Not a valid App")
+ else:
+ self.response.out.write("Invalid Key")
+
class MainHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
@@ -136,10 +175,12 @@ def get(self):
def post(self):
image = 'http://0.gravatar.com/avatar/%s' % hashlib.md5(str(users.get_current_user()) + DOMAIN).hexdigest()
- update = Update(body=sanitizeHtml(self.request.get('body')),image_url=image)
- sendEmailNotifications(update)
- sendNotifyIoNotifications(update)
- update.put()
+ body = sanitizeHtml(self.request.get('body'))
+ if len(body) > 0 and len(body) < 500:
+ update = Update(body=body,image_url=image)
+ sendEmailNotifications(update)
+ sendNotifyIoNotifications(update)
+ update.put()
self.redirect('/')
class EmailSendNotificationHandler(webapp.RequestHandler):
@@ -179,6 +220,7 @@ def main():
('/', MainHandler),
('/updates/(.+)', UpdatesHandler),
('/comment/(.+)', CommentHandler),
+ ('/api', ApiHandler),
('/notifications/email', EmailEnableNotificationHandler),
('/notifications/email/send', EmailSendNotificationHandler),
('/notifications/notifyio', NotifyIoEnableNotificationHandler),
View
2 static/style.css
@@ -36,6 +36,8 @@ h4 { font-size: smaller; }
.update .avatar img {height:50px; width:50px; -webkit-border-radius: 2px;-moz-border-radius: 2px;border-radius: 2px;}
.update .update-body {margin-left: 56px; min-height:48px; display:block;}
.update-meta {color:#999999; display:block; font-size:11px;}
+.meta-right {text-align:right;color:#999999; display:block; font-size:11px;}
+.meta-left {text-align:left;color:#999999; display:block; font-size:11px;}
.update .user-fullname {color:#D50025;}
.comment .comment-fullname {color:#D50025;}
.update-input { width:90%; height:50px}
View
5 templates/main.html
@@ -3,8 +3,8 @@
<h3>What are you doing?</h3>
<form method="post">
- <textarea name="body" class="update-input"></textarea>
- <input type="submit" value="Update" />
+ <textarea name="body" class="update-input" ></textarea>
+ <input type="submit" value="Update" /><span class="meta-right">Max 500 chars</span>
</form>
<div id="updates">
{% for update in updates %}
@@ -37,6 +37,7 @@
<div class="comment-form-controls">
<input type="submit" value="Comment" />
<button type="button" class="comment-link-cancel" onclick="toggleComment({{update.key.id}})">Cancel</button>
+ <span class="meta-left">max 500 chars</span>
</div>
</form>
</div>

0 comments on commit 0fb6a77

Please sign in to comment.
Something went wrong with that request. Please try again.