Skip to content

Instantly share code, notes, and snippets.

@ryanbateman
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanbateman/11374098 to your computer and use it in GitHub Desktop.
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
# 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)
@technicalpickles
Copy link

I would definitely suggest checking that access_token is set before using it and warn the user. Check out https://github.com/github/hubot/blob/master/docs/scripting.md#environment-variables for some examples.

@ryanbateman
Copy link
Author

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment