Skip to content

Commit

Permalink
v0.2.0 (#31)
Browse files Browse the repository at this point in the history
* updating to latest uuid-based version of Gonebusy API [finishes: #154308503]
  • Loading branch information
alexagranov authored Jan 15, 2018
1 parent e0c7853 commit 20f9359
Show file tree
Hide file tree
Showing 102 changed files with 2,189 additions and 1,026 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/lib
/node_modules
7 changes: 3 additions & 4 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ parser: "babel-eslint"
rules:
consistent-return: 0
comma-dangle: 0
curly:
- 2
- multi
curly: 0
func-names:
- 2
- never
- as-needed
func-style:
- 2
- expression
Expand All @@ -32,6 +30,7 @@ rules:
- always
strict: 0
env:
commonjs: true
mocha: true
browser: true
node: true
Expand Down
19 changes: 3 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
language: node_js
node_js:
- '6.8'
- '6.7'
- '6.6'
- '6.5'
- '6.4'
- '6.3'
- '6.2'
- '6.1'
- '6.0'
- '5'
- '5.11'
- '5.10'
- '5.9'
- '5.8'
- '5.7'
- '5.6'
- '7.10'
- '6.12'
- '5.12'
notifications:
slack:
secure: ht5oAlTQUv+NkLso6Wb9T89cLbNC7kwdIf0rm9cAjtnuu4oarXRDzOWZBtAayguhHrRiY3VKbTKIllOHmhb0gYRv4gKf+4L3AES0RSq5cLYiZNdCofT1Dj0OeAb2p9cpj/AyIhr5S/O+QvVb2ixmgmRproYZh97GFZqSrXP0HNqQhXSR3fVaE0fJSu6tWETDbvU6r7M5SAIwxLprSO4LboE8kqiXGGqgU+lVYsDsjEy9Lhd1Y33cVeA+73ubvau+PN75oubjBoqDtipLii2aqi1M6p5UtfPWeG2eu06R3yEdWBQ5Uc94qsFep/Fd+6a9auXZTO32fjF8mgnivr3sH+WiX611eXcQPq2iziNBo2zjK2Jx1Vg8ezM39YJnfnDwIYNfBuc5Ui1hBjuMQqByNTMfErJ2gzA9FdT8o0GvytAFeLg9GRXaJPel1ak1qJkT3KqPrz+tYb+p0uQLcLpdLkTn6xM0R3Dy4P/l5FnDFg1ub7kSB9lTQR2e+p1o7wwzV2m65yYzyJeqTRlRGF95ewgJEZutBBR5byXXEt7D1HZdnhBzGRlx8hfbha6FQaqBKtLx6lF2xKZtWaB1MJOumERO3oY6voqbkppFhbTQNuCySKwqra2etgoz/y67tKrwwS9LGJTG7LjYOjgFGkJl3WABghPMU8IKBsz4vMjlJ64=
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.2.0] - 2018-01-14 ##
## BREAKING CHANGE
- [#31](https://github.com/gonebusy/gonebusy-nodejs-client/pull/31)
- Updated SDK to pass string ids in UUID format for all API endpoints that refer to user, resource, service, schedule, time_window, and pricing_model ids.
- Date parameters to BookingsController.cancelBookingById and ServicesController.getServiceAvailableSlotsById should now be constructed with moment, rather than simply a String in 'YYYY-MM-DD' form.

### Updated
- All tests to reflect use of UUID params as well as moment datetime objects.

## [0.1.3] - 2017-06-18 ##
### Added
- [#30](https://github.com/gonebusy/gonebusy-nodejs-client/pull/30) - Booking creation/update now accept optional :name and :description
Expand Down
132 changes: 53 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Then try the following:
```js
gonebusy.Configuration.currentEnvironment = 'sandbox'
```

1. Configure your API Key:

```js
Expand All @@ -46,31 +46,35 @@ Then try the following:
1. Get a list of Services for the current user:

```js
gonebusy.ServicesController.getServices({authorization}).then((result)=>{
gonebusy.ServicesController.getServices(authorization).then((result)=>{
console.log(result);
}).catch((e)=>{
console.log(e);
})
```

Output of `console.log()`:
```
BaseModel {
services:
[ BaseModel {
categories: [],
description: 'A Service for Samples',
duration: 30,
maxDuration: 30,
id: 197264885,
GetServicesResponse {
services:
[ EntitiesServiceResponse {
id: '3f58d6bb-59ba-4e7f-aeaa-2544c384d9d7',
ownerId: '281ce067-50dc-4746-ac78-ded592655699',
name: 'name',
shortName: 'short_name',
duration: 15,
maxDuration: 15,
description: A Service for Samples,
priceModelId: '5d9cea4f-9e6a-46bd-9c7f-6195a88753eb',
isActive: true,
name: 'Sample Service',
ownerId: 8552697701,
priceModelId: 2,
resources: [Object],
shortName: null } ] }
categories: [],
resources: [],
schedules: [] },
...
]
}
```

## Using Request Body Helpers

For any controller operations that expect a request body, or a set of params, there exist CreateXXXBody/UpdateXXXByIdBody/etc. helper objects corresponding to the operation. The helper objects allow your request code to be constructed with params that conform to the GoneBusy API while still supporting Node/ES6-style property access.
Expand All @@ -80,100 +84,70 @@ The following is an example of how to use the CreateServiceBody helper object wh
1. Create an instance of CreateServiceBody to wrap your desired attributes into an object:

```js
var new_service = new CreateServiceBody({
var new_service = new gonebusy.CreateServiceBody({
name: 'My Sample Service',
duration: 30,
max_duration: 30,
description: 'Sample Service for Testing',
short_name: 'MyService'
});
```

2. Note that the property passed to the constructor uses snake_case but the underlying `BaseModel` object allows access via ES6 camelCase or even a traditional getter:

```js
new_service.shortName;
new_service.getShortName();
```

Both output:
```js
'MyService'
```

Setters work as well:
```js
new_service.setShortName('My Sample x2');
new_service.getShortName();
```

Outputs:
```js
'My Sample x2'
```

3. Let's send off the request to create our new Service:

```js
gonebusy.ServicesController.createService({
authorization: 'Token ac98ed08b5b0a9e7c43a233aeba841ce',
createServiceBody: new_service
}).then((result)=>{
console.log(result);
}).catch((e)=>{
console.log(e);
})
gonebusy.ServicesController.createService(
'Token ac98ed08b5b0a9e7c43a233aeba841ce',
new_service
).then((result)=>{
console.log(result);
}).catch((e)=>{
console.log(e);
})
```

Output of `console.log()`:
```js
BaseModel {
service:
BaseModel {
categories: [],
description: 'Sample Service for Testing',
duration: 30,
maxDuration: 30,
id: 4667058921,
isActive: true,
name: 'My Sample Service',
ownerId: 6845037920,
priceModelId: 3,
resources: [ 512294687 ],
shortName: 'My Sample x2' } }
CreateServiceResponse {
service:
EntitiesServiceResponse {
id: 'eaf76f54-f994-11e7-9c01-4fba28763be3',
ownerId: '00000000-0000-0000-0000-000000000080',
name: 'My Sample Service',
shortName: 'MyService x2',
duration: 30,
maxDuration: 30,
description: 'Sample Service for Testing',
priceModelId: 'eafb2bbc-f994-11e7-9c03-83290988f60b',
isActive: true,
categories: [],
resources: [ '00000000-0000-0000-0000-000000000034' ],
schedules: [ 'eb0246c2-f994-11e7-9c04-639c2510affb' ] } }
```

## Using Response Helpers

Just as with Request Body helpers, there are Response helper objects corresponding to each CreateXXXBody/UpdateXXXByIdBody/etc. operation.

When using Promises, the success result will be a Response instance as follows:

```js
gonebusy.ServicesController.createService({
authorization: 'Token ac98ed08b5b0a9e7c43a233aeba841ce',
createServiceBody: new_service
}).then((resp)=>{
console.log(resp.getService());
}).catch((e)=>{
console.log(e);
})
```

Output of `console.log()`:
```js
BaseModel {
categories: [],
description: 'Sample Service for Testing',
duration: 30,
maxDuration: 30,
id: 4667058921,
isActive: true,
name: 'My Sample Service',
ownerId: 6845037920,
priceModelId: 3,
resources: [ 512294687 ],
shortName: 'My Sample x2' }
```
## Using Response Helpers

In this example, the result of `resp.getService()` is an instance of `EntitiesServiceResponse`.
Just as with Request Body helpers, there are Response helper objects corresponding to each CreateXXXBody/UpdateXXXByIdBody/etc. operation.
32 changes: 29 additions & 3 deletions lib/APIHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ class APIHelper {
return first;
}
const merged = first;
const attrNamesSecond = Object.keys(second);
for (let iter = 0; iter < attrNamesSecond.length; iter += 1) {
merged[attrNamesSecond[iter]] = second[attrNamesSecond[iter]];
if (second !== undefined && second !== null) {
const attrNamesSecond = Object.keys(second);
for (let iter = 0; iter < attrNamesSecond.length; iter += 1) {
merged[attrNamesSecond[iter]] = second[attrNamesSecond[iter]];
}
}
return merged;
}
Expand Down Expand Up @@ -257,6 +259,30 @@ class APIHelper {
}
return query.length ? query.substr(0, query.length - 1) : query;
}

/**
* Returns Datetime string value for field
* @param value {object} Datetime object
* @param type {string} The Datetime format of the date object (value) passed in
* @returns {string} Stringified Datetime object
*/
static stringifyDateTime(value, type) {
if (value === null || value === undefined) {
return null;
}
switch (type) {
case 'unixtimestamp':
return value.getTime();
case 'rfc1123':
return value.toUTCString();
case 'rfc3339':
return value.format();
case 'date':
return value.format('YYYY-MM-DD');
default:
return value.format('YYYY-MM-DD');
}
}
}

module.exports = APIHelper;
Loading

0 comments on commit 20f9359

Please sign in to comment.