Skip to content

Commit

Permalink
Merge pull request #2 from rimiti/babel-v6-compliant
Browse files Browse the repository at this point in the history
Babel v6 compliant
  • Loading branch information
rimiti committed Aug 30, 2017
2 parents 4239911 + 3251f37 commit 866680b
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 116 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -15,7 +15,7 @@ $ npm install cosium-js-sdk
* ***Getting available timeslots***

```js
import cosium from 'cosium-js-sdk'
import * as cosium from 'cosium-js-sdk'

const params = {
siteCode: "c1",
Expand Down Expand Up @@ -55,7 +55,7 @@ N.B: The difference between startDate and endDate should be at maximum 20 days
* ***Create an appointment***

```js
import cosium from 'cosium-js-sdk'
import * as cosium from 'cosium-js-sdk'

const params = {
"siteCode": "c1",
Expand Down Expand Up @@ -103,7 +103,7 @@ request parameter for calling the function:
* ***Delete an appointment***

```js
import cosium from 'cosium-js-sdk'
import * as cosium from 'cosium-js-sdk'

const params = {
"siteCode": "c1",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cosium-js-sdk",
"version": "1.0.4",
"version": "1.1.0",
"description": "Cosium Javascript SDK",
"license": "MIT",
"main": "dist/lib/index.js",
Expand Down
87 changes: 76 additions & 11 deletions src/class/index.js
@@ -1,21 +1,86 @@
import SDK from './sdk'
import jsonOverride from 'json-override'
import Configuration from './configuration'
import 'isomorphic-fetch'
import Es6Promise from 'es6-promise'

let configuration
Es6Promise.polyfill()

export default {
export default class SDK extends Configuration {

constructor(config) {
super(config)
}

/**
* @description Override default configuration
* @param config
* @description Get available timeslots between two dates
* @param params
* @return {*|Promise<Promise>|Promise.<TResult>}
*/
configure: (config) => configuration = jsonOverride(configuration, config),
getAvailableTimeslots(params) {
const options = {
method: 'POST',
headers: this.headers,
body: JSON.stringify({
"siteCode": params.siteCode,
"startDate": params.startDate,
"endDate": params.endDate
})
}

return this.validateGetAvailableTimeslots(params)
.then(() => fetch(this.url + this.routes.availableTimeslots, options))
.then(response => this.httpStatus(response))
.then(response => this.errorCode(response))
}

/**
* @description Instantiate SDK class
* @returns {SDK}
* @description Create appointment
* @param params
* @return {*|Promise<Promise>|Promise.<TResult>}
*/
create: () => new SDK(configuration)
createAppointment(params) {
const options = {
method: 'POST',
headers: this.headers,
body: JSON.stringify({
"siteCode": params.siteCode,
"date": params.date,
"object": params.endDate,
"category": params.category,
"description": params.description,
"timeslotDurationInMinutes": params.timeslotDurationInMinutes,
"customer": {
"firstname": params.customer.firstname,
"lastname": params.customer.lastname,
"email": params.customer.email,
"phone": params.customer.phone
}
})
}

}
return this.validateCreateAppointment(params)
.then(() => fetch(this.url + this.routes.createAppointment, options))
.then(response => this.httpStatus(response))
.then(response => this.errorCode(response))
}

/**
* @description Cancel appointment
* @param params
* @return {*|Promise<Promise>|Promise.<TResult>}
*/
cancelAppointment(params) {
const options = {
method: 'POST',
headers: this.headers,
body: JSON.stringify({
"siteCode": params.siteCode,
"bookingId": params.bookingId
})
}

return this.validateCancelAppointment(params)
.then(() => fetch(this.url + this.routes.cancelAppointment, options))
.then(response => this.httpStatus(response))
.then(response => this.errorCode(response))
}
}
86 changes: 0 additions & 86 deletions src/class/sdk.js

This file was deleted.

23 changes: 19 additions & 4 deletions src/lib/index.js
@@ -1,6 +1,7 @@
import sdk from '../class'
import SDK from '../class'
import jsonOverride from 'json-override'

sdk.configure({
let configuration = {
"url": "",
"routes": {
"availableTimeslots": "/api/public/online-booking/query",
Expand All @@ -12,6 +13,20 @@ sdk.configure({
"username": "",
"password": ""
}
})
}

export default sdk
/**
* @description Override default configuration
* @param config
*/
export function configure(config) {
configuration = jsonOverride(configuration, config)
}

/**
* @description Instantiate SDK class
* @returns {SDK}
*/
export function create() {
return new SDK(configuration)
}
6 changes: 3 additions & 3 deletions test/appointments/cancel.js
@@ -1,8 +1,8 @@
import test from 'ava'
import sdk from '../../src/lib/index'
import SDK from '../../src/class/sdk'
import * as sdk from '../../src/lib'
import SDK from '../../src/class'
import mock from 'fetch-mock'
import {MissingMandatoryParameter, BookingNotFound} from '../../src/class/exceptions/index'
import {MissingMandatoryParameter, BookingNotFound} from '../../src/class/exceptions'

let instance = {}

Expand Down
6 changes: 3 additions & 3 deletions test/appointments/create.js
@@ -1,8 +1,8 @@
import test from 'ava'
import sdk from '../../src/lib'
import SDK from '../../src/class/sdk'
import * as sdk from '../../src/lib'
import SDK from '../../src/class'
import mock from 'fetch-mock'
import {UnknownCategoryCode, UnavailableSlot, MissingMandatoryParameter} from '../../src/class/exceptions/index'
import {UnknownCategoryCode, UnavailableSlot, MissingMandatoryParameter} from '../../src/class/exceptions'

let instance = {}

Expand Down
2 changes: 1 addition & 1 deletion test/class/configuration.js
@@ -1,5 +1,5 @@
import test from 'ava'
import sdk from '../../src/lib'
import * as sdk from '../../src/lib'
import {ConfigurationWrongCredentials, ConfigurationWrongFormat} from '../../src/class/exceptions'

test('Set empty username and password', t => {
Expand Down
6 changes: 3 additions & 3 deletions test/timeslots/get.js
@@ -1,6 +1,6 @@
import test from 'ava'
import sdk from '../../src/lib/index'
import SDK from '../../src/class/sdk'
import * as sdk from '../../src/lib'
import SDK from '../../src/class'
import mock from 'fetch-mock'
import {
MissingMandatoryParameter,
Expand All @@ -10,7 +10,7 @@ import {
NotAuthorized,
BadRequest,
UnknownError
} from '../../src/class/exceptions/index'
} from '../../src/class/exceptions'

let instance = {}

Expand Down

0 comments on commit 866680b

Please sign in to comment.