 # Description:
 #   Listens for Asana URLs and provides info about the task.
 #   The message is a markdown formatted string.
-#   The format looks something like this:
+#   The format looks like this:
 # 
 #   > [ ] Task Title (Assignee)
 #   > Lorem ipsum dolor sit amet, I am the description …

    # extract task ID from URL
    task_id = msg.match[1]
    req_uri = "https://app.asana.com/api/1.0/tasks/#{task_id}"
    auth    = 'Basic ' + new Buffer("#{api_key}:").toString('base64')

    robot.http(req_uri)
      .header("Authorization", auth)

        # parse the response body
        data = JSON.parse(body).data

        # extract and reformat data from response
        task =
          title:    data.name
          status:   if data.completed then "[&#10003;]" else "[ ]"
          assignee: if data.assignee then "#{data.assignee.name}" else "unassigned"

        # clip notes at first paragraph
        if data.notes.length > 0
          split = data.notes.split("\n")
          task.notes = if split.length > 1 then "#{split[0]} …" else data.notes
        else
          task.notes = "(no description)"

        # send the finished markdown down the pipe
        msg.send response(task)
