Skip to content

Commit

Permalink
[dist] example, test readme and package updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Fragomeni committed Mar 6, 2012
1 parent f3566b8 commit 81c8a86
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 22 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,4 +1,3 @@
.DS_Store
logs/*
node_modules/*
credentials/credentials.json
38 changes: 34 additions & 4 deletions README.md
@@ -1,4 +1,4 @@
# NOT READY YET! WORK IN PROGRESS! I JUST NEEDED TO SEND A TEXT MESSAGE =)
# NOT READY YET! WORK IN PROGRESS!

# Synopsis
Multi-vendor cellular network services for node.js
Expand All @@ -16,7 +16,7 @@ Everything else sucks

# Usage

## Simple example
## Example

```js
var Telenode = require('telenode');
Expand All @@ -30,12 +30,42 @@ client.SMS.send({

```

# Vendors and Authors
Create a file that has the name of the service, place it in the providers directory. Everything that is exported is attached to the new `Telenode` instance. Let's say we create a file called `foobar.js`.

```js
//
// this will become available on the new instance.
//
exports.getSomeInfo = function() {
console.log('here it is');
};

//
// create containers one level deep. they get bound to the correct context for you.
//
exports.Container = {
getTheSameInfo: function() { this.getInfo(); },
getSomeNewInfo: function() { console.log('something new'); }
};

```

```js
var client = new Telenode(new Telenode.providers.foobar);

//
// This will output some text to the console.
//
client.Container.getTheSameInfo();
client.Container.getSomeInfo();
```


# Installation

# Build Status

# API

# Vendors and Authors

# License
23 changes: 19 additions & 4 deletions examples/simple-sms.js
@@ -1,11 +1,13 @@

var Telenode = require('../lib/telenode');
var client = new Telenode(new Telenode.providers.Twilio);
var client = new Telenode(Telenode.providers.twilio);

//
// Signup at twilio.com to get a `sid` and `token`.
//
client.credentials({

//
// add these two things however you want, if you
// do not have them, just signup at `twilio.com`.
//
sid: '',
token: ''
});
Expand All @@ -14,7 +16,20 @@ client.credentials({
// send an sms message
//
client.SMS.send({

//
// put your twillio phone number here.
//
from: '+1-111-111-1111',

//
// put your cell phone number here.
//
to: '+1-111-111-1111',

//
// some message goes here.
//
body: 'Hello'

});
7 changes: 4 additions & 3 deletions lib/providers/twilio.js
Expand Up @@ -111,8 +111,6 @@ exports.SMS = {
headers['Content-Type'] = 'application/x-www-form-urlencoded';
headers['Authorization'] = 'Basic ' + this.basicAuth;

console.log(body)

request(
{
method: 'POST',
Expand All @@ -121,7 +119,10 @@ exports.SMS = {
body: body
},
function (err, response, body) {
return err ? callback(err) : callback(null, body);

if (callback) {
return err ? callback(err) : callback(null, body);
}
}
);

Expand Down
12 changes: 6 additions & 6 deletions lib/telenode.js
Expand Up @@ -28,6 +28,12 @@ var Telenode = module.exports = function Telenode(provider) {

var that = this;

this.HTTP = {};

for (var f in HTTP) {
typeof HTTP[f] === 'function' && (this.HTTP[f] = HTTP[f].bind(this));
}

for (var member in provider) {
if (typeof provider[member] === 'function') {

Expand All @@ -46,12 +52,6 @@ var Telenode = module.exports = function Telenode(provider) {
}
}

this.HTTP = {};

for (var f in HTTP) {
typeof HTTP[f] === 'function' && (this.HTTP[f] = HTTP[f].bind(this));
}

};

Telenode.providers = providers;
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "telenode",
"description": "A multi-vendor library for cellular network services",
"version": "0.0.2",
"version": "0.0.3",
"author": "Nodejitsu Inc <info@nodejitsu.com>",
"contributors": [
{ "name": "Paolo Fragomeni", "email": "paolo@nodejitsu.com" }
Expand Down
14 changes: 11 additions & 3 deletions test/twilio-sms-test.js
@@ -1,5 +1,7 @@

var Telenode = require('../lib/telenode');
var Telenode = require('../lib/telenode'),
assert = require('assert');

var client = new Telenode(Telenode.providers.twilio);

//
Expand All @@ -22,6 +24,12 @@ client.SMS.send(
body: 'Hello'
},
function(err, data) {
console.log(err || data);

//
// make sure we get a response that includes the
// sid that we sent in the original POST request.
//
data = JSON.parse(data);
assert.equal(data.sid, cred.sid);
}
);
);

0 comments on commit 81c8a86

Please sign in to comment.