Skip to content
This repository
file 38 lines (36 sloc) 1.389 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
# Description:
# Messing around with the Coderwall API
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot coderwall <coderwall username> - Returns coder achievements from coderwall.com
#
# Author:
# mexitek

module.exports = (robot) ->
  robot.respond /(coderwall)( me)? (.*)/i, (msg) ->
    user = msg.match[3]
    msg.http("https://coderwall.com/"+user+".json")
      .get() (err, res, body) ->
        # If not response bad username
        if res.headers['content-length'] <= 1
          letter_s = if user.substr(-1)=='s' then '' else 's'
          msg.send "Sorry I cannot find "+user+"'"+letter_s+" coderwall"
        # Else return the coder badges
        else
          profile = JSON.parse(body)
          # Give an intro to the coderwall profile
          resp_str = profile.name + " from " + profile.location + " \n"
          resp_str += "coderwall -> http://coderwall.com/"+user + "\n"
          resp_str += "github -> https://github.com/" + profile.accounts.github + "\n"
          resp_str += profile.username + " has " + profile.endorsements + " endorsements and " + profile.badges.length + " badges\n"
          # Iterate all badges and continue building string
          profile.badges.forEach (badge) ->
            resp_str += "[" + badge.name + "] - " + badge.description + "\n"
          # Return response
          msg.send resp_str
Something went wrong with that request. Please try again.