From 6e20a1d4c9b630572c9688771ab3febe6a696279 Mon Sep 17 00:00:00 2001 From: InspiredJW Date: Wed, 12 Sep 2012 16:48:44 +0900 Subject: [PATCH] coolsms initial commit --- .gitignore | 9 +++++++++ Cakefile | 5 +++++ README.md | 40 +++++++++++++++++++++++++++++++++++++++ index.js | 6 ++++++ lib/coolsms.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 +++++++++++++++++ src/coolsms.coffee | 39 ++++++++++++++++++++++++++++++++++++++ src/coolsms.js | 42 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 205 insertions(+) create mode 100644 .gitignore create mode 100644 Cakefile create mode 100644 README.md create mode 100644 index.js create mode 100644 lib/coolsms.js create mode 100644 package.json create mode 100644 src/coolsms.coffee create mode 100644 src/coolsms.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ed5916 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.db +.DS_Store +.project +ssl +node_modules +.metadata +*.tmproj +*.sublime-project +dump.rdb diff --git a/Cakefile b/Cakefile new file mode 100644 index 0000000..554b357 --- /dev/null +++ b/Cakefile @@ -0,0 +1,5 @@ +{exec} = require 'child_process' + +task 'watch', 'Watch CS File Changes and Compile right away', -> + exec 'coffee --watch --bare --compile --output lib/ src/', (err, stdout, stderr) -> + throw err if err diff --git a/README.md b/README.md new file mode 100644 index 0000000..52fba39 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +CoolSMS-node +===== + +--- + +## Installation + +
+  npm install coolsms
+
+ +or + +
+  git clone git://github.com/InspiredJW/coolsms.git
+
+ +## Usage + +```javascript +var coolsms = require('coolsms'); + +coolsms({ + ssl: true, // true | false + user: 'username', // CoolSMS username + password: 'password', // CoolSMS password + to: '01000000000', // Recipient Phone Number + from: '01000000000', // Sender Phone Number + text: 'Hello World!' // Text to send +}, function(err, result) { + // error message in String and result information in JSON + if (err) { + console.log(err); + } + console.log(body); +}); + +``` + +## \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..35726aa --- /dev/null +++ b/index.js @@ -0,0 +1,6 @@ +/* + * CoolSMS - Node.js + * Copyright (c) 2012 InspiredJW + * MIT Licensed + */ +module.exports = require('./lib/coolsms'); \ No newline at end of file diff --git a/lib/coolsms.js b/lib/coolsms.js new file mode 100644 index 0000000..855b2c7 --- /dev/null +++ b/lib/coolsms.js @@ -0,0 +1,47 @@ +// Generated by CoffeeScript 1.3.3 +var crypto, request, _; + +crypto = require("crypto"); + +request = require("request"); + +_ = require("underscore"); + +module.exports = function(input, callback) { + var options; + options = { + uri: '//api.coolsms.co.kr/sendmsg', + ssl: false, + user: 'user', + password: 'password', + enc: 'md5', + to: '', + from: '', + text: '' + }; + options = _.extend(options, input); + options.password = crypto.createHash(options.enc).update(options.password).digest("hex"); + return request.post({ + uri: (options.ssl ? "https:" : "http:") + options.uri, + form: { + user: options.user, + password: options.password, + enc: options.enc, + to: options.to, + from: options.from, + text: options.text + } + }, function(err, res, body) { + var line, lines, messages, part, _i, _len; + messages = {}; + lines = body.split('\n'); + for (_i = 0, _len = lines.length; _i < _len; _i++) { + line = lines[_i]; + part = line.split('='); + if (part[0].trim().length > 0) { + messages[part[0]] = part[1]; + } + } + return callback(err, messages); + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..0f56360 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "coolsms", + "description": "coolsms for Node.js", + "version": "1.0.0", + "author": "InspiredJW ", + "keywords": ["coolsms", "sms", "text", "mobile"], + "repository": { + "type": "git", + "url": "https://github.com/InspiredJW/coolsms.git" + }, + "dependencies": { + "request": "*", + "underscore": "*" + }, + "main": "index", + "engines": { "node": ">= 0.6.0" } +} diff --git a/src/coolsms.coffee b/src/coolsms.coffee new file mode 100644 index 0000000..600f8d5 --- /dev/null +++ b/src/coolsms.coffee @@ -0,0 +1,39 @@ +crypto = require "crypto" +request = require "request" +_ = require "underscore" + +module.exports = (input, callback) -> + options = + uri: '//api.coolsms.co.kr/sendmsg' + ssl: false + user: 'user' + password: 'password' + enc: 'md5' + to: '' + from: '' + text: '' + + options = _.extend options, input + + options.password = crypto + .createHash(options.enc) + .update(options.password) + .digest("hex") + + request.post + uri: (if options.ssl then "https:" else "http:") + options.uri + form: + user: options.user + password: options.password + enc: options.enc + to: options.to + from: options.from + text: options.text + , (err, res, body) -> + messages = {} + lines = body.split '\n' + for line in lines + part = line.split '=' + messages[part[0]] = part[1] if part[0].trim().length > 0 + + callback err, messages \ No newline at end of file diff --git a/src/coolsms.js b/src/coolsms.js new file mode 100644 index 0000000..3947b2c --- /dev/null +++ b/src/coolsms.js @@ -0,0 +1,42 @@ +// Generated by CoffeeScript 1.3.3 +(function() { + var crypto, request, _; + + crypto = require("crypto"); + + request = require("request"); + + _ = require("underscore"); + + module.exports = function(input, callback) { + var options; + options = { + uri: '//api.coolsms.co.kr/sendmsg', + method: 'post', + ssl: false, + user: 'user', + password: 'password', + enc: 'md5', + to: '', + from: '', + text: '' + }; + options = _.extend(options, input); + options.password = crypto.createHash(options.enc).update(options.password).digest("hex"); + return request({ + method: options.method, + uri: (ssl ? "https" : "http") + options.uri, + json: { + user: options.user, + password: options.password, + enc: options.enc, + to: options.to, + from: options.from, + text: options.text + } + }, function(err, res, body) { + return callback(err, res, body); + }); + }; + +}).call(this);