Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianStier committed May 31, 2017
2 parents 98a1024 + e069967 commit e9f46ea
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/onfleet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@ var Tasks = require('./onfleet/tasks.js');
var Teams = require('./onfleet/teams.js');
var Webhooks = require('./onfleet/webhooks.js');
var Workers = require('./onfleet/workers.js');
var Destinations = require('./onfleet/destinations.js');

var Onfleet = function () {
function Onfleet(apiKey, apiBase) {
_classCallCheck(this, Onfleet);

this.client = new Client(apiKey, apiBase);
this._destinations = new Destinations(this.client);
this._tasks = new Tasks(this.client);
this._teams = new Teams(this.client);
this._webhooks = new Webhooks(this.client);
this._workers = new Workers(this.client);
}

_createClass(Onfleet, [{
key: 'destinations',
get: function get() {
return this._destinations;
}
}, {
key: 'tasks',
get: function get() {
return this._tasks;
Expand Down
56 changes: 56 additions & 0 deletions lib/onfleet/destinations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Destinations = function () {
function Destinations(client) {
_classCallCheck(this, Destinations);

this.client = client;
}

/**
* Create a new destination.
*
* http://docs.onfleet.com/docs/destinations#create-destination
*
* @param {object} address - The address for the destination.
* @param {array} location
* @returns {Promise<object[]>}
*/


_createClass(Destinations, [{
key: 'create',
value: function create(address, location) {
return this.client.post('/destinations', {
'address': address,
'location': location
});
}

/**
* Gets a single destination.
*
* http://docs.onfleet.com/docs/destinations#get-single-destination
*
* @param {string} id
* @returns {Promise<object>}
*/

}, {
key: 'get',
value: function get(id) {
if (!id) {
throw new Error('No id given');
}
return this.client.get('/destinations/' + id);
}
}]);

return Destinations;
}();

module.exports = Workers;
31 changes: 28 additions & 3 deletions lib/onfleet/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,40 @@ var Tasks = function () {
}

/**
* Gets a single task for the given id
* Creates a task
*
* http://docs.onfleet.com/docs/tasks#get-single-task
* http://docs.onfleet.com/docs/tasks#create-task
*
* @param {string} id
*/


_createClass(Tasks, [{
key: 'create',
value: function create(destination, recipients) {
var container = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var auto_assign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;

var post_data = {
'destination': destination,
'recipients': recipients
};
if (container) {
post_data.container = container;
} else if (auto_assign) {
post_data.autoAssign = true;
}
return this.client.post('/tasks', post_data);
}

/**
* Gets a single task for the given id
*
* http://docs.onfleet.com/docs/tasks#get-single-task
*
* @param {string} id
*/

}, {
key: 'get',
value: function get(id) {
if (!id) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "onfleet",
"version": "2.3.0",
"version": "2.4.0",
"description": "Node client for Onfleet",
"main": "lib/onfleet.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/onfleet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ const Tasks = require('./onfleet/tasks.js');
const Teams = require('./onfleet/teams.js');
const Webhooks = require('./onfleet/webhooks.js');
const Workers = require('./onfleet/workers.js');
const Destinations = require('./onfleet/destinations.js');

class Onfleet {

constructor(apiKey, apiBase) {
this.client = new Client(apiKey, apiBase);
this._destinations = new Destinations(this.client);
this._tasks = new Tasks(this.client);
this._teams = new Teams(this.client);
this._webhooks = new Webhooks(this.client);
this._workers = new Workers(this.client);
}

get destinations() {
return this._destinations;
}

get tasks() {
return this._tasks;
}
Expand Down
40 changes: 40 additions & 0 deletions src/onfleet/destinations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

class Destinations {
constructor(client) {
this.client = client;
}

/**
* Create a new destination.
*
* http://docs.onfleet.com/docs/destinations#create-destination
*
* @param {object} address - The address for the destination.
* @param {array} location
* @returns {Promise<object[]>}
*/
create(address, location) {
return this.client.post('/destinations', {
'address': address,
'location': location
});
}

/**
* Gets a single destination.
*
* http://docs.onfleet.com/docs/destinations#get-single-destination
*
* @param {string} id
* @returns {Promise<object>}
*/
get(id) {
if(!id) {
throw new Error('No id given');
}
return this.client.get(`/destinations/${id}`);
}
}

module.exports = Workers;
19 changes: 19 additions & 0 deletions src/onfleet/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ class Tasks {
this.client = client;
}

/**
* Creates a task
*
* http://docs.onfleet.com/docs/tasks#create-task
*
*/
create(destination, recipients, container = null, auto_assign = false) {
let post_data = {
'destination': destination,
'recipients': recipients
};
if (container) {
post_data.container = container;
} else if (auto_assign) {
post_data.autoAssign = true;
}
return this.client.post('/tasks', post_data);
}

/**
* Gets a single task for the given id
*
Expand Down

0 comments on commit e9f46ea

Please sign in to comment.