-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sample app and updated api to include channels and event names
- Loading branch information
Showing
13 changed files
with
15,764 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,82 @@ | ||
NotifyIt | ||
======== | ||
#NotifyIt | ||
|
||
Simple notification tool, designed to alert developer of unit test results. | ||
This is a simple PubSub tool which allows you to publish events via an HTTP POST interface, and subscribe to events via a [socket.io][] connection. | ||
|
||
##Pre-reqs | ||
To use this tool, you'll need to have [node.js][node] (v0.4 or greater) and [npm][] installed. I've tested the tool on OSX and Linux, but it should work fine on Windows as well. | ||
|
||
[socket.io]: http://www.socket.io | ||
[node]: http://nodejs.org/ | ||
[npm]: http://npmjs.org/ | ||
|
||
##Install | ||
|
||
git clone git://github.com/sethmcl/notifyit.git | ||
cd notifyit | ||
npm install | ||
|
||
##Usage | ||
|
||
To start the server, run: | ||
|
||
$ bin/notifyit [port] | ||
|
||
You can optionally specify a port. If not port is specified, the default port of 2012 will be used. | ||
|
||
##Publishing Events | ||
To publish an event, post to the /pub endpoint on the server. For example to publish an event called "new-data" on the "test" channel, you could POST something like this: | ||
|
||
$ curl http://localhost:2012/pub/test/new-data -d "{\"name\":\"Seth\"}" -H "Content-Type:application/json" -v | ||
|
||
By specifying the `Content-Type`, NotifyIt will attempt to parse the request body as JSON. If the parsing fails (due to malformed JSON), then the event will not be published | ||
and you will receive a `500` HTTP response. | ||
|
||
If you do not specify a content type, NotifyIt will assume the data is simple text. Let's publish an event called "connect" on the "test" channel: | ||
|
||
$ curl http://localhost:2012/pub/test/connect -d "name=Seth" -v | ||
|
||
Try running these commands - you will see status output in the console where you are running the server. | ||
|
||
##Subscribing to Events | ||
Subscribing to events is pretty straightforward. Include the socket.io client library on your page or node.js script, and then subscribe to events. Example: | ||
|
||
var socket = io.connect('http://localhost:2012'); | ||
socket.on('test:new-data', function(e) { | ||
console.log( e.channel ); // Channel name, e.g., 'test' | ||
console.log( e.event ); // Event name, e.g., 'new-data' | ||
console.log( e.data ); // Data, e.g., 'name:Seth'. If event data was published as JSON, then this will be an object. | ||
} | ||
|
||
Alternatively, you can subscribe to the 'all' event to receive all events: | ||
|
||
var socket = io.connect('http://localhost:2012'); | ||
socket.on('all', function(e) { | ||
console.log( e.channel ); // Channel name, e.g., 'test' | ||
console.log( e.event ); // Event name, e.g., 'new-data' | ||
console.log( e.data ); // Data, e.g., 'name:Seth'. If event data was published as JSON, then this will be an object. | ||
} | ||
|
||
##Sample App | ||
To see this in action, start the server: | ||
|
||
$ bin/notifyit | ||
|
||
Then open a browser and go to `http://localhost:2012`. | ||
|
||
Finally, publish a sample event with a curl command: | ||
|
||
$ curl http://localhost:2012/pub/test/connect -d "name=Seth" | ||
|
||
You should see the event disaplayed in the browser. | ||
|
||
##Running the Unit Tests | ||
|
||
If you have not installed the nodeunit command before, please run these commands to build: | ||
|
||
$ cd node_modules/nodeunit | ||
$ sudo make install | ||
$ cd ../../ | ||
|
||
To execute the tests, run this command from the repository root: | ||
|
||
$ nodeunit tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
new (require("../NotifyIt"))().start(); | ||
new (require("../notifyit"))().start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
html, body { | ||
overflow: auto; | ||
} | ||
|
||
#content { | ||
margin: 70px 100px 0 100px; | ||
max-width: 75%; | ||
} | ||
|
||
#console { | ||
margin-top: 20px; | ||
background: #ccc; | ||
padding: 20px; | ||
} | ||
|
||
#console ul { | ||
list-style-type: none; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
#console li.data { | ||
color: #0271FF; | ||
} | ||
|
||
#console ul li:before { | ||
content: '>> '; | ||
} | ||
|
||
.hidden { | ||
display: none !important; | ||
} |
Oops, something went wrong.