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

Commit 4f5fe0f

Browse files
authored
Merge pull request #51 from deskbookers/develop
Dev -> Master
2 parents 5c4e3aa + 5bf6c3d commit 4f5fe0f

File tree

7 files changed

+239
-3
lines changed

7 files changed

+239
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ 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+
## 5.1.0 - 2017-08-01
8+
### Changes
9+
- Added `retrieve` method to the `Venues` resource.
10+
711
## 5.0.0 - 2017-07-24
812
### Changes
913
- Added parameter `country` on `Features` list and changed for object parameters

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,8 @@ for (let workplace of workplaces) {
7676
* [`flagAsRead(userId, body, id)`](docs/notifications.md#flagasreaduserid-body-id)
7777
* [`delete()`](docs/notifications.md#delete)
7878
* bookings
79-
* [`month(date, venueId)`](docs/bookings.md#monthdate-venueid)
79+
* [`month(date, venueId)`](docs/bookings.md#monthdate-venueid)
80+
* venues
81+
* [`retrieve(venueId, { fields, params })`](docs/venues.md#retrievevenueid--fields-params-)
82+
* [`getPaymentSettings(venueId)`](docs/venues.md#getpaymentsettings-venueId)
83+
* [`savePaymentSettings(venueId, params)`](docs/venues.md#savepaymentsettings-venueId-params)

docs/venues.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Venues
2+
3+
## `retrieve(venueId, { fields, params })`
4+
Retrieves a single venue.
5+
6+
```js
7+
const venueId = 11710
8+
const fields = ['id', 'image_urls']
9+
const params = { width: 360, height: 240 }
10+
await deskbookers.venues.retrieve(venueId, { fields, params })
11+
```
12+
13+
#### Arguments
14+
Name | Type | Description | Required
15+
--- | --- | --- | ---
16+
venueId | Number | Venue ID | Yes
17+
fields | Array|Object | Fields whitelist | No
18+
params | Object | Extra arguments | No
19+
20+
## `savePaymentSettings(venueId, params)`
21+
Retrieves the payment settings data for a venue.
22+
23+
## `getPaymentSettings(venueId)`
24+
Retrieves a single space.
25+
26+
```js
27+
const venueId = 11710
28+
await deskbookers.venues.getPaymentSettings(venueId)
29+
```
30+
31+
#### Arguments
32+
Name | Type | Description | Required
33+
--- | --- | --- | ---
34+
id | Number | Venue ID | Yes
35+
36+
## `savePaymentSettings(venueId, params)`
37+
Retrieves the payment settings data for a venue.
38+
39+
```js
40+
await deskbookers.venues.savePaymentSettings(11710, {
41+
name: 'aaa',
42+
bankInfo: 'NL01BANK012345678',
43+
bic: 'ABCDEF01',
44+
tax: '1234',
45+
company: 'hockerson',
46+
debtor: '12345',
47+
mark: 'rarara',
48+
address:
49+
{ country: 'The Netherlands',
50+
addressLine1: 'a',
51+
postalcode: '1012AK',
52+
place: 'lolala',
53+
telephonenumber: '+31610513231',
54+
telephonenumber2: '+31123412345',
55+
56+
}
57+
})
58+
```
59+
60+
#### Arguments
61+
Name | Type | Description | Required
62+
--- | --- | --- | ---
63+
id | Number | Venue ID | Yes
64+
params | `Object` | PaymentSettings | Yes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deskbookers",
3-
"version": "5.0.0",
3+
"version": "5.1.0",
44
"description": "Deskbookers API JavaScript SDK",
55
"main": "dist/index.js",
66
"scripts": {

src/resources/Venues.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import Resource from './Resource'
2+
import { DeskbookersError } from '../errors'
3+
4+
export default class Venues extends Resource {
5+
constructor (api) {
6+
super(api)
7+
this.endpoint = 'location'
8+
}
9+
10+
/**
11+
* List payment settings by venue
12+
*
13+
* @param {int} venueId - Venue Id body.
14+
* @return {Object}
15+
*/
16+
async getPaymentSettings (venueId) {
17+
return this.request({
18+
method: 'GET',
19+
path: `location/${venueId}/payment-settings`
20+
})
21+
}
22+
/**
23+
* Create payment settings to venue
24+
*
25+
* @param {int} venueId - Venue Id body.
26+
* @param {Object} paymentSettings Venue Payment Settings
27+
* @return {Object}
28+
*/
29+
async savePaymentSettings (venueId, paymentSettings) {
30+
return this.request({
31+
method: 'POST',
32+
path: `location/${venueId}/payment-settings`,
33+
params: {
34+
data: paymentSettings
35+
}
36+
})
37+
}
38+
39+
/**
40+
* Retrieve a venue
41+
*
42+
* @param {int} venueId - Venue Id
43+
* @param {Array|Object} fields - Fields whitelist
44+
* @param {Object} params - Extra arguments
45+
* @return {Object}
46+
*/
47+
async retrieve (venueId, { fields = [], params = {} } = {}) {
48+
return await this.request({
49+
method: 'GET',
50+
path: `/${this.endpoint}/${venueId}`,
51+
fields,
52+
params
53+
})
54+
}
55+
}

src/resources/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Features from './Features'
77
import Spaces from './Spaces'
88
import Notifications from './Notifications'
99
import Bookings from './Bookings'
10+
import Venues from './Venues'
1011

1112
export default {
1213
account: Account,
@@ -17,5 +18,6 @@ export default {
1718
features: Features,
1819
spaces: Spaces,
1920
notifications: Notifications,
20-
bookings: Bookings
21+
bookings: Bookings,
22+
venues: Venues
2123
}

test/venues.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import dotenv from 'dotenv'
2+
import 'fetch-everywhere'
3+
import test from 'ava'
4+
import Deskbookers from '../src'
5+
dotenv.load()
6+
7+
function client () {
8+
return new Deskbookers({
9+
https: process.env.API_HTTPS === 'true',
10+
host: process.env.API_HOST
11+
})
12+
}
13+
14+
test('get financial settings', async t => {
15+
const deskbookers = client()
16+
17+
await deskbookers.account.login(
18+
process.env.LOGIN_EMAIL,
19+
process.env.LOGIN_PASSWORD
20+
)
21+
22+
const paymentSettings = await deskbookers.venues.getPaymentSettings(11710)
23+
t.truthy(paymentSettings)
24+
})
25+
26+
test('save financial settings', async t => {
27+
const deskbookers = client()
28+
29+
await deskbookers.account.login(
30+
process.env.LOGIN_EMAIL,
31+
process.env.LOGIN_PASSWORD
32+
)
33+
34+
let payment = {
35+
name: 'aaa222',
36+
bankInfo: 'NL01BANK012345222',
37+
bic: 'ABCDEF22',
38+
tax: '1234222',
39+
company: 'hockerson2',
40+
debtor: '1234522',
41+
mark: 'rarara22',
42+
address:
43+
{ country: 'The Netherlands',
44+
addressLine1: 'a2',
45+
postalcode: '2222AK',
46+
place: 'lolala2',
47+
telephonenumber: '+31610512222',
48+
telephonenumber2: '+31123412222',
49+
50+
}
51+
}
52+
const saved = await deskbookers.venues.savePaymentSettings(11710, payment)
53+
const paymentSettings = await deskbookers.venues.getPaymentSettings(11710)
54+
55+
t.truthy(saved)
56+
})
57+
58+
test('retrieve a venue', async t => {
59+
const venueId = 12686
60+
const width = 360
61+
const height = 240
62+
63+
// Prepare API
64+
const deskbookers = client()
65+
await deskbookers.account.login(
66+
process.env.LOGIN_EMAIL,
67+
process.env.LOGIN_PASSWORD
68+
)
69+
70+
// Test simple call
71+
const venue1 = await deskbookers.venues.retrieve(venueId)
72+
t.truthy(typeof venue1 === 'object')
73+
t.is(venue1.id, venueId)
74+
t.truthy(venue1.name)
75+
t.truthy(venue1.timezone)
76+
t.truthy(venue1.lang)
77+
t.truthy(venue1.slug)
78+
79+
// Test fields
80+
const venue2 = await deskbookers.venues.retrieve(venueId, {
81+
fields: ['id', 'name', 'address_object']
82+
})
83+
t.truthy(typeof venue2 === 'object')
84+
t.is(venue2.id, venueId)
85+
t.is(venue2.name, venue1.name)
86+
t.is(
87+
JSON.stringify(venue2.address_object),
88+
JSON.stringify(venue1.address_object)
89+
)
90+
t.falsy(venue2.timezone)
91+
92+
// Test image params
93+
const venue3 = await deskbookers.venues.retrieve(venueId, {
94+
params: {
95+
width,
96+
height,
97+
crop: true
98+
},
99+
fields: ['id', 'image_urls']
100+
})
101+
t.truthy(typeof venue3 === 'object')
102+
t.is(venue3.id, venueId)
103+
t.truthy(Array.isArray(venue3.image_urls))
104+
t.truthy(venue3.image_urls.reduce((result, url) => {
105+
return result && url.indexOf(`${width}x${height}x1`) !== -1
106+
}, true))
107+
})

0 commit comments

Comments
 (0)