Skip to content

Commit

Permalink
rsstodolist : add ability to fetch last links from a rsstodolist feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Grégory PAUL committed May 15, 2014
1 parent 6998d09 commit ce159a5
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/scripts/rsstodolist.coffee
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
# Description:
# Allows you to send links to the RssToDoList service
# Allows you to send or fetch links to/from the rsstodolist service (https://rsstodolist.appspot.com)
#
# Dependencies:
# None
# jsdom
#
# Configuration:
# None
#
# Commands:
# hubot rtdl show <user_name> - Display the <user_name> RssToDoList feed url
# hubot rtdl add <user_name> <link> - Send the <link> to <user_name> RssToDoList feed
# hubot rtdl show <user_name> - Display the <user_name> rsstodolist feed url
# hubot rtdl add <user_name> <link> - Send the <link> to <user_name> rsstodolist feed
# hubot rtdl last <user_name> <limit> - Display last <optional limit> links for that <user_name>
#
# Author:
# athieriot
# paulgreg
jsdom = require 'jsdom'

module.exports = (robot) ->
robot.respond /rtdl (add|show) ([^ ]*)( .*)?/i, (msg) ->
robot.respond /rtdl (add|show|last) ([^ ]*)( .*)?/i, (msg) ->
server_url = 'http://rsstodolist.appspot.com'

[action, user_name, link] = [msg.match[1], escape(msg.match[2]), msg.match[3]]
[action, user_name, arg] = [msg.match[1], escape(msg.match[2]), msg.match[3]]

if action == 'add' && link != undefined
if action == 'add' && arg != undefined
msg.http(server_url + '/add')
.query(n: user_name)
.query(url: link.trim())
.query(url: arg.trim())
.get() (err, res, body) ->
status = res.statusCode

Expand All @@ -33,3 +36,15 @@ module.exports = (robot) ->
msg.reply "An error occured on " + user_name + " feed"
else if action == 'show'
msg.reply user_name + ' feed is ' + server_url + '/?n=' + user_name
else if action == 'last'
msg.http(server_url + '/')
.query(n: user_name)
.query(l: arg || 10)
.get() (err, res, body) ->
try
xml = jsdom.jsdom(body)
for item in xml.getElementsByTagName("rss")[0].getElementsByTagName("channel")[0].getElementsByTagName("item")
do (item) ->
msg.reply " - " + item.getElementsByTagName("link")[0].childNodes[0].nodeValue
catch err
msg.reply err

0 comments on commit ce159a5

Please sign in to comment.