Skip to content

Commit 53d7807

Browse files
committed
Reformat with Prettier.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 3daad9c commit 53d7807

40 files changed

+698
-476
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"plugins": [
44
"@babel/plugin-transform-destructuring",
55
"@babel/plugin-transform-instanceof",
6-
["@babel/plugin-transform-runtime",
6+
[
7+
"@babel/plugin-transform-runtime",
78
{
89
"regenerator": true
910
}

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/lib

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"proseWrap": "never",
3+
"singleQuote": true
4+
}

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,70 @@
11
# zulip-js [![Build Status](https://travis-ci.com/zulip/zulip-js.svg?branch=master)](https://travis-ci.com/github/zulip/zulip-js)
2+
23
Javascript library to access the Zulip API
34

45
# Usage
6+
57
## Initialization
8+
69
### With API Key
10+
711
```js
812
const zulip = require('zulip-js');
913
const config = {
1014
username: process.env.ZULIP_USERNAME,
1115
apiKey: process.env.ZULIP_API_KEY,
12-
realm: process.env.ZULIP_REALM
16+
realm: process.env.ZULIP_REALM,
1317
};
1418

15-
zulip(config).then(zulip => {
19+
zulip(config).then((zulip) => {
1620
// The zulip object now initialized with config
17-
zulip.streams.subscriptions.retrieve().then(res => {
21+
zulip.streams.subscriptions.retrieve().then((res) => {
1822
console.log(res);
1923
});
2024
});
2125
```
2226

2327
### With Username & Password
28+
2429
You will need to first retrieve the API key by calling `zulip(config)` and then use the zulip object that it passes to `.then()`
2530

2631
```js
2732
const zulip = require('zulip-js');
2833
const config = {
2934
username: process.env.ZULIP_USERNAME,
3035
password: process.env.ZULIP_PASSWORD,
31-
realm: process.env.ZULIP_REALM
36+
realm: process.env.ZULIP_REALM,
3237
};
3338

3439
//Fetch API Key
35-
zulip(config).then(zulip => {
40+
zulip(config).then((zulip) => {
3641
// The zulip object now contains the API Key
37-
zulip.streams.subscriptions.retrieve().then(res => {
42+
zulip.streams.subscriptions.retrieve().then((res) => {
3843
console.log(res);
3944
});
4045
});
4146
```
4247

4348
### With zuliprc
49+
4450
Create a file called `zuliprc` (in the same directory as your code) which looks like:
51+
4552
```
4653
[api]
4754
4855
key=wlueAg7cQXqKpUgIaPP3dmF4vibZXal7
4956
site=http://localhost:9991
5057
```
5158

52-
Please remember to add this file to your `.gitignore`!
53-
Calling `zulip({ zuliprc: 'zuliprc' } )` will read this file and then pass a configured zulip object to `.then()`.
59+
Please remember to add this file to your `.gitignore`! Calling `zulip({ zuliprc: 'zuliprc' } )` will read this file and then pass a configured zulip object to `.then()`.
5460

5561
```js
5662
const zulip = require('zulip-js');
5763
const path = require('path');
5864
const zuliprc = path.resolve(__dirname, 'zuliprc');
59-
zulip({ zuliprc }).then(zulip => {
65+
zulip({ zuliprc }).then((zulip) => {
6066
// The zulip object now contains the config from the zuliprc file
61-
zulip.streams.subscriptions.retrieve().then(res => {
67+
zulip.streams.subscriptions.retrieve().then((res) => {
6268
console.log(res);
6369
});
6470
});
@@ -98,7 +104,7 @@ zulip.callEndpoint('/messages', 'POST', params);
98104
| `zulip.accounts.retrieve()` | POST `/fetch_api_key` | returns a promise that you can use to retrieve your `API key`. |
99105
| `zulip.emojis.retrieve()` | GET `/realm/emoji` | retrieves the list of realm specific emojis. |
100106
| `zulip.events.retrieve()` | GET `/events` | retrieves events from a queue. You can pass it a params object with the id of the queue you are interested in, the last event id that you have received and wish to acknowledge. You can also specify whether the server should not block on this request until there is a new event (the default is to block). |
101-
| `zulip.messages.send()` | POST `/messages` | returns a promise that can be used to send a message.|
107+
| `zulip.messages.send()` | POST `/messages` | returns a promise that can be used to send a message. |
102108
| `zulip.messages.retrieve()` | GET `/messages` | returns a promise that can be used to retrieve messages from a stream. You need to specify the id of the message to be used as an anchor. Use `1000000000` to retrieve the most recent message, or [`zulip.users.me.pointer.retrieve()`](#fetching-a-pointer-for-a-user) to get the id of the last message the user read. |
103109
| `zulip.messages.render()` | POST `/messages/render` | returns a promise that can be used to get rendered HTML for a message text. |
104110
| `zulip.messages.update()` | PATCH `/messages/<msg_id>` | updates the content or topic of the message with the given `msg_id`. |
@@ -135,9 +141,7 @@ Use `npm test` to run the tests.
135141

136142
## Writing Tests
137143

138-
Currently, we have a simple testing framework which stubs our network
139-
requests and also allows us to test the input passed to it. This is what
140-
a sample test for an API endpoint looks like:
144+
Currently, we have a simple testing framework which stubs our network requests and also allows us to test the input passed to it. This is what a sample test for an API endpoint looks like:
141145

142146
```js
143147
const chai = require('chai');
@@ -153,18 +157,22 @@ describe('Users', () => {
153157
subject: 'test',
154158
content: 'sample test',
155159
};
156-
const validator = (url, options) => { // Function to test the network request parameters.
160+
const validator = (url, options) => {
161+
// Function to test the network request parameters.
157162
url.should.equal(`${common.config.apiURL}/users`);
158163
Object.keys(options.body.data).length.should.equal(4);
159164
options.body.data.subject.should.equal(params.subject);
160165
options.body.data.content.should.equal(params.content);
161166
};
162-
const output = { // The data returned by the API in JSON format.
167+
const output = {
168+
// The data returned by the API in JSON format.
163169
already_subscribed: {},
164170
result: 'success',
165171
};
166172
const stubs = common.getStubs(validator, output); // Stub the network modules.
167-
users(common.config).retrieve(params).should.eventually.have.property('result', 'success'); // Function call.
173+
users(common.config)
174+
.retrieve(params)
175+
.should.eventually.have.property('result', 'success'); // Function call.
168176
common.restoreStubs(stubs); // Restore the stubs.
169177
});
170178
});

examples/.eslintrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"rules": {
3-
"no-console": 0
4-
}
2+
"rules": {
3+
"no-console": 0
4+
}
55
}

