Socket
Socket
Sign inDemoInstall

hipchatter

Package Overview
Dependencies
6
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

42

hipchatter.js

@@ -6,3 +6,3 @@ // Dependencies

// Hipchatter constructor
var Hipchatter = function(token, api_root) {
var Hipchatter = function(token, api_root) {
this.token = token;

@@ -81,6 +81,10 @@ this.api_root = api_root || 'https://api.hipchat.com/v2/';

// https://www.hipchat.com/docs/apiv2/method/get_all_users
users: function(callback) {
this.request('get', 'user', function(err, results) {
users: function(params, callback) {
if (this.isFunction(params)) { // No payload
callback = params;
params = {};
}
this.request('get', 'user', params, function(err, results) {
if(err) callback(err);
else callback(err, results.items)
else callback(err, results.items);
});

@@ -103,3 +107,3 @@ },

this.request('post', 'user', params, callback);
},
},
// Deletes a user

@@ -126,3 +130,3 @@ // https://www.hipchat.com/docs/apiv2/method/delete_user

// or
//
//
// Get emoticon by shortcut or id

@@ -237,3 +241,3 @@ // https://www.hipchat.com/docs/apiv2/method/get_emoticon

if (err) return callback(new Error(response));
var hooks = response.items;

@@ -265,6 +269,6 @@ var hookCalls = [];

}
else if (err.message == 'Room not found'){
else if (err.message.match(/Room .* not found/)){
return callback(null, false);
}
else {
else {
console.log(err)

@@ -316,6 +320,7 @@ return callback(err)

// type: required - type of REST request ('get' or 'post' currently)
// path: required -
// payload: optional - query string data for 'get', ''
// callback: required -
// path: required -
// payload: optional - query string data for 'get', ''
// callback: required -
request: function(type, path, payload, callback){
self = this;
if (this.isFunction(payload)) { // No payload

@@ -340,3 +345,5 @@ callback = payload;

else {
if (self.isFunction(callback)) {
callback(null, body, response.statusCode);
}
}

@@ -348,3 +355,2 @@ };

var url = payload.hasOwnProperty('token') ? this.url(path, payload, payload.token) : this.url(path, payload);
needle.get(url, requestCallback);

@@ -358,13 +364,15 @@

// PUT request
// PUT request
} else if (type.toLowerCase() === 'put') {
needle.put(this.url(path), payload, {json: true, headers:{'Content-Type': 'application/json; charset=utf-8'}}, requestCallback);
// DELETE request
// DELETE request
} else if (type.toLowerCase() === 'delete') {
needle.delete(this.url(path), {}, requestCallback);
// otherwise, something went wrong
} else {
// otherwise, something went wrong
} else {
if (self.isFunction(callback)) {
callback(new Error('Invalid use of the hipchatter.request function.'));
}
}

@@ -371,0 +379,0 @@ },

{
"name": "hipchatter",
"description": "Wrapper for the HipChat API (v2)",
"version": "0.2.0",
"author": "Charlton Roberts <charltonroberts@gmail.com (http://charlton.io)",
"version": "0.3.0",
"author": "Charlton Roberts <charltonroberts@gmail.com> (http://charlton.io)",
"license": "GPL-2.0",
"contributors": [

@@ -24,4 +25,4 @@ "Macklin Underdown <macklinu@gmail.com> (http://mackli.nu)"

"dependencies": {
"needle": "~0.6.3",
"async": "~0.2.9"
"async": "~0.2.9",
"needle": "^1.0.0"
},

@@ -28,0 +29,0 @@ "engines": {

@@ -142,6 +142,30 @@ HipChatter

// print the last message
console.log(history.items[items.length-1].message);
console.log(history.items[history.items.length-1].message);
});
````
### hipchatter.users
Returns all of the users.
**Parameters:**
- `param` (object) - Optional. query string parameters (optional)
- `'start-index': <int>` - Optional. The start index for the result set. Defaults to `0`.
- `'max-results': <int>` - Optional. The maximum number of results. Defaults to `100`.
- `'include-guests': <boolean>` - Optional. Include active guest users in response. Otherwise, no guest users will be included. Defaults to `'false'`.
- `'include-deleted': <boolean>` - Optional. Include deleted users in response. Defaults to`'false'`.
**Results:** `err`, response (array: list of users)
#### Usage
````javascript
// default: returns array of all emoticons
hipchatter.users(function(err, users){
console.log(users);
});
hipchatter.emoticons({'start-index': 20, 'max-results': 40}, function(err, users){
console.log(users);
});
````
### hipchatter.emoticons

@@ -299,3 +323,3 @@ Returns up to 100 emoticons.

````javascript
hipchatter.deleted_webhook('Hipchatter Room', '12345', function(err){
hipchatter.delete_webhook('Hipchatter Room', '12345', function(err){
if (err == null) console.log('Webhook sucessfully deleted');

@@ -349,5 +373,5 @@ });

- Copy `/test/settings.example.json` to `/test/settings.json`
- Fill out your creds
- Fill out your creds and strip comments from the JSON
- `npm install`
- `grunt stub` which creates the test room and test user
- `npm test`

@@ -7,3 +7,3 @@ var assert = require("assert");

// Make sure the API Credentials are present
try { var settings = require(__dirname+"/settings.json"); }
try { var settings = require(__dirname+"/settings.json"); }
catch (e) { console.error('Create test/settings.json and populate with your credentials.'.red);}

@@ -15,2 +15,8 @@

// tester emoticon
var EMOTICON = {
ID: 105216,
SHORTCUT: 'allthethings'
}
// Get emoticon(s)

@@ -83,3 +89,3 @@ describe('Emoticons', function(){

var options = {
'puppets': 10,
'puppets': 10,
'isCat': true

@@ -117,3 +123,3 @@ };

before(function(done){
hipchatter.emoticons(34, function(_err, _emoticon){
hipchatter.emoticons(EMOTICON.ID, function(_err, _emoticon){
err = _err;

@@ -133,6 +139,6 @@ emoticon = _emoticon;

expect(emoticon).to.not.be.empty;
expect(emoticon).to.have.property('id', 34);
expect(emoticon).to.have.property('id', EMOTICON.ID);
expect(emoticon).to.have.property('url');
expect(emoticon).to.have.property('links');
expect(emoticon).to.have.property('shortcut', 'menorah');
expect(emoticon).to.have.property('shortcut', EMOTICON.SHORTCUT);
});

@@ -146,3 +152,3 @@ });

before(function(done){
hipchatter.emoticons('fonzie', function(_err, _emoticon){
hipchatter.emoticons(EMOTICON.SHORTCUT, function(_err, _emoticon){
err = _err;

@@ -162,8 +168,8 @@ emoticon = _emoticon;

expect(emoticon).to.not.be.empty;
expect(emoticon).to.have.property('id', 41842);
expect(emoticon).to.have.property('id', EMOTICON.ID);
expect(emoticon).to.have.property('url');
expect(emoticon).to.have.property('links');
expect(emoticon).to.have.property('shortcut', 'fonzie');
expect(emoticon).to.have.property('shortcut', EMOTICON.SHORTCUT);
});
});
});
});

@@ -7,3 +7,3 @@ var assert = require("assert");

// Make sure the API Credentials are present
try { var settings = require(__dirname+"/settings.json"); }
try { var settings = require(__dirname+"/settings.json"); }
catch (e) { console.error('Create test/settings.json and populate with your credentials.'.red);}

@@ -20,3 +20,3 @@

describe('Get all rooms', function(){
// Set scope for the responses

@@ -48,3 +48,3 @@ var err, rooms;

describe('Create room', function(){
// Set scope for the responses

@@ -77,7 +77,7 @@ var err, room;

// READ
describe('Get room', function(){
// Set scope for the responses

@@ -108,4 +108,3 @@ var err, room;

hipchatter.get_room('non-existent room', function(err){
expect(err.message).to.equal('Room not found');
expect(err.message).to.contain('not found');
done();

@@ -117,13 +116,13 @@ });

// EDIT
describe('Update room', function(){
// Set scope for the responses
describe('Update room', function(){
// Set scope for the responses
var err, status;
// Make the request
before(function(done){
hipchatter.update_room( {
name: settings.disposable_room,
privacy: 'private',
is_archived: false,
is_guest_accessible: false,
topic: "New Topic",
before(function(done){
hipchatter.update_room( {
name: settings.disposable_room,
privacy: 'private',
is_archived: false,
is_guest_accessible: false,
topic: "New Topic",
owner: {id: ownerId}

@@ -142,3 +141,3 @@ }, function(_err, _body, _status) {

expect(status).to.equal(204);
});
});
});

@@ -148,3 +147,3 @@

describe('Delete room', function(){
// Set scope for the responses

@@ -167,2 +166,2 @@ var err;

});
});

@@ -7,3 +7,3 @@ var assert = require("assert");

// Make sure the API Credentials are present
try { var settings = require(__dirname+"/settings.json"); }
try { var settings = require(__dirname+"/settings.json"); }
catch (e) { console.error('Create test/settings.json and populate with your credentials.'.red);}

@@ -15,2 +15,7 @@

/*
* May need to create a test user for these tests to work
*
* node utils/create_test_users
*/
describe('Rooms -- members', function(){

@@ -22,3 +27,3 @@

params = {
room_name: settings.test_room,
room_name: settings.test_room,
user_email: settings.test_user.email

@@ -42,3 +47,3 @@ };

});
});

@@ -50,3 +55,3 @@

params = {
room_name: settings.test_room,
room_name: settings.test_room,
user_email: settings.test_user.email

@@ -70,3 +75,3 @@ };

});
});

@@ -78,3 +83,3 @@

params = {
room_name: settings.test_room,
room_name: settings.test_room,
user_email: settings.test_user.email

@@ -98,4 +103,4 @@ };

});
});
});
});

@@ -21,3 +21,3 @@ var assert = require("assert");

hipchatter.notify(settings.test_room, function(err, response, body){
expect(err.message).to.equal('Must supply an options object to the notify function containing at least the message and the room notification token. See https://www.hipchat.com/docs/apiv2/method/send_room_notification');
expect(err.message).to.contain('options object to the notify function');
done();

@@ -27,10 +27,2 @@ });

it('should throw an error if required options aren\'t passed', function(done){
hipchatter.notify(settings.test_room, {message: "No Auth token"}, function(err, response){
expect(err.message).to.equal('Message and Room Notification token are required.');
done();
});
});
//Sample room notification

@@ -37,0 +29,0 @@ it('should not return an error on valid request', function(done){

@@ -7,3 +7,3 @@ var assert = require("assert");

// Make sure the API Credentials are present
try { var settings = require(__dirname+"/settings.json"); }
try { var settings = require(__dirname+"/settings.json"); }
catch (e) { console.error('Create test/settings.json and populate with your credentials.'.red);}

@@ -40,3 +40,3 @@

hipchatter.history('non-existent room', function(err){
expect(err.message).to.equal('Room not found');
expect(err.message).to.contain('not found');
done();

@@ -57,2 +57,2 @@ });

});
});
});

@@ -7,3 +7,3 @@ var assert = require("assert");

// Make sure the API Credentials are present
try { var settings = require(__dirname+"/settings.json"); }
try { var settings = require(__dirname+"/settings.json"); }
catch (e) { console.error('Create test/settings.json and populate with your credentials.'.red);}

@@ -43,2 +43,28 @@

// Get all users
describe('Get All Users with Options', function() {
// Set scope for the responses
var err, users;
// Make the request
before(function(done){
hipchatter.users({"max-results": 1000}, function(_err, _users){
err = _err;
users = _users;
done();
});
});
it('should not return an error', function(){
expect(err).to.be.null;
});
it('should return a list of users', function(){
expect(users).to.be.ok;
expect(users).to.not.be.empty;
});
it('should return users that have an id and name, at least', function(){
expect(users[0]).to.have.property('name');
expect(users[0]).to.have.property('id');
});
});
// Create a user

@@ -82,3 +108,3 @@ describe('Create User', function() {

});
});

@@ -113,3 +139,3 @@

//TODO check with get_user that the user was actually updated
//TODO check with get_user that the user was actually updated
});

@@ -136,3 +162,3 @@

});
});

@@ -161,3 +187,3 @@

});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc