UNPKG

telstra-api

Version:

A node.js module for interfacing with the Telstra Dev APIs

80 lines (69 loc) 2.49 kB
//© Copyright 2016 Joshua 'JD' Davison - MIT License. // Generated by CoffeeScript 1.10.0 (function() { var TelstraSMS; TelstraSMS = (function() { function TelstraSMS(tAuthInstance) { this.tAuthInstance = tAuthInstance; } TelstraSMS.prototype.send = function(target, message) { return this.tAuthInstance.doSecurePost("https://api.telstra.com/v1/sms/messages", { to: target, body: message }).then(function(msg) { var headers, ref, result, statusCode; statusCode = msg[0], headers = msg[1], result = msg[2]; if (statusCode === 202) { return result.messageId; } else { throw Error((ref = result.message) != null ? ref : "Unknown Error"); } }); }; TelstraSMS.prototype.getFullReplies = function(messageId) { return this.tAuthInstance.doSecurePost("https://api.telstra.com/v1/sms/messages/" + messageId + "/response").then(function(msg) { var headers, ref, result, statusCode; statusCode = msg[0], headers = msg[1], result = msg[2]; if (statusCode === 200) { return result; } else if (statusCode === 500) { return []; } else { throw Error((ref = result.message) != null ? ref : "Unknown Error"); } }); }; TelstraSMS.prototype.getFullStatus = function(messageId) { return this.tAuthInstance.doSecurePost("https://api.telstra.com/v1/sms/messages/" + messageId).then(function(msg) { var headers, ref, result, statusCode; statusCode = msg[0], headers = msg[1], result = msg[2]; if (statusCode === 200) { return result; } else { throw Error((ref = result.message) != null ? ref : "Unknown Error"); } }); }; TelstraSMS.prototype.getReplies = function(messageId) { return this.getFullReplies(messageId).then(function(msg) { var replies, reply; return replies = (function() { var i, len, results; results = []; for (i = 0, len = msg.length; i < len; i++) { reply = msg[i]; results.push(reply.content); } return results; })(); }); }; TelstraSMS.prototype.getStatus = function(messageId) { return this.getFullStatus(messageId).then(function(msg) { return msg.status; }); }; return TelstraSMS; })(); module.exports = TelstraSMS; }).call(this);