Skip to content

Commit d3fc8be

Browse files
committed
Use libubsub to provide API rather than self-integrating. Bump version to 1.0
1 parent de336de commit d3fc8be

File tree

10 files changed

+360
-358
lines changed

10 files changed

+360
-358
lines changed

README.md

+2-43
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
[![npm](https://img.shields.io/npm/v/ubsub.svg)](https://www.npmjs.com/package/ubsub)
55
[![npm](https://img.shields.io/npm/l/ubsub.svg)](https://www.npmjs.com/package/ubsub)
66

7-
The ubsub-client is a nodejs module to easily connect to send and receive events from [UbSub](https://ubsub.io) using sockets and https.
7+
The ubsub-client is a nodejs module to easily connect to send and receive events from [UbSub](https://ubsub.io) using sockets and https via CLI.
88

9-
It also provides convenient wrappers to forward HTTP connections behind a NAT, to easily give you an endpoint to forward
10-
events from the public internet to a local network.
9+
**NOTICE:** This package is now ONLY the cli. API and streaming functions have been broken out into [libubsub](https://github.com/ubsub/libubsub)
1110

1211
# Using
1312

@@ -94,46 +93,6 @@ Other useful commands include things like:
9493
For a full list of features, run: `ubsub --help`
9594

9695

97-
## Installing for App Use
98-
99-
Installing into your project:
100-
101-
```bash
102-
npm install --save ubsub
103-
```
104-
105-
See [examples/](examples/) for some sample uses.
106-
107-
### Listening to a Topic
108-
109-
```js
110-
const ubsub = require('ubsub')(<user id>, <user secret>, [opts]);
111-
112-
ubsub.listen(<topic id>, (event, rawSocketEvent ) => {
113-
console.log('received event ' + JSON.stringify(event));
114-
});
115-
```
116-
117-
### Forwarding a Topic to an HTTP endpoint
118-
119-
```js
120-
const ubsub = require('ubsub')(<user id>, <user secret>, [opts]);
121-
122-
ubsub.forward(<topic id>, 'http://localhost:5000', {..optional axios opts..});
123-
```
124-
125-
### Sending an Event
126-
```js
127-
const ubsub = require('ubsub')(<user id>, <user secret>, [opts]);
128-
129-
ubsub.send('topicId', 'key'/null, { payload: 123 }, [method = 'POST']);
130-
```
131-
132-
## Options
133-
134-
`reconnectOnError`: Whether or not to reconnect on a fatal error. This is separate from the default SocketIO reconnect. (default: true)
135-
136-
`reconnectOnErrorDelay`: Number of milliseconds to delay the reconnect on error (default: 5000)
13796

13897
# License
13998

cmds/authUtil.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const os = require('os');
22
const fs = require('fs');
33
const chalk = require('chalk');
44
const _ = require('lodash');
5-
const Ubsub = require('../index');
5+
const Ubsub = require('libubsub').streaming;
66

77
const CONFIG_PATH = `${os.homedir()}/.ubsub`;
88

cmds/forward.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ exports.handler = function cmdForward(args) {
3232
},
3333
}).then(resp => {
3434
console.error(chalk.blue(` Received ${resp.status}`));
35+
}).catch(err => {
36+
console.error(chalk.red(err.message));
3537
});
3638
});
3739
}).catch(catchError);

cmds/login.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const inquirer = require('inquirer');
22
const chalk = require('chalk');
3-
const Ubsub = require('../index');
3+
const Ubsub = require('libubsub').streaming;
44
const authUtil = require('./authUtil');
55

66
exports.command = 'login';

cmds/webhook.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ exports.handler = function cmdWebhook(args) {
2323
const api = assertGetClient(args).getApi();
2424
return api.createTopic(args.name || `Webhook${~~(Math.random() * 1000)}`, !args.keyless)
2525
.then(topic => {
26-
const sock = cmdForward(_.assign({
26+
cmdForward(_.assign({
2727
topic: topic.id,
28-
}, args));
28+
}, args)).then(sock => {
29+
const url = `${api.routerUrl()}/event/${topic.id}${topic.key ? `?key=${topic.key}` : ''}`;
30+
console.error(`${chalk.bold('Endpoint')}: ${chalk.underline(url)}`);
2931

30-
const url = `${api.routerUrl()}/event/${topic.id}${topic.key ? `?key=${topic.key}` : ''}`;
31-
console.error(`${chalk.bold('Endpoint')}: ${chalk.underline(url)}`);
32-
33-
// Hook on to SIGINT for cleanup
34-
process.on('SIGINT', () => {
35-
sock.close();
36-
if (!args.keep) {
37-
console.error('Deleting topic...');
38-
api.deleteTopic(topic.id)
39-
.then(() => process.exit(0))
40-
.catch(err => {
41-
console.error(err.message);
42-
process.exit(1);
43-
});
44-
} else process.exit(0);
32+
// Hook on to SIGINT for cleanup
33+
process.on('SIGINT', () => {
34+
sock.close();
35+
if (!args.keep) {
36+
console.error('Deleting topic...');
37+
api.deleteTopic(topic.id)
38+
.then(() => process.exit(0))
39+
.catch(err => {
40+
console.error(err.message);
41+
process.exit(1);
42+
});
43+
} else process.exit(0);
44+
});
4545
});
4646
});
4747
};

examples/listening.js

-11
This file was deleted.

index.js

-83
This file was deleted.

lib/client.js

-106
This file was deleted.

0 commit comments

Comments
 (0)