examples/accounts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ zulip({
44
username: process.env.ZULIP_USERNAME,
55
apiKey: process.env.ZULIP_API_KEY,
66
realm: process.env.ZULIP_REALM,
7-
}).then((z) => z.accounts.retrieve())
7+
})
8+
.then((z) => z.accounts.retrieve())
89
.then(console.log);

examples/emojis.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const config = {
1717
// },
1818
// ...
1919

20-
zulip(config).then((z) => z.emojis.retrieve())
20+
zulip(config)
21+
.then((z) => z.emojis.retrieve())
2122
.then(console.log)
2223
.catch((err) => console.log(err.msg));

examples/events.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ const config = {
66
realm: process.env.ZULIP_REALM,
77
};
88

9-
zulip(config).then((z) => {
10-
// Retrieve events from a queue, blocking until there is an event (or the request timesout)
11-
const params = {
12-
queue_id: process.env.ZULIP_QUEUE_ID,
13-
last_event_id: -1,
14-
dont_block: false,
15-
};
16-
return z.events.retrieve(params).then(console.log);
17-
// Prints
18-
// { msg: '',
19-
// result: 'success',
20-
// handler_id: 2005928,
21-
// events:
22-
// [ { flags: [Object], message: [Object], type: 'message', id: 0 },
23-
// { type: 'heartbeat', id: 1 },
24-
// { flags: [], message: [Object], type: 'message', id: 2 },
25-
// { flags: [], message: [Object], type: 'message', id: 3 },
26-
// { flags: [], message: [Object], type: 'message', id: 4 } ] }
27-
}).catch((err) => console.log(err.message));
9+
zulip(config)
10+
.then((z) => {
11+
// Retrieve events from a queue, blocking until there is an event (or the request timesout)
12+
const params = {
13+
queue_id: process.env.ZULIP_QUEUE_ID,
14+
last_event_id: -1,
15+
dont_block: false,
16+
};
17+
return z.events.retrieve(params).then(console.log);
18+
// Prints
19+
// { msg: '',
20+
// result: 'success',
21+
// handler_id: 2005928,
22+
// events:
23+
// [ { flags: [Object], message: [Object], type: 'message', id: 0 },
24+
// { type: 'heartbeat', id: 1 },
25+
// { flags: [], message: [Object], type: 'message', id: 2 },
26+
// { flags: [], message: [Object], type: 'message', id: 3 },
27+
// { flags: [], message: [Object], type: 'message', id: 4 } ] }
28+
})
29+
.catch((err) => console.log(err.message));

examples/filters.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const config = {
66
realm: process.env.ZULIP_REALM,
77
};
88

9-
zulip(config).then((z) => {
10-
z.filters.retrieve().then(console.log);
11-
}).catch((err) => console.log(err.message));
9+
zulip(config)
10+
.then((z) => {
11+
z.filters.retrieve().then(console.log);
12+
})
13+
.catch((err) => console.log(err.message));

examples/init.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@ const config = {
99

1010
// Initialization with zuliprc
1111
const zuliprc = path.resolve(__dirname, 'zuliprc');
12-
zulip({ zuliprc }).then((z) => {
13-
// The zulip object now contains the API key
14-
console.log(z.config);
15-
return z.streams.subscriptions();
16-
}).then(console.log)
12+
zulip({ zuliprc })
13+
.then((z) => {
14+
// The zulip object now contains the API key
15+
console.log(z.config);
16+
return z.streams.subscriptions();
17+
})
18+
.then(console.log)
1719
.catch((err) => console.log(err.message));
1820

1921
// Initialization with username & API key
20-
zulip(config).then((z) => {
21-
// The zulip object now contains the API key
22-
console.log(z.config);
23-
return z.config.apiKey;
24-
}).then((key) => {
25-
// Initialization with API key
26-
config.apiKey = key;
27-
return zulip(config).streams.subscriptions();
28-
}).then(console.log)
22+
zulip(config)
23+
.then((z) => {
24+
// The zulip object now contains the API key
25+
console.log(z.config);
26+
return z.config.apiKey;
27+
})
28+
.then((key) => {
29+
// Initialization with API key
30+
config.apiKey = key;
31+
return zulip(config).streams.subscriptions();
32+
})
33+
.then(console.log)
2934
.catch((err) => console.log(err.message));

0 commit comments

Comments
 (0)