Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #293 from simon/flattr
Browse files Browse the repository at this point in the history
Update flattr script to work better with new API states
  • Loading branch information
tombell committed Feb 7, 2012
2 parents 055b385 + 0e809ae commit aa35446
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/scripts/flattr.coffee
Expand Up @@ -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
Expand Down Expand Up @@ -66,18 +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?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
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}"

0 comments on commit aa35446

Please sign in to comment.