Browse files

hello, hipchat

  • Loading branch information...
0 parents commit 63e212a2420b4f54ae16007b98f98d0feb0fa589 @smurthas committed Jun 9, 2011
Showing with 79 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +19 −0 README.md
  3. +12 −0 example/test.js
  4. +36 −0 hipchat_client.js
  5. +11 −0 package.json
1 .gitignore
@@ -0,0 +1 @@
+node_modules
19 README.md
@@ -0,0 +1,19 @@
+# hipchat-js
+
+Simple HipChat API client
+
+ npm install hipchat-js
+
+## Usage
+
+hipchat-js has but one method:
+
+* apiCall(_http_method_, _path_, _params_, _callback_): Does a call to the HipChat API.
+
+
+## Test
+
+Enter your auth token in example/test.js
+
+ cd test
+ node test.js
12 example/test.js
@@ -0,0 +1,12 @@
+var hipchatClient = require('../')('aee0523648bbeb0fe89ccc02acff8d');
+
+hipchatClient.apiCall('GET', '/rooms/list', {}, function(err, resp) {
+ if(!err) {
+ hipchatClient.apiCall('GET', '/rooms/history',
+ {room_id:resp.rooms[0].room_id, date:'recent'}, function(err, resp) {
+ if(!err) {
+ console.log(resp);
+ }
+ });
+ }
+});
36 hipchat_client.js
@@ -0,0 +1,36 @@
+/*
+ * hipchat-js
+ *
+ * Copyright (c) 2011 Simon Murtha-Smith <simon@murtha-smith.com>
+ */
+
+var querystring = require('querystring');
+var request = require('request');
+
+var baseUrl = 'https://api.hipchat.com/v1';
+
+var Client = function(auth_token) {
+ this.apiCall = function (method, path, params, callback) {
+ callback = callback || function () {};
+ params.format = 'json';
+ params.auth_token = auth_token;
+ request({
+ method: method,
+ uri: baseUrl + path + '?' + querystring.stringify(params)
+ }, function (err, resp, body) {
+ if(err)
+ callback(err, body);
+ else {
+ try {
+ callback(null, JSON.parse(body));
+ } catch(e) {
+ callback(e, body);
+ }
+ }
+ });
+ };
+};
+
+module.exports = function(auth_token) {
+ return new Client(auth_token);
+}
11 package.json
@@ -0,0 +1,11 @@
+{
+ "name": "hipchat-js",
+ "description": "Simple Yammer API client",
+ "version": "0.0.0",
+ "author": "Simon Murtha-Smith <simon@murtha-smith.com>",
+ "keywords": ["hipchat"],
+ "main" : "hipchat_client.js",
+ "dependencies": { "request": "= 1.9.5" },
+ "repository" : {"type": "git" , "url": "http://github.com/smurthas/hipchat-js.git" },
+ "engines": { "node": ">=0.2.0 <0.5.0" }
+}

0 comments on commit 63e212a

Please sign in to comment.