From 6ba5f4460c5cbb3d2bd587330cd83418d96f860f Mon Sep 17 00:00:00 2001 From: Simon Gate Date: Tue, 7 Feb 2012 15:18:37 +0100 Subject: [PATCH 1/2] Update flattr script --- src/scripts/flattr.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/scripts/flattr.coffee b/src/scripts/flattr.coffee index ae07c3637..e98256e87 100644 --- a/src/scripts/flattr.coffee +++ b/src/scripts/flattr.coffee @@ -9,7 +9,8 @@ module.exports = (robot) -> robot.respond /search things (.*)/i, (msg) -> query = msg.match[1] - msg.http("https://api.flattr.com/rest/v2/things/search?query=#{query}") + msg.http("https://api.flattr.com/rest/v2/things/search") + .query(query: query) .headers(Accept: "application/json") .get() (err, res, body) -> if err @@ -68,7 +69,8 @@ module.exports = (robot) -> robot.hear /(http(?:s)?:\/\/.*)/, (msg) -> url = msg.match[1] - msg.http("https://api.flattr.com/rest/v2/things/lookup?q=#{url}") + msg.http("https://api.flattr.com/rest/v2/things/lookup") + .query(url: url) .headers(Accept: "application/json") .get() (err, res, body) -> if err From 0e809ae3d97cca62c1e50c0dfc55d4a8ba1f5326 Mon Sep 17 00:00:00 2001 From: Simon Gate Date: Tue, 7 Feb 2012 16:10:53 +0100 Subject: [PATCH 2/2] flattr script gets better regexp and dont fail on new lookup status --- src/scripts/flattr.coffee | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/scripts/flattr.coffee b/src/scripts/flattr.coffee index e98256e87..26706f164 100644 --- a/src/scripts/flattr.coffee +++ b/src/scripts/flattr.coffee @@ -67,19 +67,18 @@ module.exports = (robot) -> thing = JSON.parse(body) msg.send "Thing: [#{thing.flattrs}] #{thing.title} - #{thing.link}" - robot.hear /(http(?:s)?:\/\/.*)/, (msg) -> + robot.hear /(https?:\/\/[-a-zA-Z0-9+&@#/%?=~_|$!:,.;]*)/, (msg) -> url = msg.match[1] msg.http("https://api.flattr.com/rest/v2/things/lookup") - .query(url: url) + .query('url': url) .headers(Accept: "application/json") .get() (err, res, body) -> if err return location = JSON.parse(body) - if location.message == 'not_found' - return - msg.http(location.location) - .headers(Accept: "application/json") - .get() (err, res, body) -> - thing = JSON.parse(body) - msg.send "Thing: [#{thing.flattrs}] #{thing.title} - #{thing.link}" + if location.message == 'found' + msg.http(location.location) + .headers(Accept: "application/json") + .get() (err, res, body) -> + thing = JSON.parse(body) + msg.send "Thing: [#{thing.flattrs}] #{thing.title} - #{thing.link}"