Skip to content
This repository has been archived by the owner on Jul 18, 2018. It is now read-only.

Initial commit based off tentacles. #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
node_modules
npm-debug.log
.env
output
18 changes: 0 additions & 18 deletions Makefile

This file was deleted.

115 changes: 0 additions & 115 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,126 +11,11 @@ $ npm install --save node-gitter

## Basics

```js
var Gitter = require('node-gitter');

var gitter = new Gitter(token);

gitter.currentUser()
.then(function(user) {
console.log('You are logged in as:', user.username);
});
```

### Authentication

It's mandatory to provide a valid Gitter OAuth token in order to use the client. You can obtain one from [https://developer.gitter.im/apps](https://developer.gitter.im/apps).

### Promises or Callbacks

The client implements both. The following code is equivalent:

Using promises:

```js
gitter.rooms.join('gitterhq/sandbox')
.then(function(room) {
console.log('Joined room: ', room.name);
})
.fail(function(err) {
console.log('Not possible to join the room: ', err);
})
```

Using node-style callbacks:

```js
gitter.rooms.join('gitterhq/sandbox', function(err, room) {
if (err) {
console.log('Not possible to join the room: ', err);
return;
}

console.log('Joined room: ', room.name);
});

```

## Users

### Current user
```js
gitter.currentUser()
```

### Current user rooms, repos, orgs and channels
```js
gitter.currentUser()
.then(function(user) {
user.rooms()
user.repos()
user.orgs()
user.channels()
})
```

### Find a user
```js
gitter.users.find(userId)
```

## Rooms

### Join a room
```js
gitter.rooms.join('gitterhq/sandbox')
```

### Post a message to a room
```js
gitter.rooms.join('gitterhq/sandbox')
.then(function(room) {
room.send('Hello world!');
});

```

### Listen for chatMessages, Events or Users in a room
```js
gitter.rooms.find(roomId).then(function(room) {

var events = room.streaming().chatMessages();

// The 'snapshot' event is emitted once, with the last messages in the room
events.on('snapshot', function(snapshot) {
console.log(snapshot.length + ' messages in the snapshot');
});

// The 'chatMessages' event is emitted on each new message
events.on('chatMessages', function(message) {
console.log('A message was ' + message.operation);
console.log('Text: ', message.model.text);
});
});
```

### Room users, channels and messages
```js
gitter.rooms.find(roomId)
.then(function(room) {
room.users()
room.channels()
room.chatMessages()
});
```

### Leave a room
```js
gitter.rooms.find(roomId)
.then(function(room) {
room.leave()
});
```

# License

Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

21 changes: 21 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var gulp = require('gulp');
var mocha = require('gulp-spawn-mocha');

/**
* test
*/
gulp.task('test', function() {
return gulp.src(['./test/**/*.js'], { read: false })
.pipe(mocha({
reporter: 'spec',
timeout: 10000,
istanbul: {
dir: 'output/coverage-reports/'
},
env: {
Q_DEBUG: 1
}
}));
});

gulp.task('default', ['test']);
Loading