Skip to content

Commit

Permalink
Merge pull request #1 from rimiti/api-implementation
Browse files Browse the repository at this point in the history
Api implementation
  • Loading branch information
rimiti committed Aug 28, 2017
2 parents 2abb353 + 13b6a27 commit d04dc7b
Show file tree
Hide file tree
Showing 26 changed files with 934 additions and 47 deletions.
115 changes: 115 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,121 @@ Cosium Javascript SDK
$ npm install cosium-js-sdk
```

## Available methods

* ***Getting available timeslots***

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

const params = {
siteCode: "c1",
startDate: "2017-09-23T12:00:00.000Z",
endDate: "2017-09-23T13:00:00.000Z"
}

cosium.getAvailableTimeslots(params).then((response) => {
console.log(response)
})
```
Response body example:

```json
{
"errorCode": null,
"errorMessage": null,
"availableTimeSlots": [
{"date": "2017-09-23T12:00:00.000+0000", "qualifications": ["CONTACT_LENS", "OPTIC", "HEARING_AID"]},
{"date": "2017-09-23T12:30:00.000+0000", "qualifications": ["CONTACT_LENS", "OPTIC", "HEARING_AID"]}
]
}
```

request parameter for calling the function:

| Name | description | Required |
| ------------- |:---------------------:| ---------:|
| siteCode | requested center code | true |
| startDate | start date | true |
| endDate | end date | true |

N.B: The difference between startDate and endDate should be at maximum 20 days

<br/>

* ***Create an appointment***

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

const params = {
"siteCode": "c1",
"description": "my description",
"qualification": "HEARING_AID",
"category": "consultation1",
"customer":
{
"firstname": "Jean",
"lastname": "Dupont",
"email": "jean.dupont@gmail.com"
}
}

cosium.createAppointment(params).then((response) => {
console.log(response)
})
```
Response body example:

```json
{"errorCode": null, "bookingId": "1935472128"}
```

request parameter for calling the function:

| Name | description | Required |
| ------------------------- |:--------------------------------------:| ---------:|
| siteCode | requested center code | true |
| date | date of appointment | true |
| object | object of the appointment | true |
| category | code of appointment category | true |
| description | description of the appointment | false |
| timeslotDurationInMinutes | duration in minutes of the slot | false |
| customer | customer informations | true |
| customer.firstname | firstname of customer | true |
| customer.lastname | lastname of customer | true |
| customer.email | email of customer | false |
| qualification | desired qualification of the seller | false |

<br/>

* ***Delete an appointment***

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

const params = {
"siteCode": "c1",
"bookingId": "20"
}

cosium.cancelAppointment(params).then((response) => {
console.log(response)
})
```
Response body example:

```json
{"errorCode": null}
```

request parameter for calling the function:

| Name | description | Required |
| ------------- |:-----------------------------------------------------:| ---------:|
| siteCode | requested center code | true |
| bookingId | unique identifier of the reservation to be deleted | true |

## Tests
```js
// Run tests
Expand Down
81 changes: 77 additions & 4 deletions package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -32,14 +32,18 @@
},
"homepage": "https://github.com/rimiti/cosium-js-sdk#readme",
"dependencies": {
"es6-promise": "^4.1.1",
"isomorphic-fetch": "^2.2.1",
"json-override": "^0.2.0",
"moment": "^2.18.1",
"source-map-support": "^0.4.15"
},
"devDependencies": {
"ava": "^0.22.0",
"babel-preset-es2015": "^6.24.1",
"coveralls": "^2.13.1",
"del": "^3.0.0",
"fetch-mock": "^5.12.2",
"gulp": "^3.9.1",
"gulp-ava": "^0.18.0",
"gulp-babel": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/class/authentication.js
Expand Up @@ -26,7 +26,7 @@ export default class Authentication {

getAuthentication() {
const base64 = new Buffer(`${this.username}:${this.password}`).toString('base64')
return {header: {Authorization: `Basic ${base64}`}}
return `Basic ${base64}`
}

_checkConfiguration() {
Expand Down
37 changes: 33 additions & 4 deletions src/class/configuration.js
@@ -1,13 +1,15 @@
import {ConfigurationWrongFormat} from './exceptions'
import Authentication from './authentication'
import Validation from './validation'

export default class Configuration {
export default class Configuration extends Validation {

/**
* @description Auto-hydrate object from configuration
* @param config
*/
constructor(config) {
super()
this._hydrate(config, this._itemsToHydrate())
}

Expand All @@ -28,25 +30,52 @@ export default class Configuration {
this._credentials = new Authentication(value)
}

get url() {
return this._url
}

set url(value) {
this._url = value
}

get routes() {
return this._routes
}

set routes(value) {
this._routes = value
}

/**
* @description Get headers pre formatted
* @returns {{Authorization: ({header}|*), Accept: string, Content-Type: string}}
*/
get headers() {
return {
'Authorization': this._credentials.getAuthentication(),
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}

/**
* @description Hydrate object from configuration settings
* @param obj
* @param attributes
* @private
*/
_hydrate(obj, attributes) {
if (!obj) return
for (let item of attributes) {
this[item] = (obj[item]) ? obj[item] : ''
}
}

/**
* @description Return array with items names to hydrate
* @return {[string,string]}
* @returns {[string,string,string,string]}
* @private
*/
_itemsToHydrate() {
return ['format', 'credentials']
return ['format', 'credentials', 'url', 'routes']
}
}
10 changes: 10 additions & 0 deletions src/class/exceptions/api/bad_request.js
@@ -0,0 +1,10 @@
import Exception from '../base'

export default class BadRequest extends Exception {

constructor(message) {
super()
this.name = this.constructor.name
this.message = message || `Bad request`
}
}

0 comments on commit d04dc7b

Please sign in to comment.