dispatch-node-sdk
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -54,2 +54,8 @@ import * as endpoints from '../endpoints'; | ||
}, | ||
createAppointment: (data = {}) => { | ||
return client.doAuthenticatedRequest('POST', endpoints.APPOINTMENTS, Object.assign({}, data, { | ||
job_id: id, | ||
})); | ||
}, | ||
}; | ||
@@ -56,0 +62,0 @@ }; |
@@ -114,2 +114,19 @@ import expect from 'expect'; | ||
}); | ||
describe('createAppointment', () => { | ||
it('should call endpoint with correct body', () => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
const scope = nock('https://api.dispatch.me') | ||
.post('/v1/appointments', { | ||
job_id: 123, | ||
foo: 'bar', | ||
}) | ||
.reply(200); | ||
client.entities.job(123).createAppointment({ | ||
foo: 'bar', | ||
}); | ||
expect(scope.isDone()).toEqual(true); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "dispatch-node-sdk", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "High- and low-level libraries for interacting with the Dispatch API", | ||
@@ -24,2 +24,3 @@ "main": "dist/lib/index.js", | ||
"babel-preset-es2015": "6.x.x", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babel-register": "6.x.x", | ||
@@ -26,0 +27,0 @@ "eslint": "^2.9.0", |
@@ -34,4 +34,4 @@ Dispatch JavaScript SDK | ||
```javascript | ||
client.loginEmailPassword(email, password).then(token => { | ||
return client.identifyUser() | ||
client.loginEmailPassword(email, password).then(() => { | ||
return client.identifyUser(); | ||
}).then(user => { | ||
@@ -54,11 +54,21 @@ console.log('Current user is', user); | ||
#### Login with limited-use auth token | ||
```javascript | ||
client.loginAuthToken(token).then(() => { | ||
return client.identifyUser(); | ||
}).then(user => { | ||
console.log('Current user is', user); | ||
}).catch(err => console.error('Failed to log in:', err)); | ||
``` | ||
### Interacting with Data | ||
By default, the SDK wraps each entity in a `Model` class, (very similar to a Backbone model), which exposes methods like `refresh`, `set`, `get`, and `save`. | ||
#### Get a list of models | ||
For example, get a list of unscheduled jobs: | ||
You can use the `getCollection` method directly, like this: | ||
```javascript | ||
client.getCollection('/v1/jobs', { | ||
status_eq: 'unscheduled' | ||
filter: { | ||
status_eq: 'unscheduled', | ||
} | ||
}).then(jobs => { | ||
@@ -69,11 +79,17 @@ jobs.forEach(job => console.log('Got job ID ' + job.get('id'))); | ||
#### Updating a model | ||
Once you have a model, you can modify it and save it: | ||
Or, use the defined collection, like this: | ||
```javascript | ||
model.set('status', 'scheduled'); | ||
client.entities.jobs.get({ | ||
filter: { | ||
status_eq: 'unscheduled', | ||
} | ||
}); | ||
``` | ||
model.save().then(() => { | ||
alert('Saved!'); | ||
}).catch(err => alert('Error saving job!')); | ||
#### Creating a Model | ||
```javascript | ||
client.entities.jobs.create({ | ||
title: 'New job!', | ||
}).then(...); | ||
``` | ||
@@ -86,6 +102,27 @@ | ||
client.getModel('/v1/jobs', 1) | ||
.then(job => alert('Job 1 has status: ' + job.get('status'))) | ||
.then(job => alert('Job 1 has status: ' + job.status)) | ||
.catch(err => alert('Error loading job #1')); | ||
``` | ||
Similarly: | ||
```javascript | ||
client.entities.jobs.getOne(1).then(...) | ||
``` | ||
#### Updating a model | ||
Once you have a model, you can modify it and save it: | ||
```javascript | ||
model.status = 'new status'; | ||
client.entities.jobs.update(1, model).then(...); | ||
``` | ||
#### Entity-specific Functions | ||
Some entities have additional abstracted convenience functions. For example: | ||
```javascript | ||
client.entities.job(123).addNote('note text').then(...) | ||
``` | ||
## Raw Client | ||
@@ -92,0 +129,0 @@ Use the low-level raw client on the server-side for shared-key authentication: |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80078
2025
145
13