Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 0256b56edd98d3daef573cdc26e6759c291d23a8 @fabrik42 fabrik42 committed Jul 11, 2011
Showing with 7,148 additions and 0 deletions.
  1. 0 README.md
  2. +1 −0 index.js
  3. +84 −0 lib/pusher.js
  4. +1 −0 node_modules/.bin/nodeunit
  5. +3 −0 node_modules/nodeunit/.gitignore
  6. +3 −0 node_modules/nodeunit/.npmignore
  7. +60 −0 node_modules/nodeunit/CONTRIBUTORS.md
  8. +19 −0 node_modules/nodeunit/LICENSE
  9. +126 −0 node_modules/nodeunit/Makefile
  10. +433 −0 node_modules/nodeunit/README.md
  11. +108 −0 node_modules/nodeunit/bin/nodeunit
  12. +10 −0 node_modules/nodeunit/bin/nodeunit.json
  13. +623 −0 node_modules/nodeunit/deps/async.js
  14. +125 −0 node_modules/nodeunit/deps/ejs.js
  15. +483 −0 node_modules/nodeunit/deps/json2.js
  16. +60 −0 node_modules/nodeunit/doc/nodeunit.md
  17. +1,757 −0 node_modules/nodeunit/examples/browser/nodeunit.js
  18. +12 −0 node_modules/nodeunit/examples/browser/suite1.js
  19. +13 −0 node_modules/nodeunit/examples/browser/suite2.js
  20. +16 −0 node_modules/nodeunit/examples/browser/test.html
  21. BIN node_modules/nodeunit/img/example_fail.png
  22. BIN node_modules/nodeunit/img/example_pass.png
  23. +3 −0 node_modules/nodeunit/index.js
  24. +316 −0 node_modules/nodeunit/lib/assert.js
  25. +236 −0 node_modules/nodeunit/lib/core.js
  26. +80 −0 node_modules/nodeunit/lib/nodeunit.js
  27. +119 −0 node_modules/nodeunit/lib/reporters/browser.js
  28. +131 −0 node_modules/nodeunit/lib/reporters/default.js
  29. +112 −0 node_modules/nodeunit/lib/reporters/html.js
  30. +9 −0 node_modules/nodeunit/lib/reporters/index.js
  31. +186 −0 node_modules/nodeunit/lib/reporters/junit.js
  32. +117 −0 node_modules/nodeunit/lib/reporters/minimal.js
  33. +110 −0 node_modules/nodeunit/lib/reporters/skip_passed.js
  34. +50 −0 node_modules/nodeunit/lib/track.js
  35. +187 −0 node_modules/nodeunit/lib/types.js
  36. +209 −0 node_modules/nodeunit/lib/utils.js
  37. +95 −0 node_modules/nodeunit/man1/nodeunit.1
  38. +4 −0 node_modules/nodeunit/nodelint.cfg
  39. +53 −0 node_modules/nodeunit/package.json
  40. +19 −0 node_modules/nodeunit/share/junit.xml.ejs
  41. +11 −0 node_modules/nodeunit/share/license.js
  42. +70 −0 node_modules/nodeunit/share/nodeunit.css
  43. +4 −0 node_modules/nodeunit/test/fixtures/coffee/mock_coffee_module.coffee
  44. +1 −0 node_modules/nodeunit/test/fixtures/dir/mock_module3.js
  45. +1 −0 node_modules/nodeunit/test/fixtures/dir/mock_module4.js
  46. +1 −0 node_modules/nodeunit/test/fixtures/mock_module1.js
  47. +1 −0 node_modules/nodeunit/test/fixtures/mock_module2.js
  48. +3 −0 node_modules/nodeunit/test/fixtures/raw_jscode1.js
  49. +3 −0 node_modules/nodeunit/test/fixtures/raw_jscode2.js
  50. +1 −0 node_modules/nodeunit/test/fixtures/raw_jscode3.js
  51. +219 −0 node_modules/nodeunit/test/test-base.js
  52. +114 −0 node_modules/nodeunit/test/test-failing-callbacks.js
  53. +55 −0 node_modules/nodeunit/test/test-httputil.js
  54. +214 −0 node_modules/nodeunit/test/test-runfiles.js
  55. +125 −0 node_modules/nodeunit/test/test-runmodule.js
  56. +46 −0 node_modules/nodeunit/test/test-runtest.js
  57. +31 −0 node_modules/nodeunit/test/test-sandbox.js
  58. +234 −0 node_modules/nodeunit/test/test-testcase.js
  59. +26 −0 node_modules/nodeunit/test/test.html
  60. +15 −0 package.json
No changes.
@@ -0,0 +1 @@
+module.exports = require('./lib/pusher');
@@ -0,0 +1,84 @@
+module.exports = (function(){
+ var crypto = require('crypto'),
+ http = require('http'),
+ sys = require('sys');
+
+ var Pusher = function(options) {
+ this.options = options;
+
+ return this;
+ }
+
+ Pusher.prototype.domain = 'api.pusherapp.com';
+
+ Pusher.prototype.channel = function(channel) {
+ if(typeof channel === 'undefined') return this.options.channel;
+ this.options.channel = channel;
+
+ return this;
+ }
+
+ Pusher.prototype.trigger = function(event, data, callback) {
+ this.event = event;
+ this.data = JSON.stringify(data);
+ this.send(callback);
+
+ return this;
+ }
+
+ Pusher.prototype.send = function(callback) {
+ var client = http.createClient(80, this.domain);
+ var request = client.request('POST', this.path(), {
+ 'host': this.domain,
+ 'Content-Type': 'application/json',
+ 'Content-Length': this.data.length
+ });
+
+ if(callback) {
+ client.addListener('error', function(error) {
+ callback(error, request, null);
+ });
+
+ request.addListener('response', function(response) {
+ callback(null, request, response);
+ });
+ }
+
+ request.write(this.data);
+ request.end();
+
+ return request;
+ }
+
+ Pusher.prototype.path = function() {
+ return this.uri() + '?' + this.queryString() + '&auth_signature=' + this.signature();
+ }
+
+ Pusher.prototype.uri = function() {
+ return '/apps/' + this.options.appId + '/channels/' + this.options.channel + '/events';
+ }
+
+ Pusher.prototype.queryString = function() {
+ var timestamp = parseInt(new Date().getTime() / 1000);
+
+ return [
+ 'auth_key=', this.options.appKey,
+ '&auth_timestamp=', timestamp,
+ '&auth_version=', '1.0',
+ '&body_md5=', this.hash(),
+ '&name=', this.event
+ ].join('');
+ }
+
+ Pusher.prototype.hash = function() {
+ return crypto.createHash('md5').update(this.data).digest("hex");
+ }
+
+ Pusher.prototype.signature = function(uri, queryString) {
+ var signData = ['POST', this.uri(), this.queryString()].join('\n');
+
+ return crypto.createHmac('sha256', this.options.secret).update(signData).digest('hex');
+ }
+
+ return Pusher;
+})();

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 0256b56

Please sign in to comment.