Permalink
Browse files

initial commit of files.

  • Loading branch information...
0 parents commit 7c5e39fb0a7b9bb4af2f3d0ba66499446e3029e8 @mheadd mheadd committed May 18, 2011
@@ -0,0 +1,4 @@
+.buildpath
+.project
+.settings/*
+
@@ -0,0 +1,3 @@
+.git*
+.settings*
+.project
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Voxeo Corporation
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,89 @@
+Node.js Module for the SMSified API
+=========================
+
+A Node.js module for interaction with the [SMSified](http://smsified.com) API.
+
+SMSified API Overview
+---------------------
+
+SMSified is a simple REST SMS API, built to uniquely enable developers to create powerful SMS services with minimum effort. Through SMSified, developers can both send and receive SMS messages, as well as track usage and message history through a powerful reporting dashboard. You can use either standard phone numbers or short codes, and best of all, SMSified is backed by Voxeo - the world's largest real-time application cloud.
+
+When you sign up, you automatically receive $20 in credit and one free phone number; this allows you to both receive and send free SMS messages while testing. When the credit runs out, just add a credit card for billing and you're live - but you get to keep the phone number for free! Check out our pricing page for more information.
+
+More info here: [SMSified API Docs](http://www.smsified.com/sms-api-documentation)
+
+Installation
+------------
+
+ npm intall smsified
+
+
+Usage Examples
+--------------
+
+The following simple example will send an outbound SMS message from (407) 554-1234 to (518) 476-1234 and write out the JSON response from SMSified to the console:
+
+ var sys = require('sys');
+ var smsified = require('smsified');
+
+ var sms = new SMSified('username', 'password');
+ var options = {senderAddress: '4075541234', address: '15184761234', message: 'Hello world from Node.js'};
+ sms.sendMessage(options, function(result) {
+ sys.puts(sys.inspect(result));
+ });
+
+Send an outbound SMS message and set a callback URL:
+
+ var sms = new SMSified('username', 'password');
+ var options = {senderAddress: '4075541234', address: '15184761234', message: 'Hello from Node.js with another callback', notifyURL: 'http://path-to-somewhere/'};
+ sms.sendMessage(options, function(result) {
+ sys.puts(sys.inspect(result));
+ });
+
+Check the status of an SMS message:
+
+ var sms = new SMSified('username', 'password');
+ sms.checkStatus('4075541234', '43d2f75b2bda27006200003e9b7dcf3b', function(result) {
+ sys.puts(sys.inspect(result.deliveryInfoList.deliveryInfo));
+ });
+
+Create a subscription for an account phone number:
+
+ var sms = new SMSified('username', 'password');
+ sms.createSubscription('4075541234', 'outbound', 'http://path-to-somewhere', function(result) {
+ sys.puts(sys.inspect(result));
+ });
+
+View all active subscriptions:
+
+ var sms = new SMSified('username', 'password');
+ sms.viewSubscriptions('4075541234', 'outbound', function(result) {
+ sys.puts('Number of subscriptions: ' + result.outboundSubscriptionList.numberOfSubscriptions);
+ sys.puts(sys.inspect(result.outboundSubscriptionList.outboundSubscription));
+ });
+
+Delete a subscription:
+
+ var sms = new SMSified('username', 'password');
+ sms.deleteSubscriptions('6267217aae394b5dc656ba4216082304', 'outbound', function(result) {
+ if(result = '204') {
+ sys.puts('Subscription delted.');
+ }
+ else {
+ sys.puts('Could not delete subscription.');
+ }
+ });
+
+Retrieve delivery information on a message:
+
+ var sms = new SMSified('username', 'password');
+ sms.getMessages('02b45e3072ae5e157a12d0408bcede65', null, function(result) {
+ sys.puts(sys.inspect(result));
+ });
+
+Retrieve delivery information on a set of messages, using filters to specify messages:
+
+ var sms = new SMSified('username', 'password');
+ sms.getMessages(null, {status: 'success', direction: 'in'}, function(result) {
+ sys.puts(sys.inspect(result));
+ });
@@ -0,0 +1,10 @@
+/**
+ * Check the status of an SMS message.
+ */
+var sys = require('sys');
+var smsified = require('../lib/smsified');
+
+var sms = new SMSified('username', 'password');
+sms.checkStatus('4075541234', '43d2f75b2bda27006200003e9b7dcf3b', function(result) {
+ sys.puts(sys.inspect(result.deliveryInfoList.deliveryInfo));
+});
@@ -0,0 +1,10 @@
+/**
+ * Create a subscription for an account phone number.
+ */
+var sys = require('sys');
+var smsified = require('../lib/smsified');
+
+var sms = new SMSified('username', 'password');
+sms.createSubscription('4075541234', 'outbound', 'http://path-to-somewhere', function(result) {
+ sys.puts(sys.inspect(result));
+});
@@ -0,0 +1,16 @@
+/**
+ * Delete a subscription.
+ */
+
+var sys = require('sys');
+var smsified = require('../lib/smsified');
+
+var sms = new SMSified('username', 'password');
+sms.deleteSubscriptions('6267217aae394b5dc656ba4216082304', 'outbound', function(result) {
+ if(result = '204') {
+ sys.puts('Subscription delted.');
+ }
+ else {
+ sys.puts('Could not delete subscription.');
+ }
+});
@@ -0,0 +1,10 @@
+/**
+ * Retrieve delivery information on a message.
+ */
+var sys = require('sys');
+var smsified = require('../lib/smsified');
+
+var sms = new SMSified('username', 'password');
+sms.getMessages('02b45e3072ae5e157a12d0408bcede65', null, function(result) {
+ sys.puts(sys.inspect(result));
+});
@@ -0,0 +1,11 @@
+/**
+ * Retrieve delivery information on a set of messages, using filters to specify messages.
+ */
+
+var sys = require('sys');
+var smsified = require('../lib/smsified');
+
+var sms = new SMSified('username', 'password');
+sms.getMessages(null, {status: 'success', direction: 'in'}, function(result) {
+ sys.puts(sys.inspect(result));
+});
@@ -0,0 +1,12 @@
+/**
+ * Send an outbound SMS message and set a callback URL.
+ */
+
+var sys = require('sys');
+var smsified = require('../lib/smsified');
+
+var sms = new SMSified('username', 'password');
+var options = {senderAddress: '4075541234', address: '15184761234', message: 'Hello from Node.js with another callback', notifyURL: 'http://path-to-somewhere/'};
+sms.sendMessage(options, function(result) {
+ sys.puts(sys.inspect(result));
+});
@@ -0,0 +1,12 @@
+/**
+ * Send an outbound SMS message.
+ */
+
+var sys = require('sys');
+var smsified = require('../lib/smsified');
+
+var sms = new SMSified('username', 'password');
+var options = {senderAddress: '4075541234', address: '15184761234', message: 'Hello world from Node.js'};
+sms.sendMessage(options, function(result) {
+ sys.puts(sys.inspect(result));
+});
@@ -0,0 +1,12 @@
+/**
+ * View all active subscriptions.
+ */
+
+var sys = require('sys');
+var smsified = require('../lib/smsified');
+
+var sms = new SMSified('username', 'password');
+sms.viewSubscriptions('4075541234', 'outbound', function(result) {
+ sys.puts('Number of subscriptions: ' + result.outboundSubscriptionList.numberOfSubscriptions);
+ sys.puts(sys.inspect(result.outboundSubscriptionList.outboundSubscription));
+});
@@ -0,0 +1,107 @@
+/**
+ * A Node.js module or interacting with the SMSified API.
+ */
+
+var http = require('http');
+
+SMSified = function(username, password) {
+ this.host = 'api.smsified.com';
+ this.version = 'v1',
+ this.username = username;
+ this.password = password;
+ this.responseBody = "";
+};
+
+// Send an outbmound SMS message.
+SMSified.prototype.sendMessage = function(options, callback) {
+ path = '/' + this.version + '/smsmessaging/outbound/' + options.senderAddress + '/requests?address=' + options.address + '&message=' + encodeURI(options.message);
+ path += options.notifyURL ? '&notifyURL=' + options.notifyURL : '';
+ this.makeApiCall('POST', path, callback);
+};
+
+// Check the status of an SMS message.
+SMSified.prototype.checkStatus = function(senderAddress, requestID, callback) {
+ path = '/v1/smsmessaging/outbound/' + senderAddress + '/requests/' + requestID + '/deliveryInfos';
+ this.makeApiCall('GET', path, callback);
+};
+
+// Create a subscription for an account phone number.
+SMSified.prototype.createSubscription = function(senderAddress, direction, notifyURL, callback) {
+ path = '/' + this.version + '/smsmessaging/' + direction + '/' + senderAddress + '/subscriptions?notifyURL=' + notifyURL;
+ this.makeApiCall('POST', path, callback);
+};
+
+// View all active subscriptions.
+SMSified.prototype.viewSubscriptions = function(senderAddress, direction, callback) {
+ path = '/' + this.version + '/smsmessaging/' + direction + '/subscriptions/?senderAddress=' + senderAddress;
+ this.makeApiCall('GET', path, callback);
+};
+
+// Delete a subscrption.
+SMSified.prototype.deleteSubscriptions = function(subscriptionID, direction, callback) {
+ path = '/' + this.version + '/smsmessaging/' + direction + '/subscriptions/' + subscriptionID;
+ this.makeApiCall('DELETE', path, callback);
+};
+
+// Get information on SMS messages.
+SMSified.prototype.getMessages = function(messageID, options, callback) {
+ path = '/' + this.version + '/messages/';
+ if(messageID) {
+ path += messageID;
+ }
+ else {
+ path += '?';
+ for(item in options) {
+ path += item + '=' + encodeURI(options[item]) + '&';
+ }
+ }
+ this.makeApiCall('GET', path, callback);
+};
+
+// Helper method to make HTTP call to SMSified API.
+SMSified.prototype.makeApiCall = function(method, path, callback) {
+
+ var self = this;
+
+ // Set athentication header.
+ var auth = 'Basic ' + new Buffer(this.username + ':' + this.password).toString('base64');
+
+ // Set options for HTTP request.
+ var options = {
+ host : this.host,
+ port: 80,
+ path : path,
+ method : method
+ };
+
+ // Set HTTP headers for API request.
+ if(method != 'DELETE') {
+ headers = { 'Content-Type' : 'application/x-www-form-urlencoded', 'Authorization' : auth , 'Content-Length': 0 };
+ }
+ else {
+ headers = { 'Authorization' : auth, 'Content-Length': 0 };
+ }
+ options.headers = headers;
+
+ var apiCall = http.request(options, function(response) {
+
+ // If the HTTP method used is delete, just return the statusCode.
+ if(method == 'DELETE') {
+ callback(response.statusCode);
+ }
+
+ // Otherwise, return the response body.
+ else {
+ response.setEncoding('utf8');
+ response.on('data', function(chunk) {
+ self.responseBody += chunk;
+ });
+ response.on('end', function() {
+ callback(JSON.parse(self.responseBody));
+ });
+ }
+ });
+ apiCall.end();
+};
+
+exports.SMSified = SMSified;
@@ -0,0 +1,15 @@
+{
+ "name": "smsified",
+ "description": "A Node.js library for interaction with the SMSified API.",
+ "version": "1.0.1",
+ "homepage": "http://smsified.com",
+ "author": "Mark Headd <mheadd@voxeo.com> (http://smsified.com)",
+ "main": "./lib/smsified",
+ "directories" : { "lib" : "./lib", "examples" : "./examples" },
+ "repositories" : [
+ { "type":"git", "url":"https://github.com/smsified/smsified-node" }
+ ],
+ "engines": {
+ "node": "> 0.4"
+ }
+}

0 comments on commit 7c5e39f

Please sign in to comment.