From 5451605b3f31532c68eda0d8f15df36ce6bb1301 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Mon, 2 Oct 2017 09:38:12 +0200 Subject: [PATCH 01/19] platform version --- .DS_Store | Bin 0 -> 6148 bytes LICENSE | 7 + LICENSE.md | 21 --- README.md | 92 +--------- api/http.js | 32 ++++ api/rest.js | 35 ++++ index.js | 11 ++ package-lock.json | 406 +++++++++++++++++++++++++++++++++++++++++ package.json | 44 ++--- src/api/http.js | 197 -------------------- src/api/rest.js | 171 ----------------- src/decoder.js | 63 ------- src/diagnostic.js | 18 -- src/index.js | 16 -- src/transport.js | 62 ------- test.js | 4 + test/api/http.test.js | 238 ------------------------ test/api/rest.test.js | 307 ------------------------------- test/decorator.test.js | 66 ------- test/index.test.js | 23 --- test/transport.test.js | 31 ---- 21 files changed, 520 insertions(+), 1324 deletions(-) create mode 100644 .DS_Store create mode 100644 LICENSE delete mode 100644 LICENSE.md mode change 100755 => 100644 README.md create mode 100644 api/http.js create mode 100644 api/rest.js create mode 100644 index.js create mode 100644 package-lock.json delete mode 100755 src/api/http.js delete mode 100644 src/api/rest.js delete mode 100644 src/decoder.js delete mode 100644 src/diagnostic.js delete mode 100644 src/index.js delete mode 100644 src/transport.js create mode 100644 test.js delete mode 100644 test/api/http.test.js delete mode 100644 test/api/rest.test.js delete mode 100644 test/decorator.test.js delete mode 100644 test/index.test.js delete mode 100644 test/transport.test.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 (http://www.cainsvault.com/)", - "main": "./src/index.js", - "repository": { - "type": "git", - "url": "git://github.com/arcturial/clickatell-node.git" - }, - "bugs": { - "url": "https://github.com/arcturial/clickatell-node/issues" - }, - "keywords": [ - "clickatell", - "api", - "sms" - ], - "license": "GNU", - "dependencies": { - "merge": "1.2.0" - }, - "devDependencies": { - "mocha": "*", - "nock": "*" - }, - "scripts": { - "test": "node node_modules/mocha/bin/mocha --recursive" - } -} \ No newline at end of file + "name": "clickatell-platform", + "author": "Morne Zeelie ", + "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", + "main": "index.js", + "version": "2.0.0", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/holla22/clickatell-platform.git" + }, + "bugs": "https://github.com/holla22/clickatell-platform/issues", + "dependencies": { + "request": "^2.79.0" + } +} diff --git a/src/api/http.js b/src/api/http.js deleted file mode 100755 index 97114c8..0000000 --- a/src/api/http.js +++ /dev/null @@ -1,197 +0,0 @@ -/** - * This class represents the Clickatell HTTP API. The methods all function - * like a standard NodeJS API where the results are returned in two values "err" and "response": - * - * api.sendMessage(to, message, extra, function (err, response) { - * - * }); - * - */ - -var Transport = require('./../transport'); -var decoder = require('./../decoder'); -var merge = require('merge'); -var diagnostic = require('./../diagnostic'); -var transport = new Transport; - -function Http(user, password, apiId) -{ - var self = this; - self.user = user; - self.password = password; - self.apiId = apiId; -} - -// Apply request and response filters to any transport invocation. -// This methods adds the HTTP methods and arguments used in the HTTP -// API. It also unwraps the content to parse those plain text responses. -Http.prototype._invoke = function (uri, args, callback, throwErr) { - var self = this; - args.user = self.user; - args.password = self.password; - args.api_id = self.apiId; - - var options = { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' - }, - method: "GET" - }; - - transport.call(uri, args, options, function (content, err) { - - try { - if (err) throw err; - content = decoder.unwrapLegacy(content, throwErr); - callback.apply(self, [content, null]); - } catch (e) { - callback.apply(self, [null, e]); - } - }); -} - -/** - * https://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf - * - * Section 3.3 - */ -Http.prototype.sendMessage = function (to, message, extra, callback) { - - var self = this; - - // Merge parameter defaults together with the - // requested parameters. - var args = merge( - { - mo: 1, - callback: 7, - to: to.join(","), - text: message - }, - extra - ); - - self._invoke('/http/sendmsg', args, function (content, err) { - - // The sendmsg can't really fail. Since the call might succeed, but the message - // might be in a "non-delivered" state. We will always return an array of messages and - // the errors will be contained within the message data. - if (err) content = { error: err.message, code: err.code }; - var messages = []; - - // Always return an array so we can make sure it's a consistent response format; - content = (Object.keys(content))[0] === '0' ? content : [content]; - - for (var key in content) { - var message = content[key]; - - // Build up a new message from the fields that we acquired from the API response. - messages.push({ - id: typeof message.ID !== 'undefined' ? message.ID : false, - destination: typeof message.To !== 'undefined' ? message.To: args['to'], - error: typeof message.error !== 'undefined' ? message.error: false, - code: typeof message.code !== 'undefined' ? message.code : false - }); - } - - // Resolve the promised object. - callback.apply(self, [null, messages]); - }, false); - - return self; -} - -/** - * https://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf - * - * Section 5.2 - */ -Http.prototype.getBalance = function (callback) { - var self = this; - - self._invoke('/http/getbalance', {}, function (content, err) { - - if (err) return callback.call(self, err); - - callback.apply(self, [null, { - balance: parseFloat(content.Credit) - }]); - }); - - return self; -} - -/** - * https://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf - * - * Section 5.1 - */ -Http.prototype.stopMessage = function (apiMsgId, callback) { - var self = this; - - self._invoke('/http/delmsg', { apimsgid: apiMsgId }, function (content, err) { - if (err) return callback.call(self, err); - - callback.apply(self, [null, { - id: content.ID, - status: content.Status, - description: diagnostic[content.Status] - }]); - }); - - return self; -} - -/** - * https://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf - * - * Section 3.4 - */ -Http.prototype.queryMessage = function (apiMsgId, callback) { - var self = this; - return self.getMessageCharge(apiMsgId, callback); -} - -/** - * https://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf - * - * Section 5.3 - */ -Http.prototype.routeCoverage = function (msisdn, callback) { - var self = this; - - self._invoke('/utils/routeCoverage', { msisdn: msisdn }, function (content, err) { - - content = { - routable: err ? false : true, - msisdn: msisdn, - charge: err ? 0 : content.Charge - } - - return callback.apply(self, [null, content]) - }); - - return self; -} - -/** - * https://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf - * - * Section 5.6 - */ -Http.prototype.getMessageCharge = function (apiMsgId, callback) { - var self = this; - - self._invoke('/http/getmsgcharge', { apimsgid: apiMsgId }, function (content, err) { - if (err) return callback.call(self, err); - - callback.apply(self, [null, { - id: apiMsgId, - status: content.status, - description: diagnostic[content.status], - charge: parseFloat(content.charge) - }]); - }); -} - -module.exports = Http; \ No newline at end of file diff --git a/src/api/rest.js b/src/api/rest.js deleted file mode 100644 index 7fabeb5..0000000 --- a/src/api/rest.js +++ /dev/null @@ -1,171 +0,0 @@ -/** - * This class represents the Clickatell REST API. The methods all function - * like a standard NodeJS API where the results are returned in two values "err" and "response": - * - * api.sendMessage(to, message, extra, function (err, response) { - * - * }); - * - */ - -var Transport = require('./../transport'); -var decoder = require('./../decoder'); -var merge = require('merge'); -var diagnostic = require('./../diagnostic'); -var transport = new Transport; - -function Rest(token) -{ - var self = this; - self.token = token; -} - -// For REST we need to encode the packets en decode the responses. We will -// be using JSON since it's just the easiest. -Rest.prototype._invoke = function (uri, args, method, callback) { - var self = this; - - var options = { - headers: { - 'Authorization': 'Bearer ' + self.token, - 'Content-Type': 'application/json', - 'X-Version': '1', - 'Accept': 'application/json' - }, - method: method - }; - - args = JSON.stringify(args); - - transport.call(uri, args, options, function (content, err) { - - try { - if (err) throw err; - callback.apply(self, [decoder.decodeRest(content), null]); - } catch (e) { - callback.apply(self, [null, e]); - } - }); -} - -/** - * http://www.clickatell.com/help/apidocs/#Message.htm#SendMessage - */ -Rest.prototype.sendMessage = function (to, message, extra, callback) { - var self = this; - - // Merge parameter defaults together with the - // requested parameters. - var args = merge( - { - mo: 1, - callback: 7, - to: to, - text: message - }, - extra - ); - - self._invoke('/rest/message', args, 'POST', function (content, err) { - - if (err) content = { error: err.message, code: err.code }; - var messages = []; - - for (var key in content.message) { - var message = content.message[key]; - - // Build up a new message from the fields that we acquired from the API response. - messages.push({ - id: message.apiMessageId !== '' ? message.apiMessageId : false, - destination: typeof message.to !== 'undefined' ? message.to: false, - error: typeof message.error !== 'undefined' && message.error ? message.error.description : false, - code: typeof message.error !== 'undefined' && message.error ? message.error.code : false - }); - } - - // Resolve the promised object. - callback.apply(self, [null, messages]); - }); - - return self; -} - -/** - * http://www.clickatell.com/help/apidocs/#account-balance.htm%3FTocPath%3DClickatell%2520REST%2520API%2520Resources|_____3 - */ -Rest.prototype.getBalance = function (callback) { - var self = this; - - self._invoke('/rest/account/balance', {}, 'GET', function (content, err) { - if (err) return callback.call(self, err); - callback.apply(self, [null, { balance: content.balance }]); - }); -} - -/** - * http://www.clickatell.com/help/apidocs/#Message.htm#StopMessage - */ -Rest.prototype.stopMessage = function (apiMsgId, callback) { - var self = this; - - self._invoke('/rest/message/' + apiMsgId, {}, 'DELETE', function (content, err) { - if (err) return callback.call(self, err); - - var response = { - id: content.apiMessageId, - status: content.messageStatus, - description: diagnostic[content.messageStatus], - } - - callback.apply(self, [null, response]); - }); -} - -/** - * http://www.clickatell.com/help/apidocs/#Message.htm#QueryMsgStatus - */ -Rest.prototype.queryMessage = function (apiMsgId, callback) { - var self = this; - return self.getMessageCharge(apiMsgId, callback); -} - -/** - * http://www.clickatell.com/help/apidocs/#Coverage.htm%3FTocPath%3DClickatell%2520REST%2520API%2520Resources|_____1 - */ -Rest.prototype.routeCoverage = function (msisdn, callback) { - var self = this; - - self._invoke('/rest/coverage/' + msisdn, {}, 'GET', function (content, err) { - if (err) return callback.call(self, err); - - var response = { - routable: content.routable, - destination: content.destination, - charge: content.minimumCharge - } - - callback.apply(self, [null, response]); - }); -} - -/** - * http://www.clickatell.com/help/apidocs/#Message.htm#QueryMsgStatus - */ -Rest.prototype.getMessageCharge = function (apiMsgId, callback) { - var self = this; - - self._invoke('/rest/message/' + apiMsgId, {}, 'GET', function (content, err) { - if (err) return callback.call(self, err); - - var response = { - id: content.apiMessageId, - status: content.messageStatus, - description: diagnostic[content.messageStatus], - charge: content.charge - } - - callback.apply(self, [null, response]); - }); -} - -module.exports = Rest; \ No newline at end of file diff --git a/src/decoder.js b/src/decoder.js deleted file mode 100644 index bfee14c..0000000 --- a/src/decoder.js +++ /dev/null @@ -1,63 +0,0 @@ -/** - * This class deals with unwrapping the data we receive from Clickatell - * into a usable format. The adapter can then proceed with their tasks in a "known" - * manner and not have to worry about different packet results when changing variables. - */ - -module.exports = { - decodeRest: function (data) { - var data = JSON.parse(data); - - if (typeof data.error !== 'undefined') { - var response = new Error(data.error.description); - response.code = data.error.code; - throw response; - } - - return data.data; - }, - // This function is responsible for parsing the text packets that Clickatell - // returns. Their format is inconsistent so any exceptions also needs to be handled - // in this function. - unwrapLegacy: function (data, throwErr) { - - throwErr = throwErr == null ? true : throwErr; - var lines = data.trim("\n").split("\n"); - var result = []; - var re = new RegExp(/([A-Za-z]+):((.(?![A-Za-z]+:))*)/g); - - for (var key in lines) { - var line = lines[key]; - var match; - var row = []; - - // Loop through every match and create an associative - // array that indexes by using the response key. - while (match = re.exec(line)) { - row[match[1]] = match[2].trim(); - } - - // If an "ERR" key is present it means the entire packet (or part of it) failed - // and must be handled. We will only throw an error if the packet contained one - // item...otherwise it's too difficult to handle. - if (typeof row['ERR'] !== 'undefined') { - var error = row['ERR'].split(","); - row.code = error.length == 2 ? error[0] : 0; - row.error = typeof error[1] !== 'undefined' ? error[1].trim() : error[0]; - delete row['ERR']; - - // If this response only has one value then we will - // raise an exception to be handled. - if (lines.length == 1 && throwErr) { - var response = new Error(row['error']); - response.code = row['code']; - throw response; - } - } - - result.push(row); - } - - return result.length > 1 ? result : result[0]; - } -} \ No newline at end of file diff --git a/src/diagnostic.js b/src/diagnostic.js deleted file mode 100644 index e5a239a..0000000 --- a/src/diagnostic.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * This file just contains a list of message status descriptions. Some of the API's actually - * return this information with the call, but others don't. - */ -module.exports = { - "001": "The message ID is incorrect or reporting is delayed.", - "002": "The message could not be delivered and has been queued for attempted redelivery.", - "003": "Delivered to the upstream gateway or network (delivered to the recipient).", - "004": "Confirmation of receipt on the handset of the recipient.", - "005": "There was an error with the message, probably caused by the content of the message itself.", - "006": "The message was terminated by a user (stop message command) or by our staff.", - "007": "An error occurred delivering the message to the handset. 008 0x008 OK Message received by gateway.", - "009": "The routing gateway or network has had an error routing the message.", - "010": "Message has expired before we were able to deliver it to the upstream gateway. No charge applies.", - "011": "Message has been queued at the gateway for delivery at a later time (delayed delivery).", - "012": "The message cannot be delivered due to a lack of funds in your account. Please re-purchase credits.", - "014": "Maximum MT limit exceeded The allowable amount for MT messaging has been exceeded.", -} \ No newline at end of file diff --git a/src/index.js b/src/index.js deleted file mode 100644 index 57da823..0000000 --- a/src/index.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * This class serves as the main script and also a sort of "factory" for all - * the available transports. - */ - -var Http = require("./api/http"); -var Rest = require('./api/rest'); - -module.exports = { - http: function (user, password, apiId) { - return new Http(user, password, apiId); - }, - rest: function (token) { - return new Rest(token); - } -} \ No newline at end of file diff --git a/src/transport.js b/src/transport.js deleted file mode 100644 index a113c53..0000000 --- a/src/transport.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * The transport class is a wrapper around NodeJS HTTP class. - * It contains some custom functionalit like request and response filters - * to make the wrapping and unwrapping of data easier. - */ - -var merge = require('merge'); -var http = require('http'); -var querystring = require('querystring'); - -function Transport() -{ - var self = this; - - // Define the default httpOptions to use - // for our request to the Clickatell API. - self.options = { - hostname: 'api.clickatell.com', - port: 80, - method: 'GET', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' - } - }; - - self.call = function (uri, args, options, callback) { - - var query = querystring.stringify(args); - query = query ? "?" + query : ""; - - options = merge(self.options, options); - options.path = uri + (options.method == 'GET' ? query : ''); - - // Run the HTTP request and register the callback listener. - var req = http.request(options, function (res) { - var data = []; - - res.on('data', function (chunk) { - data.push(chunk); - }); - - res.on('end', function () { - var content = Buffer.concat(data).toString('utf8'); - - // If the response filter wasn't specified or did not fail...only - // then can we be sure that our content is safe. - callback.apply(self, [content, null]); - }); - }); - - // Listen for any potential errors so we can notify - // the calling adapter. - req.on('error', function (err) { - callback.apply(self, [null, err]); - }); - - // Finalize the request - req.end(options.method == "POST" ? args : ''); - } -} - -module.exports = Transport; \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..d4c0ecb --- /dev/null +++ b/test.js @@ -0,0 +1,4 @@ +var clickatell = require('./index.js'); + +///clickatell.rest("Hello testing message", ["27XXXXX-NUMBER"], ""); +clickatell.http("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); diff --git a/test/api/http.test.js b/test/api/http.test.js deleted file mode 100644 index a5d0c56..0000000 --- a/test/api/http.test.js +++ /dev/null @@ -1,238 +0,0 @@ -var assert = require("assert"); -var Http = require("./../../src/api/http"); -var diagnostic = require("./../../src/diagnostic"); -var nock = require("nock"); - - -var user = "user"; -var pass = "pass"; -var apiId = 12345; - -describe("http.js", function () { - - describe("sendMessage", function () { - - it("should ensure that default parameters are added to requests", function (done) { - - var to = "00000000000"; - var message = 'message'; - - nock('http://api.clickatell.com') - .get('/http/sendmsg?mo=1&callback=7&to=' + to + '&text=' + message + '&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'ID: 12345 To: 123'); - - var api = new Http(user, pass, apiId); - api.sendMessage([to], message, {}, function (err, content) { - assert(err == null); - assert.equal(content[0].destination, 123); - assert.equal(content[0].id, 12345); - done(); - }); - }); - - it("should handle error messages properly", function (done) { - - var to = "00000000000"; - var message = 'message'; - - nock('http://api.clickatell.com') - .get('/http/sendmsg?mo=1&callback=7&to=' + to + '&text=' + message + '&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'ERR: 301, Some error'); - - var api = new Http(user, pass, apiId); - api.sendMessage([to], message, {}, function (err, content) { - assert(err == null); - assert.equal(content[0].error, 'Some error'); - assert.equal(content[0].code, 301); - done(); - }); - }); - - it("should handle mixed success/error messages properly", function (done) { - - var to = ["00000000000", "00000000001"]; - var message = 'message'; - - nock('http://api.clickatell.com') - .get('/http/sendmsg?mo=1&callback=7&to=00000000000%2C00000000001&text=' + message + '&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'ERR: 301, Some error\nID: 12345 To: 00000000001'); - - var api = new Http(user, pass, apiId); - api.sendMessage(to, message, {}, function (err, content) { - assert(err == null); - assert.equal(content[0].error, 'Some error'); - assert.equal(content[0].code, 301); - assert.equal(content[1].destination, '00000000001'); - assert.equal(content[1].id, 12345); - done(); - }); - }); - }); - - - describe("getBalance", function () { - - - it("should return an error if the call was incorrectly formatted", function (done) { - - nock('http://api.clickatell.com') - .get('/http/getbalance?user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'ERR: 301, Some error'); - - var api = new Http(user, pass, apiId); - - api.getBalance(function (err, content) { - - assert(err instanceof Error); - assert.equal(301, err.code); - assert.equal('Some error', err.message); - done(); - }); - }); - - it("should return the balance from the 'Credit' field", function (done) { - - nock('http://api.clickatell.com') - .get('/http/getbalance?user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'Credit: 101'); - - var api = new Http(user, pass, apiId); - - api.getBalance(function (err, content) { - - assert.equal(101, content.balance); - done(); - }); - }); - - }); - - describe("stopMessage", function () { - - it("should return an error if the call failed", function (done) { - - nock('http://api.clickatell.com') - .get('/http/delmsg?apimsgid=123456&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'ERR: 301, Some error'); - - var api = new Http(user, pass, apiId); - - api.stopMessage("123456", function (err, content) { - assert(err instanceof Error); - assert.equal(301, err.code); - assert.equal('Some error', err.message); - done(); - }); - - }); - - it("should return the message details if call was succesful", function (done) { - - nock('http://api.clickatell.com') - .get('/http/delmsg?apimsgid=123456&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'ID: 123456 Status: 004'); - - var api = new Http(user, pass, apiId); - - api.stopMessage("123456", function (err, content) { - assert.equal("123456", content.id); - assert.equal("004", content.status); - assert.equal(diagnostic["004"], content.description); - done(); - }); - - }); - - }); - - describe("queryMessage", function () { - - it("should forward the call to getMessageCharge", function (done) { - - var api = new Http(user, pass, apiId); - - api.getMessageCharge = function (apiMsgId, callback) { - callback.apply(this, [null, true]); - }; - - api.queryMessage("123456", function (err, content) { - assert(content); - done(); - }); - }); - - }); - - describe("routeCoverage", function () { - - it("should return a non routable response incase of error", function (done) { - - nock('http://api.clickatell.com') - .get('/utils/routeCoverage?msisdn=123456&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'ERR: 301, Some error'); - - var api = new Http(user, pass, apiId); - api.routeCoverage("123456", function (err, content) { - assert(err == null); - assert.equal(false, content.routable); - done(); - }); - }); - - it("should return a routable status if successful", function (done) { - - nock('http://api.clickatell.com') - .get('/utils/routeCoverage?msisdn=123456&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'Charge: 100'); - - var api = new Http(user, pass, apiId); - api.routeCoverage("123456", function (err, content) { - assert(err == null); - assert.equal(true, content.routable); - assert.equal(100, content.charge); - assert.equal("123456", content.msisdn); - done(); - }); - - }); - }); - - describe("getMessageCharge", function () { - - - it("should return an error if the request fails", function (done) { - - nock('http://api.clickatell.com') - .get('/http/getmsgcharge?apimsgid=123456&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'ERR: 301, Some error'); - - var api = new Http(user, pass, apiId); - api.getMessageCharge("123456", function (err, content) { - assert(err instanceof Error); - assert.equal(301, err.code); - assert.equal('Some error', err.message); - done(); - }); - - }); - - it("should return the correct fields upon success", function (done) { - - nock('http://api.clickatell.com') - .get('/http/getmsgcharge?apimsgid=123456&user=' + user + '&password=' + pass + '&api_id=' + apiId) - .reply(200, 'status: 004 charge: 101'); - - var api = new Http(user, pass, apiId); - api.getMessageCharge("123456", function (err, content) { - - assert.equal(101, content.charge); - assert.equal("004", content.status); - assert.equal(diagnostic[content.status], content.description); - done(); - }); - - }); - - }); - -}); \ No newline at end of file diff --git a/test/api/rest.test.js b/test/api/rest.test.js deleted file mode 100644 index bcdaf33..0000000 --- a/test/api/rest.test.js +++ /dev/null @@ -1,307 +0,0 @@ -var assert = require("assert"); -var Rest = require("./../../src/api/rest"); -var diagnostic = require("./../../src/diagnostic"); -var nock = require("nock"); - - -var token = "token"; - -describe("rest.js", function () { - - describe("_invoke", function () { - - it("should append the appropriate RESTful headers", function (done) { - - nock( - 'http://api.clickatell.com', - { - reqheaders: { - 'Authorization': 'Bearer ' + token, - 'X-Version': '1', - 'Content-Type': 'application/json', - 'Accept': 'application/json' - } - }) - .post('/rest/message', { arg: true }) - .reply(200, { data: true }); - - var api = new Rest(token); - api._invoke('/rest/message', { arg: true }, 'POST', function (content, err) { - assert(err == null); - assert(content); - done(); - }); - }); - - }); - - describe("sendMessage", function () { - - it("should handle mixed responses correctly", function (done) { - - nock('http://api.clickatell.com') - .post('/rest/message', { mo: 1, callback: 7, to: ["0000", "0001"], text: "message" }) - .reply( - 200, - { - data: - { - message: [ - { - apiMessageId: false, - to: "0000", - error: { - description: "Some error", - code: 301 - } - }, - { - apiMessageId: 12345, - to: "0001", - error: false - } - ] - } - } - ); - - var api = new Rest(token); - api.sendMessage(["0000", "0001"], "message", {}, function (err, content) { - assert(err == null); - assert(!content[0].id); - assert.equal("Some error", content[0].error); - assert.equal(301, content[0].code); - assert.equal(12345, content[1].id); - assert.equal("0001", content[1].destination); - done(); - }); - }); - }); - - - describe("getBalance", function () { - - it("should return an error if the call was incorrectly formatted", function (done) { - - nock('http://api.clickatell.com') - .get('/rest/account/balance') - .reply( - 400, - { - error: - { - description: "Some error", - code: 301 - } - } - ); - - var api = new Rest(token); - api.getBalance(function (err, content) { - assert(err instanceof Error); - assert.equal(301, err.code); - assert.equal("Some error", err.message); - done(); - }); - }); - - it("should return the balance from the 'balance' field", function (done) { - - nock('http://api.clickatell.com') - .get('/rest/account/balance') - .reply( - 200, - { - data: - { - balance: 500 - } - } - ); - - var api = new Rest(token); - api.getBalance(function (err, content) { - assert(err == null); - assert.equal(500, content.balance); - done(); - }); - }); - - }); - - describe("stopMessage", function () { - - it("should return an error if the call failed", function (done) { - nock('http://api.clickatell.com') - .delete('/rest/message/12345') - .reply( - 400, - { - error: - { - description: "Some error", - code: 301 - } - } - ); - - var api = new Rest(token); - api.stopMessage("12345", function (err, content) { - assert(err instanceof Error); - assert.equal(301, err.code); - assert.equal("Some error", err.message); - done(); - }); - }); - - it("should return the message details if call was succesful", function (done) { - - nock('http://api.clickatell.com') - .delete('/rest/message/12345') - .reply( - 200, - { - data: - { - apiMessageId: "12345", - messageStatus: "004" - } - } - ); - - var api = new Rest(token); - api.stopMessage("12345", function (err, content) { - assert(err == null); - assert.equal("12345", content.id); - assert.equal("004", content.status); - assert.equal(diagnostic["004"], content.description); - done(); - }); - }); - - }); - - describe("queryMessage", function () { - - it("should forward the call to getMessageCharge", function (done) { - var api = new Rest(token); - - api.getMessageCharge = function (apiMsgId, callback) { - callback.apply(this, [null, true]); - }; - - api.queryMessage("123456", function (err, content) { - assert(content); - done(); - }); - }); - - }); - - describe("routeCoverage", function () { - - it("should return an error incase of a failed request", function (done) { - - nock('http://api.clickatell.com') - .get('/rest/coverage/12345') - .reply( - 400, - { - error: - { - description: "Some error", - code: 301 - } - } - ); - - var api = new Rest(token); - api.routeCoverage("12345", function (err, content) { - assert(err instanceof Error); - assert.equal(301, err.code); - assert.equal("Some error", err.message); - done(); - }); - - }); - - it("should return a routable status if successful", function (done) { - - nock('http://api.clickatell.com') - .get('/rest/coverage/12345') - .reply( - 200, - { - data: - { - routable: true, - destination: "12345", - minimumCharge: 1 - } - } - ); - - var api = new Rest(token); - api.routeCoverage("12345", function (err, content) { - assert.equal(true, content.routable); - assert.equal(1, content.charge); - done(); - }); - }); - }); - - describe("getMessageCharge", function () { - - it("should return an error if the request fails", function (done) { - - nock('http://api.clickatell.com') - .get('/rest/message/12345') - .reply( - 400, - { - error: - { - description: "Some error", - code: 301 - } - } - ); - - var api = new Rest(token); - api.getMessageCharge("12345", function (err, content) { - assert(err instanceof Error); - assert.equal(301, err.code); - assert.equal("Some error", err.message); - done(); - }); - }); - - it("should return the correct fields upon success", function (done) { - - nock('http://api.clickatell.com') - .get('/rest/message/12345') - .reply( - 200, - { - data: - { - apiMessageId: "12345", - messageStatus: "004", - charge: 1 - } - } - ); - - var api = new Rest(token); - api.getMessageCharge("12345", function (err, content) { - assert.equal("12345", content.id); - assert.equal("004", content.status); - assert.equal(diagnostic["004"], content.description); - assert.equal(1, content.charge); - done(); - }); - }); - - }); - -}); \ No newline at end of file diff --git a/test/decorator.test.js b/test/decorator.test.js deleted file mode 100644 index 28110eb..0000000 --- a/test/decorator.test.js +++ /dev/null @@ -1,66 +0,0 @@ -var assert = require("assert"); -var decoder = require("./../src/decoder"); - -describe("decoder.js", function () { - describe("unwrapLegacy", function () { - - it("should throw an error if a single response fails.", function () { - var data = "ERR: 301, Some random error."; - assert.throws(function () { decoder.unwrapLegacy(data); }, Error); - }); - - it("should return an array even if it contains an error.", function () { - var data = "ERR: 301, Some random error.\nID: 123456 To: 0000000000"; - var result = decoder.unwrapLegacy(data); - - assert.equal(result[0]['code'], 301); - assert.equal(result[0]['error'], "Some random error."); - }); - - it("should unwrap multiple values.", function () { - var data = "ID: 123456 To: 123\nID:123 To:456"; - var result = decoder.unwrapLegacy(data); - - assert.equal(result[0]['ID'], 123456); - assert.equal(result[0]['To'], 123); - assert.equal(result[1]['ID'], 123); - assert.equal(result[1]['To'], 456); - }); - - it("should return a single value not as an array.", function () { - var data = "ID: 123456 To:123"; - var result = decoder.unwrapLegacy(data); - - assert.equal(result['ID'], 123456); - assert.equal(result['To'], 123); - }); - }); - - describe("decodeRest", function () { - - it("should throw an error if one exists.", function () { - - var data = JSON.stringify({ - error: { - description: "Some error", - code: 100 - } - }); - - assert.throws(function () { decoder.decodeRest(data); }, Error, 'Some error'); - }); - - it("should return the 'data' parameter in a response.", function () { - - var data = JSON.stringify({ - data: { - balance: 100 - } - }); - - var result = decoder.decodeRest(data); - - assert.equal(100, result.balance); - }) - }); -}); \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js deleted file mode 100644 index 6a76f7e..0000000 --- a/test/index.test.js +++ /dev/null @@ -1,23 +0,0 @@ -var assert = require("assert"); -var index = require("./../src/index"); -var Http = require('./../src/api/http'); -var Rest = require('./../src/api/rest'); - -describe("index.js", function () { - - describe("http", function () { - - it("should return an instance of an HTTP API connection.", function () { - var http = index.http('user', 'pass', 123456); - assert(http instanceof Http, 'Object not of type Http'); - }); - }); - - describe("rest", function () { - - it("should return an instance of an REST API connection.", function () { - var rest = index.rest(123456); - assert(rest instanceof Rest, 'Object not of type Rest'); - }); - }); -}); \ No newline at end of file diff --git a/test/transport.test.js b/test/transport.test.js deleted file mode 100644 index 9a42c1b..0000000 --- a/test/transport.test.js +++ /dev/null @@ -1,31 +0,0 @@ -var assert = require("assert"); -var Transport = require("./../src/transport"); -var nock = require("nock"); - -describe("transport.js", function () { - - describe("call", function () { - - it("should turn arguments into a query string.", function (done) { - - nock('http://api.clickatell.com').get('/index?user=1234').reply(200, 'content'); - - var transport = new Transport; - transport.call('/index', { user: 1234 }, {}, function (content, err) { - assert.equal('content', content); - done(); - }); - }); - - it("should handle HTTP errors on request.", function (done) { - - var transport = new Transport; - - transport.call('/', {}, { hostname: "www.notfound.error" }, function (content, err) { - assert(content == null); - assert(err instanceof Error); - done(); - }); - }); - }); -}); \ No newline at end of file From a107e6d2466a848b00c4b26babdb09193f99ceae Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Mon, 2 Oct 2017 10:06:23 +0200 Subject: [PATCH 02/19] git ignore files --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Thu, 5 Oct 2017 11:33:27 +0200 Subject: [PATCH 03/19] updated readme and package.json --- README.md | 38 ++++- callback.js | 43 ++++++ package-lock.json | 348 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 10 +- test.js | 7 +- 5 files changed, 432 insertions(+), 14 deletions(-) create mode 100644 callback.js diff --git a/README.md b/README.md index d7c9a8a..9ebdcbf 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Add the message you want to send, and add the cell number you're sending to, and ``` clickatell.rest("Hello testing message", ["27XXXXX-NUMBER","27XXXXX-NUMBER"], "APIKEY-HERE"); + +// Or use http method below clickatell.http("Hello testing message", ["27XXXXX-NUMBER","27XXXXX-NUMBER"], "APIKEY-HERE"); ``` @@ -16,4 +18,38 @@ Simply trigger the sending by running "node test.js" in your terminal. ``` node test.js -``` \ No newline at end of file +``` + +### Handeling API callbacks + +In the callback.js file you will find a code example that simply creates a NodeJS server and then listens on port 80. + +It has a express post method pointing to yourdomain.com/sms which you will use on your platform api to send the callback +posts to be able to read callback infromation. + +Below is data that you will get back on the callback. + +DELIVERED_TO_GATEWAY : +* integrationName +* messageId +* requestId +* clientMessageId +* to +* from +* statusCode +* status +* statusDescription +* timestamp + +RECEIVED_BY_RECIPIENT : +* integrationName +* messageId +* requestId +* clientMessageId +* to +* from +* statusCode +* status +* statusDescription +* timestamp + diff --git a/callback.js b/callback.js new file mode 100644 index 0000000..ea280f4 --- /dev/null +++ b/callback.js @@ -0,0 +1,43 @@ +const express = require('express') +const bodyParser = require('body-parser') + + +const app = express() + + +const http = require('http') +const port = 80 + +const server = http.createServer(app) + +app.use( bodyParser.json() ); // to support JSON-encoded bodies +app.use(bodyParser.urlencoded({ // to support URL-encoded bodies + extended: true +})); + +app.use(express.json()); // to support JSON-encoded bodies +app.use(express.urlencoded()); // to support URL-encoded bodies + +server.listen(port, (err) => { + if (err) { + return console.log('something bad happened', err) + } + + console.log(`server is listening on ${port}`); + + + app.get('/', function (req, res) { + res.send('This is an example route.') + }) + + app.post('/sms', function (req, res) { + const body = req.body + console.log(body); + + + res.set('Content-Type', 'text/plain') + res.send(`You sent: ${body}`) + }) + + +}) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9cd59ff..3124c2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,18 @@ { - "name": "simple-api-interaction", - "requires": true, + "name": "clickatell-platform", + "version": "2.0.0", "lockfileVersion": 1, + "requires": true, "dependencies": { + "accepts": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz", + "integrity": "sha1-hiRnWMfdbSGmR0/whKR0DsBesh8=", + "requires": { + "mime-types": "2.1.17", + "negotiator": "0.6.1" + } + }, "ajv": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.8.tgz", @@ -12,10 +22,10 @@ "json-stable-stringify": "1.0.1" } }, - "angular": { - "version": "1.6.5", - "resolved": "https://registry.npmjs.org/angular/-/angular-1.6.5.tgz", - "integrity": "sha1-N/eI7r7Fzi4/oCsXu8sqIxV2oNY=" + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, "asn1": { "version": "0.2.3", @@ -51,6 +61,30 @@ "tweetnacl": "0.14.5" } }, + "body-parser": { + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", + "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", + "requires": { + "bytes": "3.0.0", + "content-type": "1.0.4", + "debug": "2.6.9", + "depd": "1.1.1", + "http-errors": "1.6.2", + "iconv-lite": "0.4.19", + "on-finished": "2.3.0", + "qs": "6.5.1", + "raw-body": "2.3.2", + "type-is": "1.6.15" + }, + "dependencies": { + "qs": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + } + } + }, "boom": { "version": "2.10.1", "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", @@ -59,6 +93,11 @@ "hoek": "2.16.3" } }, + "bytes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", + "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" + }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -77,6 +116,26 @@ "delayed-stream": "1.0.0" } }, + "content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" + }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -105,11 +164,29 @@ } } }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, "ecc-jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", @@ -119,6 +196,70 @@ "jsbn": "0.1.1" } }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "encodeurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", + "integrity": "sha1-eePVhlU0aQn+bw9Fpd5oEDspTSA=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + }, + "express": { + "version": "4.16.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.16.1.tgz", + "integrity": "sha512-STB7LZ4N0L+81FJHGla2oboUHTk4PaN1RsOkoRh9OSeEKylvF5hwKYVX1xCLFaCT7MD0BNG/gX2WFMLqY6EMBw==", + "requires": { + "accepts": "1.3.4", + "array-flatten": "1.1.1", + "body-parser": "1.18.2", + "content-disposition": "0.5.2", + "content-type": "1.0.4", + "cookie": "0.3.1", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "1.1.1", + "encodeurl": "1.0.1", + "escape-html": "1.0.3", + "etag": "1.8.1", + "finalhandler": "1.1.0", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "1.1.2", + "on-finished": "2.3.0", + "parseurl": "1.3.2", + "path-to-regexp": "0.1.7", + "proxy-addr": "2.0.2", + "qs": "6.5.1", + "range-parser": "1.2.0", + "safe-buffer": "5.1.1", + "send": "0.16.1", + "serve-static": "1.13.1", + "setprototypeof": "1.1.0", + "statuses": "1.3.1", + "type-is": "1.6.15", + "utils-merge": "1.0.1", + "vary": "1.1.2" + }, + "dependencies": { + "qs": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + } + } + }, "extend": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", @@ -129,6 +270,20 @@ "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" }, + "finalhandler": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.0.tgz", + "integrity": "sha1-zgtoVbRYU+eRsvzGgARtiCU91/U=", + "requires": { + "debug": "2.6.9", + "encodeurl": "1.0.1", + "escape-html": "1.0.3", + "on-finished": "2.3.0", + "parseurl": "1.3.2", + "statuses": "1.3.1", + "unpipe": "1.0.0" + } + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -144,6 +299,16 @@ "mime-types": "2.1.17" } }, + "forwarded": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -189,6 +354,24 @@ "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" }, + "http-errors": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", + "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", + "requires": { + "depd": "1.1.1", + "inherits": "2.0.3", + "setprototypeof": "1.0.3", + "statuses": "1.3.1" + }, + "dependencies": { + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" + } + } + }, "http-signature": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz", @@ -199,6 +382,21 @@ "sshpk": "1.13.1" } }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "ipaddr.js": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.5.2.tgz", + "integrity": "sha1-1LUFvemUaYfM8PxY2QEP+WB+P6A=" + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -256,6 +454,26 @@ } } }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, + "mime": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", + "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" + }, "mime-db": { "version": "1.30.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", @@ -269,16 +487,53 @@ "mime-db": "1.30.0" } }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" + }, "oauth-sign": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "requires": { + "ee-first": "1.1.1" + } + }, + "parseurl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, "performance-now": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-0.2.0.tgz", "integrity": "sha1-M+8wxcd9TqIcWlOGnZG1bY8lVeU=" }, + "proxy-addr": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.2.tgz", + "integrity": "sha1-ZXFQT0e7mI7IGAJT+F3X4UlSvew=", + "requires": { + "forwarded": "0.1.2", + "ipaddr.js": "1.5.2" + } + }, "punycode": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", @@ -289,6 +544,22 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", "integrity": "sha1-E+JtKK1rD/qpExLNO/cI7TUecjM=" }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" + }, + "raw-body": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", + "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", + "requires": { + "bytes": "3.0.0", + "http-errors": "1.6.2", + "iconv-lite": "0.4.19", + "unpipe": "1.0.0" + } + }, "request": { "version": "2.81.0", "resolved": "https://registry.npmjs.org/request/-/request-2.81.0.tgz", @@ -323,6 +594,42 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, + "send": { + "version": "0.16.1", + "resolved": "https://registry.npmjs.org/send/-/send-0.16.1.tgz", + "integrity": "sha512-ElCLJdJIKPk6ux/Hocwhk7NFHpI3pVm/IZOYWqUmoxcgeyM+MpxHHKhb8QmlJDX1pU6WrgaHBkVNm73Sv7uc2A==", + "requires": { + "debug": "2.6.9", + "depd": "1.1.1", + "destroy": "1.0.4", + "encodeurl": "1.0.1", + "escape-html": "1.0.3", + "etag": "1.8.1", + "fresh": "0.5.2", + "http-errors": "1.6.2", + "mime": "1.4.1", + "ms": "2.0.0", + "on-finished": "2.3.0", + "range-parser": "1.2.0", + "statuses": "1.3.1" + } + }, + "serve-static": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.1.tgz", + "integrity": "sha512-hSMUZrsPa/I09VYFJwa627JJkNs0NrfL1Uzuup+GqHfToR2KcsXFymXSV90hoyw3M+msjFuQly+YzIH/q0MGlQ==", + "requires": { + "encodeurl": "1.0.1", + "escape-html": "1.0.3", + "parseurl": "1.3.2", + "send": "0.16.1" + } + }, + "setprototypeof": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", + "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" + }, "sntp": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", @@ -353,6 +660,11 @@ } } }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", @@ -380,11 +692,35 @@ "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", "optional": true }, + "type-is": { + "version": "1.6.15", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", + "integrity": "sha1-yrEPtJCeRByChC6v4a1kbIGARBA=", + "requires": { + "media-typer": "0.3.0", + "mime-types": "2.1.17" + } + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, + "utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" + }, "uuid": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + }, "verror": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", diff --git a/package.json b/package.json index d59b691..e314f18 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,18 @@ { "name": "clickatell-platform", - "author": "Morne Zeelie ", + "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.0", + "version": "2.0.1", "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/holla22/clickatell-platform.git" + "url": "https://github.com/clickatell/clickatell-node.git" }, - "bugs": "https://github.com/holla22/clickatell-platform/issues", + "bugs": "https://github.com/clickatell/clickatell-node/issues", "dependencies": { + "express": "^4.16.1", + "body-parser": "^1.18.2", "request": "^2.79.0" } } diff --git a/test.js b/test.js index d4c0ecb..c42a83a 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,5 @@ -var clickatell = require('./index.js'); +var clickatell = require("./index.js"); -///clickatell.rest("Hello testing message", ["27XXXXX-NUMBER"], ""); -clickatell.http("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); +clickatell.rest("Hello testing message", ["27XXXXXNUMBER"], "APIKEY-HERE"); + +//clickatell.http("Hello testing message", ["27XXXXXNUMBER"], "APIKEY-HERE"); From ceb208e6f392db9dc269d7c7c4be5a1756974757 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 11:36:10 +0200 Subject: [PATCH 04/19] git ignore updated --- .gitignore | 3 +- package-lock.json | 742 ---------------------------------------------- package.json | 2 +- 3 files changed, 3 insertions(+), 744 deletions(-) delete mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index 2b49dfc..aefca1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ stage.js -.DS_Store \ No newline at end of file +.DS_Store +package-lock.json \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 3124c2a..0000000 --- a/package-lock.json +++ /dev/null @@ -1,742 +0,0 @@ -{ - "name": "clickatell-platform", - "version": "2.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "accepts": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz", - "integrity": "sha1-hiRnWMfdbSGmR0/whKR0DsBesh8=", - "requires": { - "mime-types": "2.1.17", - "negotiator": "0.6.1" - } - }, - "ajv": { - "version": "4.11.8", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.8.tgz", - "integrity": "sha1-gv+wKynmYq5TvcIK8VlHcGc5xTY=", - "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" - } - }, - "array-flatten": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" - }, - "asn1": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", - "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" - }, - "assert-plus": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.2.0.tgz", - "integrity": "sha1-104bh+ev/A24qttwIfP+SBAasjQ=" - }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" - }, - "aws-sign2": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz", - "integrity": "sha1-FDQt0428yU0OW4fXY81jYSwOeU8=" - }, - "aws4": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", - "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=" - }, - "bcrypt-pbkdf": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", - "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", - "optional": true, - "requires": { - "tweetnacl": "0.14.5" - } - }, - "body-parser": { - "version": "1.18.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", - "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", - "requires": { - "bytes": "3.0.0", - "content-type": "1.0.4", - "debug": "2.6.9", - "depd": "1.1.1", - "http-errors": "1.6.2", - "iconv-lite": "0.4.19", - "on-finished": "2.3.0", - "qs": "6.5.1", - "raw-body": "2.3.2", - "type-is": "1.6.15" - }, - "dependencies": { - "qs": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", - "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" - } - } - }, - "boom": { - "version": "2.10.1", - "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", - "integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=", - "requires": { - "hoek": "2.16.3" - } - }, - "bytes": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", - "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" - }, - "caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" - }, - "co": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", - "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" - }, - "combined-stream": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", - "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=", - "requires": { - "delayed-stream": "1.0.0" - } - }, - "content-disposition": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", - "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" - }, - "content-type": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", - "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" - }, - "cookie": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", - "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" - }, - "cookie-signature": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" - }, - "cryptiles": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", - "integrity": "sha1-O9/s3GCBR8HGcgL6KR59ylnqo7g=", - "requires": { - "boom": "2.10.1" - } - }, - "dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } - } - }, - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" - }, - "depd": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", - "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" - }, - "destroy": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" - }, - "ecc-jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", - "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "ee-first": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" - }, - "encodeurl": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", - "integrity": "sha1-eePVhlU0aQn+bw9Fpd5oEDspTSA=" - }, - "escape-html": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" - }, - "etag": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" - }, - "express": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/express/-/express-4.16.1.tgz", - "integrity": "sha512-STB7LZ4N0L+81FJHGla2oboUHTk4PaN1RsOkoRh9OSeEKylvF5hwKYVX1xCLFaCT7MD0BNG/gX2WFMLqY6EMBw==", - "requires": { - "accepts": "1.3.4", - "array-flatten": "1.1.1", - "body-parser": "1.18.2", - "content-disposition": "0.5.2", - "content-type": "1.0.4", - "cookie": "0.3.1", - "cookie-signature": "1.0.6", - "debug": "2.6.9", - "depd": "1.1.1", - "encodeurl": "1.0.1", - "escape-html": "1.0.3", - "etag": "1.8.1", - "finalhandler": "1.1.0", - "fresh": "0.5.2", - "merge-descriptors": "1.0.1", - "methods": "1.1.2", - "on-finished": "2.3.0", - "parseurl": "1.3.2", - "path-to-regexp": "0.1.7", - "proxy-addr": "2.0.2", - "qs": "6.5.1", - "range-parser": "1.2.0", - "safe-buffer": "5.1.1", - "send": "0.16.1", - "serve-static": "1.13.1", - "setprototypeof": "1.1.0", - "statuses": "1.3.1", - "type-is": "1.6.15", - "utils-merge": "1.0.1", - "vary": "1.1.2" - }, - "dependencies": { - "qs": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", - "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" - } - } - }, - "extend": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", - "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=" - }, - "extsprintf": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" - }, - "finalhandler": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.0.tgz", - "integrity": "sha1-zgtoVbRYU+eRsvzGgARtiCU91/U=", - "requires": { - "debug": "2.6.9", - "encodeurl": "1.0.1", - "escape-html": "1.0.3", - "on-finished": "2.3.0", - "parseurl": "1.3.2", - "statuses": "1.3.1", - "unpipe": "1.0.0" - } - }, - "forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" - }, - "form-data": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.1.4.tgz", - "integrity": "sha1-M8GDrPGTJ27KqYFDpp6Uv+4XUNE=", - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.5", - "mime-types": "2.1.17" - } - }, - "forwarded": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", - "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" - }, - "fresh": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" - }, - "getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } - } - }, - "har-schema": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-1.0.5.tgz", - "integrity": "sha1-0mMTX0MwfALGAq/I/pWXDAFRNp4=" - }, - "har-validator": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-4.2.1.tgz", - "integrity": "sha1-M0gdDxu/9gDdID11gSpqX7oALio=", - "requires": { - "ajv": "4.11.8", - "har-schema": "1.0.5" - } - }, - "hawk": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz", - "integrity": "sha1-B4REvXwWQLD+VA0sm3PVlnjo4cQ=", - "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" - } - }, - "hoek": { - "version": "2.16.3", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" - }, - "http-errors": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", - "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", - "requires": { - "depd": "1.1.1", - "inherits": "2.0.3", - "setprototypeof": "1.0.3", - "statuses": "1.3.1" - }, - "dependencies": { - "setprototypeof": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", - "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" - } - } - }, - "http-signature": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz", - "integrity": "sha1-33LiZwZs0Kxn+3at+OE0qPvPkb8=", - "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.1", - "sshpk": "1.13.1" - } - }, - "iconv-lite": { - "version": "0.4.19", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", - "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "ipaddr.js": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.5.2.tgz", - "integrity": "sha1-1LUFvemUaYfM8PxY2QEP+WB+P6A=" - }, - "is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" - }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" - }, - "jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "optional": true - }, - "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" - }, - "json-stable-stringify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", - "integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=", - "requires": { - "jsonify": "0.0.0" - } - }, - "json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" - }, - "jsonify": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", - "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=" - }, - "jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.3.0", - "json-schema": "0.2.3", - "verror": "1.10.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } - } - }, - "media-typer": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" - }, - "merge-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" - }, - "methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" - }, - "mime": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", - "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" - }, - "mime-db": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", - "integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE=" - }, - "mime-types": { - "version": "2.1.17", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", - "integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=", - "requires": { - "mime-db": "1.30.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, - "negotiator": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", - "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" - }, - "oauth-sign": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", - "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" - }, - "on-finished": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", - "requires": { - "ee-first": "1.1.1" - } - }, - "parseurl": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", - "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" - }, - "path-to-regexp": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" - }, - "performance-now": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-0.2.0.tgz", - "integrity": "sha1-M+8wxcd9TqIcWlOGnZG1bY8lVeU=" - }, - "proxy-addr": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.2.tgz", - "integrity": "sha1-ZXFQT0e7mI7IGAJT+F3X4UlSvew=", - "requires": { - "forwarded": "0.1.2", - "ipaddr.js": "1.5.2" - } - }, - "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" - }, - "qs": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", - "integrity": "sha1-E+JtKK1rD/qpExLNO/cI7TUecjM=" - }, - "range-parser": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", - "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" - }, - "raw-body": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", - "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", - "requires": { - "bytes": "3.0.0", - "http-errors": "1.6.2", - "iconv-lite": "0.4.19", - "unpipe": "1.0.0" - } - }, - "request": { - "version": "2.81.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.81.0.tgz", - "integrity": "sha1-xpKJRqDgbF+Nb4qTM0af/aRimKA=", - "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.12.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "4.2.1", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.17", - "oauth-sign": "0.8.2", - "performance-now": "0.2.0", - "qs": "6.4.0", - "safe-buffer": "5.1.1", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.6.0", - "uuid": "3.1.0" - } - }, - "safe-buffer": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" - }, - "send": { - "version": "0.16.1", - "resolved": "https://registry.npmjs.org/send/-/send-0.16.1.tgz", - "integrity": "sha512-ElCLJdJIKPk6ux/Hocwhk7NFHpI3pVm/IZOYWqUmoxcgeyM+MpxHHKhb8QmlJDX1pU6WrgaHBkVNm73Sv7uc2A==", - "requires": { - "debug": "2.6.9", - "depd": "1.1.1", - "destroy": "1.0.4", - "encodeurl": "1.0.1", - "escape-html": "1.0.3", - "etag": "1.8.1", - "fresh": "0.5.2", - "http-errors": "1.6.2", - "mime": "1.4.1", - "ms": "2.0.0", - "on-finished": "2.3.0", - "range-parser": "1.2.0", - "statuses": "1.3.1" - } - }, - "serve-static": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.1.tgz", - "integrity": "sha512-hSMUZrsPa/I09VYFJwa627JJkNs0NrfL1Uzuup+GqHfToR2KcsXFymXSV90hoyw3M+msjFuQly+YzIH/q0MGlQ==", - "requires": { - "encodeurl": "1.0.1", - "escape-html": "1.0.3", - "parseurl": "1.3.2", - "send": "0.16.1" - } - }, - "setprototypeof": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", - "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" - }, - "sntp": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", - "integrity": "sha1-ZUEYTMkK7qbG57NeJlkIJEPGYZg=", - "requires": { - "hoek": "2.16.3" - } - }, - "sshpk": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", - "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", - "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } - } - }, - "statuses": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", - "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" - }, - "stringstream": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", - "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=" - }, - "tough-cookie": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.2.tgz", - "integrity": "sha1-8IH3bkyFcg5sN6X6ztc3FQ2EByo=", - "requires": { - "punycode": "1.4.1" - } - }, - "tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", - "requires": { - "safe-buffer": "5.1.1" - } - }, - "tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", - "optional": true - }, - "type-is": { - "version": "1.6.15", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", - "integrity": "sha1-yrEPtJCeRByChC6v4a1kbIGARBA=", - "requires": { - "media-typer": "0.3.0", - "mime-types": "2.1.17" - } - }, - "unpipe": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" - }, - "utils-merge": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" - }, - "uuid": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", - "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" - }, - "vary": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" - }, - "verror": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", - "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", - "requires": { - "assert-plus": "1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "1.3.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } - } - } - } -} diff --git a/package.json b/package.json index e314f18..966b01a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.1", + "version": "2.0.2", "license": "MIT", "repository": { "type": "git", From e44448efef42854aec8652746da48db574efca36 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 11:36:38 +0200 Subject: [PATCH 05/19] 2.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 966b01a..605be27 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.2", + "version": "2.0.3", "license": "MIT", "repository": { "type": "git", From 0d74582c6de0c30edc9cdf870cf0f57a1adb00e4 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 11:40:15 +0200 Subject: [PATCH 06/19] spelling fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ebdcbf..c5969f3 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Simply trigger the sending by running "node test.js" in your terminal. node test.js ``` -### Handeling API callbacks +### Handling API callbacks In the callback.js file you will find a code example that simply creates a NodeJS server and then listens on port 80. From 9295b66a741be1c45cd9324493691c7576fdeda7 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 11:41:21 +0200 Subject: [PATCH 07/19] package.json updated --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 605be27..a8ac38d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.3", + "version": "2.0.4", "license": "MIT", "repository": { "type": "git", From 98e426a822f1bc2d0a26c802eb9410e5b7c8874a Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 11:42:04 +0200 Subject: [PATCH 08/19] package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a8ac38d..920f71e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.4", + "version": "2.0.5", "license": "MIT", "repository": { "type": "git", From c20d51719921cc21b952a483b147e6ab32f7b4db Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 15:54:03 +0200 Subject: [PATCH 09/19] code changes and readme update --- README.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++++----- api/http.js | 2 +- api/rest.js | 1 - callback.js | 3 ++- index.js | 13 +++++++--- test.js | 4 +-- 6 files changed, 80 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c5969f3..e0aceb5 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,21 @@ Simply require the file index.js file and use one of the methods to send. Add the message you want to send, and add the cell number you're sending to, and the API key. ``` -clickatell.rest("Hello testing message", ["27XXXXX-NUMBER","27XXXXX-NUMBER"], "APIKEY-HERE"); +var clickatell = require("clickatell-platform"); + +///clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); + +clickatell.sendMessageHttp("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); + -// Or use http method below -clickatell.http("Hello testing message", ["27XXXXX-NUMBER","27XXXXX-NUMBER"], "APIKEY-HERE"); ``` ### Run the code -Simply trigger the sending by running "node test.js" in your terminal. +Simply create a file called test.js and add the code above. +Then trigger the sending by running "node test.js" in your terminal. + +Remember to add the number you are sending to and your API Key to be able to send successfully. ``` node test.js @@ -22,12 +28,65 @@ node test.js ### Handling API callbacks -In the callback.js file you will find a code example that simply creates a NodeJS server and then listens on port 80. +Create a file called server.js and paste the code below into it and save it. It has a express post method pointing to yourdomain.com/sms which you will use on your platform api to send the callback -posts to be able to read callback infromation. +posts to, to be able to read callback infromation. + +Simply run the code by typing "node server.js" and it will start to run on port 80, make sure it works by just going to yourdomain.com + +``` +node server.js" +``` + +``` +const express = require('express') +const bodyParser = require('body-parser') + + +const app = express() + + +const http = require('http') +const port = 80 + +const server = http.createServer(app) + + +app.use(bodyParser.urlencoded({ // to support URL-encoded bodies + extended: true +})); +app.use( bodyParser.json() ); // to support JSON-encoded bodies + +app.use(express.json()); // to support JSON-encoded bodies +app.use(express.urlencoded()); // to support URL-encoded bodies + +server.listen(port, (err) => { + if (err) { + return console.log('something bad happened', err) + } + + console.log(`server is listening on ${port}`); + + + app.get('/', function (req, res) { + res.send('It's working') + }) + + app.post('/sms', function (req, res) { + const body = req.body + console.log(body); + + + res.set('Content-Type', 'text/plain') + res.send(`You sent: ${body}`) + }) + + +}) +``` -Below is data that you will get back on the callback. +Below is data that you will get back on the callback, once you send a sms. DELIVERED_TO_GATEWAY : * integrationName diff --git a/api/http.js b/api/http.js index 4e6994f..b28d071 100644 --- a/api/http.js +++ b/api/http.js @@ -7,7 +7,6 @@ function Http(content, to, apiKey) { this.to = to; // phone number this.apiKey = apiKey; - this.sendMessage(this.content,this.to,this.apiKey); } // class methods Http.prototype.sendMessage = function(content, to, apiKey) { @@ -28,5 +27,6 @@ Http.prototype.sendMessage = function(content, to, apiKey) { }); }; + // export the class module.exports = Http; \ No newline at end of file diff --git a/api/rest.js b/api/rest.js index cfac917..c1de4f6 100644 --- a/api/rest.js +++ b/api/rest.js @@ -7,7 +7,6 @@ function Rest(content, to, apiKey) { this.to = to; // phone number this.apiKey = apiKey; - this.sendMessage(this.content,this.to,this.apiKey); } // class methods Rest.prototype.sendMessage = function(content, to, apiKey) { diff --git a/callback.js b/callback.js index ea280f4..a3021b5 100644 --- a/callback.js +++ b/callback.js @@ -10,10 +10,11 @@ const port = 80 const server = http.createServer(app) -app.use( bodyParser.json() ); // to support JSON-encoded bodies + app.use(bodyParser.urlencoded({ // to support URL-encoded bodies extended: true })); +app.use( bodyParser.json() ); // to support JSON-encoded bodies app.use(express.json()); // to support JSON-encoded bodies app.use(express.urlencoded()); // to support URL-encoded bodies diff --git a/index.js b/index.js index 0d44d2d..4c020b8 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,15 @@ var Http = require("./api/http"); var Rest = require('./api/rest'); module.exports = { - http: function (content, to, apiKey) { - return new Http(content, to, apiKey); + sendMessageHttp: function (content, to, apiKey) { + var http = new Http(); + var sendMessageHttp = http.sendMessage(content, to, apiKey); + return sendMessageHttp; }, - rest: function (content, to, apiKey) { - return new Rest(content, to, apiKey); + sendMessageRest: function (content, to, apiKey) { + var rest = new Rest(); + var sendMessageRest = rest.sendMessage(content, to, apiKey) + return sendMessageRest; } + // more methods coming } \ No newline at end of file diff --git a/test.js b/test.js index c42a83a..6e7646b 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ var clickatell = require("./index.js"); -clickatell.rest("Hello testing message", ["27XXXXXNUMBER"], "APIKEY-HERE"); +///clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); +clickatell.sendMessageHttp("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); -//clickatell.http("Hello testing message", ["27XXXXXNUMBER"], "APIKEY-HERE"); From 4306abaa5df93dc78e763c53c1ca538570584166 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 15:54:43 +0200 Subject: [PATCH 10/19] package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 920f71e..4a3594a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.5", + "version": "2.0.6", "license": "MIT", "repository": { "type": "git", From 8e6baf011e44345416b4f5c0b0eb72697445163d Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 16:01:48 +0200 Subject: [PATCH 11/19] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0aceb5..e6f2adf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Inside the test.js file is an example implementation of the REST and HTTP API. -Simply require the file index.js file and use one of the methods to send. +Simply require the file clickatell-platform package and use one of the methods to send. Add the message you want to send, and add the cell number you're sending to, and the API key. ``` From ffef7dff6488fe79099bbefa3ee19f89d14f75d9 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 14:01:55 +0000 Subject: [PATCH 12/19] 2.0.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a3594a..3d66909 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.6", + "version": "2.0.7", "license": "MIT", "repository": { "type": "git", From 664efd3bb1ec25395e42d77091119137c0e7258d Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 16:02:49 +0200 Subject: [PATCH 13/19] 2.0.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3d66909..4287be4 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.7", + "version": "2.0.8", "license": "MIT", "repository": { "type": "git", From a6e6a70251a0ad87cc8fcf8b67ad805c3c86979e Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 16:05:08 +0200 Subject: [PATCH 14/19] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6f2adf..4ba78a3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Inside the test.js file is an example implementation of the REST and HTTP API. -Simply require the file clickatell-platform package and use one of the methods to send. +Simply require the clickatell-platform package and use one of the methods to send. Add the message you want to send, and add the cell number you're sending to, and the API key. ``` From 86bea0868c6a02e5744141a125e9f40c0f0fce8e Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 5 Oct 2017 14:05:19 +0000 Subject: [PATCH 15/19] 2.0.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4287be4..46ee545 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.8", + "version": "2.0.9", "license": "MIT", "repository": { "type": "git", From 53aa598eaf4151c8d87aee85978f718ee0009bd4 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 19 Oct 2017 11:07:26 +0200 Subject: [PATCH 16/19] Urlencode http message --- api/http.js | 2 +- test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/http.js b/api/http.js index b28d071..8cfc64c 100644 --- a/api/http.js +++ b/api/http.js @@ -12,7 +12,7 @@ function Http(content, to, apiKey) { Http.prototype.sendMessage = function(content, to, apiKey) { // replace spaces in message with plus sign to work correctly with http call - var contentReplaced = content.split(' ').join('+'); + var contentReplaced = encodeURIComponent(content.split(' ').join('+')); var options = { method: 'GET', diff --git a/test.js b/test.js index 6e7646b..b44900a 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ var clickatell = require("./index.js"); -///clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); +//clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); clickatell.sendMessageHttp("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); From f795f495fbbf96b98b6423582845e80d4783d7b1 Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Thu, 19 Oct 2017 13:53:14 +0200 Subject: [PATCH 17/19] made fixes to be able to send to more than one number for REST --- api/rest.js | 12 +++++++----- test.js | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api/rest.js b/api/rest.js index c1de4f6..a0f5ad7 100644 --- a/api/rest.js +++ b/api/rest.js @@ -11,6 +11,8 @@ function Rest(content, to, apiKey) { // class methods Rest.prototype.sendMessage = function(content, to, apiKey) { // set options array + content = JSON.stringify(content); + to = JSON.stringify(to); var options = { method: 'POST', url:'https://platform.clickatell.com/messages', @@ -20,14 +22,14 @@ Rest.prototype.sendMessage = function(content, to, apiKey) { 'Accept': 'application/json', 'Authorization': apiKey }, - form: {'content': content, 'to': to.join(",")} + body: '{"content": ' + content + ', "to": ' + to +'}' } + // send the request Request(options, function (error, response, body) { - - console.log('error:', error); // Print the error if one occurred - console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received - console.log('body:', body); // Print the HTML for the Google homepage. + console.log('error:', error); // Print the error if one occurred + console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received + console.log('body:', body); // Print the HTML for the Google homepage. }); }; // export the class diff --git a/test.js b/test.js index b44900a..56560e8 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,4 @@ var clickatell = require("./index.js"); -//clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); +//clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER",27XXXXX-NUMBER], "APIKEY-HERE"); clickatell.sendMessageHttp("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); - From e40fc99d01af1d6441c3f76090a9ba2a5a70ebea Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Mon, 23 Oct 2017 07:43:25 +0000 Subject: [PATCH 18/19] 2.0.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 46ee545..a5d5682 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Morne Zeelie ", "description": "A simple NodeJs REST & HTTP interaction with Clickatell platform API", "main": "index.js", - "version": "2.0.9", + "version": "2.0.10", "license": "MIT", "repository": { "type": "git", From 754459a8c3714cb170b1978c48409598421689ee Mon Sep 17 00:00:00 2001 From: Morne Zeelie Date: Mon, 23 Oct 2017 07:44:22 +0000 Subject: [PATCH 19/19] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ba78a3..8b07af7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Add the message you want to send, and add the cell number you're sending to, and ``` var clickatell = require("clickatell-platform"); -///clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); +//clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE"); clickatell.sendMessageHttp("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE");