Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.

Commit c4b2b67

Browse files
authored
Merge pull request #21 from deskbookers/develop
v2.0.0
2 parents c244082 + b1a0ff2 commit c4b2b67

File tree

4 files changed

+82
-7
lines changed

4 files changed

+82
-7
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ And every resource returns a [`Promise`](https://developer.mozilla.org/en/docs/W
2828

2929
```js
3030

31-
const workplaces = await deskbookers.workplaces.list(params)
31+
const workplaces = await deskbookers.workplaces.retrieve(params)
3232
for (let workplace of workplaces) {
3333
// Use workplace data
3434
}
@@ -47,4 +47,6 @@ for (let workplace of workplaces) {
4747
* [`urgency(id, params)`](docs/workplaces.md#urgencyid-params)
4848
* events
4949
* [`unread()`](docs/events.md#unread)
50-
* [`list(tabId, limit)`](docs/events.md##listtabid-limit)
50+
* [`retrieve(tabId, limit)`](docs/events.md##retrievetabid-limit)
51+
* [`list(limit, offset, tags)`](docs/events.md##list)
52+
* [`markAllAsRead(tags)`](docs/events.md##mark-all-as-read)

docs/events.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ const unread = await deskbookers.events.unread()
2020
}
2121
```
2222

23-
## `list(tabId, limit)`
23+
## `retrieve(tabId, limit)`
2424
Lists the events for a given tab `id`. Returns an [async generator](https://github.com/tc39/proposal-async-iteration), or throws and `Error` if no events are returned.
2525

2626
```js
2727
const tabId = 1
2828
const eventsLimit = 10
29-
const eventsIterator = deskbookers.events.list(tabId, eventsLimit)
29+
const eventsIterator = deskbookers.events.retrieve(tabId, eventsLimit)
3030

3131

3232
// Use async generator directly
@@ -44,3 +44,31 @@ Name | Type | Description | Required
4444
--- | --- | --- | ---
4545
tabId | Number | Tab id | Yes
4646
eventsLimit | Number | Amount of events to return | Yes
47+
48+
## `list(limit, offset, tags)`
49+
Gets all the events for a specific user, if only events of certain type where to be required you can specify them in the tags array.
50+
51+
```js
52+
// gets the first page of results of all the events with the tag 'booking'
53+
const res = await deskbookers.events.getAllEvents(30, 0, ['booking'])
54+
```
55+
56+
### Arguments
57+
Name | Type | Description | Required
58+
--- | --- | --- | ---
59+
limit | Number | Tab id | Yes
60+
offset | Number | Tab id | Yes
61+
tags | Array | Tags to filter the results | No
62+
63+
## `markAllAsRead(tags)`
64+
Gets all the events for a specific user, if only events of certain type where to be required you can specify them in the tags array.
65+
66+
```js
67+
// mark all events with the tag 'booking' as read
68+
const res = await deskbookers.events.markAllAsRead(['booking'])
69+
```
70+
71+
### Arguments
72+
Name | Type | Description | Required
73+
--- | --- | --- | ---
74+
tags | Array | Tags to filter the results | No

src/resources/Events.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class Events extends Resource {
1212
})
1313
}
1414

15-
async list (tabId = null, limit = 10) {
15+
async retrieve (tabId = null, limit = 10) {
1616
if (!tabId) {
1717
throw new Error('No tab id')
1818
}
@@ -44,6 +44,28 @@ export default class Events extends Resource {
4444
}
4545
}
4646

47+
async list (limit, offset, tags = []) {
48+
return await this.request({
49+
method: 'GET',
50+
path: 'event',
51+
params: {
52+
limit,
53+
offset,
54+
tags
55+
}
56+
})
57+
}
58+
59+
async markAllAsRead (tags = []) {
60+
return await this.request({
61+
method: 'POST',
62+
path: 'event/read',
63+
params: {
64+
tags
65+
}
66+
})
67+
}
68+
4769
async getEvents (tabId, startId, limit, offset) {
4870
return await this.request({
4971
method: 'GET',

test/events.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,31 @@ test('Events', async t => {
2929
const unread = await deskbookers.events.unread()
3030
const tabId = unread.tabs[0].id
3131

32-
// List events
33-
const events = await deskbookers.events.list(tabId)
32+
// Retrieve events
33+
const events = await deskbookers.events.retrieve(tabId)
3434
const firstBatch = await events.next()
3535
t.truthy(firstBatch.value.length)
3636
})
37+
38+
test('Can retrieve first page containing all events', async t => {
39+
await deskbookers.account.login(
40+
process.env.LOGIN_EMAIL,
41+
process.env.LOGIN_PASSWORD
42+
)
43+
44+
const res = await deskbookers.events.list(30, 0)
45+
46+
t.truthy(Array.isArray(res))
47+
})
48+
49+
test('Can mark all events as read', async t => {
50+
await deskbookers.account.login(
51+
process.env.LOGIN_EMAIL,
52+
process.env.LOGIN_PASSWORD
53+
)
54+
55+
const res = await deskbookers.events.markAllAsRead()
56+
57+
t.truthy(res)
58+
})
59+

0 commit comments

Comments
 (0)