Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
ADD: better handling of category types
Browse files Browse the repository at this point in the history
  • Loading branch information
florianholzapfel committed May 24, 2013
1 parent 651076a commit 31e3db6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ var utils = require('./utils');
var category = function(client, xml) {
this.client = client;
if(xml) {
var get_type = function(type) {
return type;
};
this.get_type = get_type.bind(this, xml['task-category'] ? 'task-category' : 'deal-category');
utils.parse_xml(this, xml['task-category'] || xml['deal-category'] || xml);
}
};
category.prototype.create = function(type, item, callback) {
var path = '/' + type + '_categories.xml';
category.prototype.create = function(item, callback) {
var path = '/' + item.type + '_categories.xml';
delete item.type;
this.client.create_item(path, utils.to_xml(item, type + '-category'), callback, category);
};
category.prototype.delete = function(type, callback) {
var url = '/' + type + '_categories/' + this.id + '.xml';
category.prototype.delete = function(callback) {
var url = '/' + this.get_type() + '_categories/' + this.id + '.xml';

this.client.send('DELETE', url, function(err, res) {
callback(err);
Expand All @@ -43,11 +48,11 @@ category.prototype.delete = function(type, callback) {
category.prototype.get = function(type, id, callback) {
this.client.get_item('/' + type + '_categories/' + id + '.xml', callback, category);
};
category.prototype.to_xml = function(type, excluded_keys) {
return utils.to_xml(this, type + '-category', excluded_keys);
category.prototype.to_xml = function(excluded_keys) {
return utils.to_xml(this, this.get_type() + '-category', excluded_keys);
};
category.prototype.update = function(type, callback) {
var path = '/' + type + '_categories/' + this.id + '.xml';
category.prototype.update = function(callback) {
var path = '/' + this.get_type() + '_categories/' + this.id + '.xml';
this.client.send('PUT', path, this.to_xml(type), callback);
};

Expand Down

0 comments on commit 31e3db6

Please sign in to comment.