Last active
August 29, 2015 14:00
-
-
Save ryanbateman/11374098 to your computer and use it in GitHub Desktop.
A Hubot script to quickly search for an Android app and provide a Playstore link if it exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Quickly look up an Android application using 42Matters search | |
# | |
# Configuration: | |
# | |
# HUBOT_42MATTERS_ACCESS_TOKEN - the access token required for API accesss | |
# | |
# Commands: | |
# hubot app - Replies with the first result from an app search on 42Matters API | |
# | |
access_token = process.env.HUBOT_42MATTERS_ACCESS_TOKEN | |
module.exports = (robot) -> | |
robot.respond /app ?\s(.*)/i, (msg) -> | |
query msg, msg.match[1], (body, err) -> | |
return msg.send "I had some problems looking up that app. Oh dear." if err | |
unless access_token? | |
msg.send "I need a 42Matters API token to be set to help you with that." | |
return; | |
body = JSON.parse body | |
return msg.send "I can't seem to find that app. Strange." if body.results.length == 0 | |
app = body.results[0] | |
trimmedDescription = app.description.split "\n", 1 | |
msg.send "Title: #{app.title}\nDownloads: #{app.downloads}\nDescription: #{trimmedDescription}\nLink: #{app.market_url}" | |
query = (msg, searchterm, cb) -> | |
msg.http("https://42matters.com/api/1/apps/search.json?q=#{searchterm}&limit=1&access_token=#{access_token}") | |
.get() (err, res, body) -> | |
cb(body, err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Done!