Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ var client = function(config) {
var kayako = function(config) {
this.client = new client(config);
this.ticket = new(require('./ticket'))(this.client);
this.ticketattachment = new(require('./ticketattachment'))(this.client);
this.ticketattachments = new(require('./ticketattachments'))(this.client);
this.ticketpost = new(require('./ticketpost'))(this.client);
this.ticketcount = new(require('./ticketcount'))(this.client);
this.tickets = new(require('./tickets'))(this.client);
Expand Down
51 changes: 51 additions & 0 deletions lib/ticketattachment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var utils = require('node-kayako/lib/utils');
var querystring = require('querystring');
var crypto = require('crypto');

var ticketattachment = function (client, xml) {
this.client = client;
if (xml) {
utils.parse_xml(this, xml);
}
};

ticketattachment.prototype.post = function (optionsp, callback) {
var client = this.client;
var salt = crypto.randomBytes(20).toString('base64');
var options = {
e: '/Tickets/TicketAttachment',
apikey: this.client.get_apikey(),
salt: salt,
signature: this.client.generate_signature(salt)
};

options.ticketid = optionsp.ticketid;
options.ticketpostid = optionsp.ticketpostid;
options.filename = optionsp.filename;
options.contents = optionsp.contents;

var postdata = querystring.stringify(options);

var opts = {
path: '/api/index.php',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postdata.length
}
};

this.client.request(opts, postdata, function (err, res) {
if (err) {
callback(err);
} else {
client.parse_items(res.data, client, ticketattachment, callback);
}
});
};

ticketattachment.prototype.get = function (ticketid, id, callback) {
this.client.get_item('/Tickets/TicketAttachment/' + ticketid + '/' + id, ticketattachment, callback);
};

module.exports = ticketattachment;
14 changes: 14 additions & 0 deletions lib/ticketattachments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var utils = require('node-kayako/lib/utils');

var ticketattachments = function (client, xml) {
this.client = client;
if (xml) {
utils.parse_xml(this, xml);
}
};

ticketattachments.prototype.get = function (ticketid, callback) {
this.client.get_items('/Tickets/TicketAttachment/ListAll/' + ticketid, require('./ticketattachment'), callback);
};

module.exports = ticketattachments;