Socket
Socket
Sign inDemoInstall

dispatch-node-sdk

Package Overview
Dependencies
Maintainers
1
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dispatch-node-sdk - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

6

lib/entities/job.js

@@ -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);
});
});
});

3

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc