Permalink
Browse files

Fix the delete api method.

  • Loading branch information...
1 parent 6e62b05 commit ab2563c2fc00b433349be2e03c06754137559520 @mythmon mythmon committed Aug 6, 2012
Showing with 18 additions and 10 deletions.
  1. +8 −3 api.js
  2. +10 −7 standup-irc.js
View
11 api.js
@@ -57,15 +57,19 @@ exports.status = {
/* Delete a status.
* - `id`: The id of the status to delete.
*/
- delete_: function(id) {
+ delete_: function(id, user) {
+ var body = JSON.stringify({
+ user: utils.canonicalUsername(user),
+ api_key: CONFIG.standup.api_key
+ });
var options = {
host: CONFIG.standup.host,
port: CONFIG.standup.port,
path: '/api/v1/status/' + id,
method: 'DELETE',
headers: {
'content-type': 'application/json',
- 'content-length': 0
+ 'content-length': body.length
}
};
@@ -83,10 +87,11 @@ exports.status = {
if (res.statusCode === 200) {
emitter.emit('ok', json);
} else {
- emitter.emit('error', json);
+ emitter.emit('error', res.statusCode, json);
}
});
});
+ req.end(body);
req.on('error', function(e) {
emitter.emit('error', String(e));
});
View
@@ -144,15 +144,18 @@ var commands = {
/* Delete a status by id number. */
'delete': function(user, channel, message, args) {
- if (args.charAt(0) === '#') {
- args = args.slice(1);
- }
- var ret = api.status.delete_(args);
+ var ret = api.status.delete_(args[0], user);
ret.on('ok', function(data) {
- client.say(channel, 'Ok, deleted status #' + args);
+ client.say(channel, 'Ok, status #' + args + ' is no more!');
});
- ret.on('error', function(data) {
- client.say(channel, "I'm a failure, I couldn't do it.");
+ ret.on('error', function(code, data) {
+ if (code === 403) {
+ client.say(channel, "You don't have permissiont to do that. " +
+ "Do you own that status?");
+ } else {
+ client.say(channel, "I'm a failure, I couldn't do it.");
+ }
+ console.log(data);
});
},

0 comments on commit ab2563c

Please sign in to comment.