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

Commit f4dc822

Browse files
authored
Merge pull request #29 from deskbookers/develop
v2.1
2 parents a8ea495 + a606e4a commit f4dc822

21 files changed

+464
-53
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 2.1.0 - 2017-05-23
8+
### Added
9+
- `setTimezone`, `setLanguage` and `preferences` methods to `Account` resource
10+
- `Actions` resource with `report` method
11+
712
## 2.0.1 - 2017-05-12
813
### Added
914
- `createdAt` attribute to `Account` retrieval method

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ for (let workplace of workplaces) {
4343
* [`retrieve()`](docs/account.md#retrieve)
4444
* [`contexts(params)`](docs/account.md#contextsparams)
4545
* [`menu(context)`](docs/account.md#menucontext)
46+
* [`setLanguage(language)`](docs/account.md#setlanguagelanguage)
47+
* [`setTimezone(timezone)`](docs/account.md#settimezonetimezone)
48+
* [`preferences`](docs/account.md#preferences)
49+
* [`list(keys)`](docs/account.md#listkeys)
50+
* [`retrieve(key)`](docs/account.md#retrievekey)
51+
* [`update(params)`](docs/account.md#updateparams)
52+
* actions
53+
* [`report(params)`](docs/actions.md#reportparams)
4654
* workplaces
4755
* [`urgency(id, params)`](docs/workplaces.md#urgencyid-params)
4856
* events

docs/account.md

Lines changed: 113 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const password = 'm4c1nt0sh'
99
const user = await deskbookers.account.login(email, password)
1010
```
1111

12-
### Arguments
12+
#### Arguments
1313
Name | Type | Description | Required
1414
--- | --- | --- | ---
1515
email | String | User account email address | Yes
1616
password | String | User account password | Yes
1717

18-
### Example response
18+
#### Example response
1919

2020
```json
2121
{
@@ -39,15 +39,15 @@ const user = await deskbookers.account.signup({
3939
})
4040
```
4141

42-
### Arguments
42+
#### Arguments
4343
Name | Type | Description | Required
4444
--- | --- | --- | ---
4545
firstName | String | User first name | Yes
4646
lastName | String |User last name | Yes
4747
email | String | User account email address | Yes
4848
password | String | User account password | Yes
4949

50-
### Example response
50+
#### Example response
5151

5252
```json
5353
{
@@ -68,7 +68,7 @@ const email = '[email protected]'
6868
const res = await deskbookers.account.forgot(email)
6969
```
7070

71-
### Arguments
71+
#### Arguments
7272
Name | Type | Description | Required
7373
--- | --- | --- | ---
7474
email | String | Email address | Yes
@@ -81,7 +81,7 @@ Retrieves the current logged in user information.
8181
const user = await deskbookers.account.retrieve()
8282
```
8383

84-
### Example response
84+
#### Example response
8585

8686
```json
8787
{
@@ -105,14 +105,14 @@ const contexts = await deskbookers.account.contexts({
105105
})
106106
```
107107

108-
### Arguments
108+
#### Arguments
109109
Name | Type | Description | Required
110110
--- | --- | --- | ---
111111
query | String | Autocomplete value | No
112112
page | Number | Pagination number (1 indexed) | No
113113
supported | Array | Context type returned: 'provider' or 'venue' | No
114114

115-
### Example response
115+
#### Example response
116116

117117
```json
118118
[{
@@ -134,12 +134,12 @@ const context = contexts[0].context
134134
const menu = await deskbookers.account.menu(context)
135135
```
136136

137-
### Arguments
137+
#### Arguments
138138
Name | Type | Description | Required
139139
--- | --- | --- | ---
140140
context | String | Context code | Yes
141141

142-
### Example response
142+
#### Example response
143143
```json
144144
{
145145
"top": [{
@@ -204,3 +204,106 @@ context | String | Context code | Yes
204204
}]
205205
}
206206
```
207+
208+
## `setLanguage(language)`
209+
Store user language.
210+
211+
```js
212+
await deskbookers.account.setLanguage('en-gb')
213+
```
214+
215+
#### Arguments
216+
Name | Type | Description | Required
217+
--- | --- | --- | ---
218+
language | String | Language code | Yes
219+
220+
#### Example response
221+
```json
222+
true
223+
```
224+
225+
## `setTimezone(timezone)`
226+
Store user timezone.
227+
228+
```js
229+
await deskbookers.account.setTimezone('Europe/Amsterdam')
230+
```
231+
232+
#### Arguments
233+
Name | Type | Description | Required
234+
--- | --- | --- | ---
235+
timezone | String | Timezone | Yes
236+
237+
#### Example response
238+
```json
239+
true
240+
```
241+
242+
## `preferences`
243+
This sub-resource handles user account preferences.
244+
245+
### `list(keys)`
246+
247+
Returns a `Map` of account preferences. Specify an array of keys to return, or omit to return all.
248+
249+
```js
250+
// Get subset of keys
251+
const keys = ['city', 'country', 'language', 'timezone']
252+
await deskbookers.account.preferences.list(...keys)
253+
254+
// Get all
255+
await deskbookers.account.preferences.list()
256+
```
257+
258+
#### Arguments
259+
Name | Type | Description | Required
260+
--- | --- | --- | ---
261+
keys | Array | List of keys to retrieve | No
262+
263+
264+
#### Example response
265+
266+
```js
267+
Map {
268+
'city' => 'Amsterdam',
269+
'country' => 'Netherlands',
270+
'language' => 'nl-nl',
271+
'timezone' => 'Europe/Amsterdam'
272+
}
273+
```
274+
275+
### `retrieve(key)`
276+
277+
Retrieves the account preference value for the supplied key.
278+
279+
```js
280+
const city = await deskbookers.account.preferences.retrieve('city')
281+
console.log(city) // 'Amsterdam'
282+
```
283+
284+
### `update(params)`
285+
286+
Accepts an object of key/values to update. Returns a `Map` of all preferences.
287+
288+
```js
289+
const preferences = deskbookers.account.preferences
290+
291+
const prefs = await preferences.update({
292+
city: 'London',
293+
country: 'United Kingdom',
294+
timezone: 'Europe/London',
295+
language: 'en-gb'
296+
})
297+
298+
prefs.get('country') // 'United Kingdom'
299+
```
300+
301+
#### Example response
302+
```js
303+
Map {
304+
"city": "London",
305+
"country": "United Kingdom",
306+
"language": "en-gb",
307+
"timezone": "Europe/London"
308+
}
309+
```

docs/actions.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Actions
2+
3+
## `report(params)`
4+
Reports a problem to Deskbookers.
5+
6+
```js
7+
await deskbookers.actions.report({
8+
message: `This button ain't working!`,
9+
category: 'Bugs',
10+
browser: 'IE6',
11+
page: '/home',
12+
context: 'Provider mode',
13+
extras: [
14+
'day' => 'It was on a sunday',
15+
'weather' => 'It was rainy'
16+
]
17+
})
18+
```
19+
20+
#### Arguments
21+
Name | Type | Description | Required
22+
--- | --- | --- | ---
23+
message | String | Problem message | Yes
24+
category | String | Problem category | Yes
25+
browser | String | Browser the problem occured in | Yes
26+
page | String | Page the problem occured | Yes
27+
context | String | Context in which problem occured | Yes
28+
extras | Array | Extra information about problem | No
29+
30+
#### Example response
31+
32+
```json
33+
true
34+
```

docs/events.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Retrieves the unread count of the events, and returns a breakdown of unread coun
77
const unread = await deskbookers.events.unread()
88
```
99

10-
### Example response
10+
#### Example response
1111

1212
```json
1313
{
@@ -39,7 +39,7 @@ for await (let currentBatch of eventsIterator) {
3939
}
4040
```
4141

42-
### Arguments
42+
#### Arguments
4343
Name | Type | Description | Required
4444
--- | --- | --- | ---
4545
tabId | Number | Tab id | Yes
@@ -53,7 +53,7 @@ Gets all the events for a specific user, if only events of certain type where to
5353
const res = await deskbookers.events.getAllEvents(30, 0, ['booking'])
5454
```
5555

56-
### Arguments
56+
#### Arguments
5757
Name | Type | Description | Required
5858
--- | --- | --- | ---
5959
limit | Number | Tab id | Yes
@@ -68,7 +68,7 @@ Gets all the events for a specific user, if only events of certain type where to
6868
const res = await deskbookers.events.markAllAsRead(['booking'])
6969
```
7070

71-
### Arguments
71+
#### Arguments
7272
Name | Type | Description | Required
7373
--- | --- | --- | ---
7474
tags | Array | Tags to filter the results | No

docs/workplaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const urgency = await deskbookers.workplaces.urgency(12345, {
1414
})
1515
```
1616

17-
### Arguments
17+
#### Arguments
1818
Name | Type | Description | Required
1919
--- | --- | --- | ---
2020
id | Number | Workplace ID | Yes

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deskbookers",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "Deskbookers API JavaScript SDK",
55
"main": "dist/index.js",
66
"scripts": {
@@ -30,6 +30,7 @@
3030
"moment": "^2.17.1",
3131
"phpurlencode": "^1.0.0",
3232
"qs": "^6.3.0",
33+
"ramda": "^0.23.0",
3334
"rndm": "^1.2.0",
3435
"url": "^0.11.0"
3536
},
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export default class DeskbookersError extends Error {
22
constructor (message) {
3-
super()
4-
this.type = 'DeskbookersError'
5-
this.message = message
3+
super(message)
4+
this.name = 'DeskbookersError'
65
}
76
}

src/InvalidResponseError.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import DeskbookersError from './DeskbookersError'
2+
3+
const MAX_ERROR_LENGTH = 100
4+
5+
export default class InvalidResponseError extends DeskbookersError {
6+
constructor (text) {
7+
// Prepare text
8+
text = `${text || ''}`
9+
if (text.length > MAX_ERROR_LENGTH) {
10+
text = `${text.substr(0, MAX_ERROR_LENGTH)}...`
11+
}
12+
13+
super(`Invalid API response received: ${text}`)
14+
this.name = 'InvalidResponseError'
15+
}
16+
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Account from './resources/Account'
1+
import Account from './resources/account'
22
import Cart from './resources/Cart'
33
import Events from './resources/Events'
44
import Workplaces from './resources/Workplaces'

0 commit comments

Comments
 (0)