From 6d30e7f55c748d4d5a065d4e20dab9d504b9514a Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Wed, 31 Aug 2022 16:56:07 +0300
Subject: [PATCH 1/9] Added API v5 TeamManagement functions.
---
book/en/code/TeamManagement.md | 206 ++++++++++++++++++++++
src/resources/team-management.js | 231 +++++++++++++++++++++++++
test/resources/team_management.spec.js | 211 ++++++++++++++++++++++
3 files changed, 648 insertions(+)
create mode 100644 book/en/code/TeamManagement.md
create mode 100644 src/resources/team-management.js
create mode 100644 test/resources/team_management.spec.js
diff --git a/book/en/code/TeamManagement.md b/book/en/code/TeamManagement.md
new file mode 100644
index 0000000..80b60a6
--- /dev/null
+++ b/book/en/code/TeamManagement.md
@@ -0,0 +1,206 @@
+
+
+## TeamManagement ℗
+
+Notes facility
+
+**Category**: TeamManagement
+**Access**: private
+**See**: [https://route4me.io/docs/#tracking](https://route4me.io/docs/#tracking)
+**Since**: 1.0.13
+
+* [TeamManagement](#TeamManagement) ℗
+ * [new TeamManagement(requestManager)](#new_TeamManagement_new)
+ * [.create(user, [callback])](#TeamManagement+create)
+ * [.list([callback])](#TeamManagement+list)
+ * [.get(id, [callback])](#TeamManagement+get)
+ * [.delete(id, [callback])](#TeamManagement+delete)
+ * [.update(id, user, [callback])](#TeamManagement+update)
+ * [.bulkInsert(users, [options], [callback])](#TeamManagement+bulkInsert)
+
+
+
+### new TeamManagement(requestManager)
+
+Constructor
+
+**Returns**: [TeamManagement
](#TeamManagement) - - Team Management
+
+| Param | Type | Description |
+| --- | --- | --- |
+| requestManager | RequestManager
| Request Manager |
+
+
+
+### teamManagement.create(user, [callback])
+
+Add a new sub-user to the Member account by sending the corresponding
+body payload with the sub-users' parameters.
+
+**See**: [https://virtserver.swaggerhub.com/Route4Me](https://virtserver.swaggerhub.com/Route4Me)
+**Since**: 1.0.13
+
+| Param | Type | Description |
+| --- | --- | --- |
+| user | Object
| Sub-user properties. |
+| user.new_password | String
| Password. |
+| user.new_member_picture | String
| Member picture. |
+| user.member_first_name | String
| First name. |
+| user.member_last_name | String
| Last name. |
+| user.member_email | String
| E-mail. |
+| user.member_company | String
| Company. |
+| user.member_type | String
| Member type. |
+| user.OWNER_MEMBER_ID | Number
| Owner member ID. |
+| user.member_phone | String
| Phone. |
+| user.date_of_birth | String
| Date of birth. |
+| user.user_reg_state_id | Number
| User state ID. |
+| user.user_reg_country_id | Number
| User country ID. |
+| user.DriverHourlyRate | Number
| Drive hourly rate. |
+| user.HIDE_ROUTED_ADDRESSES | Boolean
| Hide routed addresses. |
+| user.HIDE_VISITED_ADDRESSES | Boolean
| Hide visited addresses. |
+| user.HIDE_NONFUTURE_ROUTES | Boolean
| Hide nonfuture routes. |
+| user.READONLY_USER | Boolean
| Readonly user. |
+| user.SHOW_SUSR_ADDR | Boolean
| Show sub-user addresses. |
+| user.SHOW_SUSR_ORDERS | Boolean
| Show sub-user orders. |
+| user.SHOW_ALL_DRIVERS | Boolean
| Show all drivers. |
+| user.SHOW_ALL_VEHICLES | Boolean
| Show all vehicles. |
+| user.display_max_routes_future_days | Boolean
| Display max routes. |
+| user.vendor_id | Number
| Vendoe ID. |
+| user.driving_rate | Number
| Driving rate. |
+| user.working_rate | Number
| Working rate. |
+| user.mile_rate | Number
| Mile rate. |
+| user.idling_rate | Number
| Idling rate. |
+| user.timezone | String
| Timezone. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### teamManagement.list([callback])
+
+View all existing sub-users associated with the Member’s account.
+
+**See**: [https://virtserver.swaggerhub.com/Route4Me](https://virtserver.swaggerhub.com/Route4Me)
+**Since**: 1.0.13
+
+| Param | Type |
+| --- | --- |
+| [callback] | module:route4me-node~RequestCallback
|
+
+
+
+### teamManagement.get(id, [callback])
+
+Get the sub-user by specifying the path parameter ID.
+
+**See**: [https://virtserver.swaggerhub.com/Route4Me](https://virtserver.swaggerhub.com/Route4Me)
+**Since**: 1.0.13
+
+| Param | Type | Description |
+| --- | --- | --- |
+| id | Number
| User ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### teamManagement.delete(id, [callback])
+
+Delete the sub-user by specifying the path parameter ID.
+
+**See**: [https://virtserver.swaggerhub.com/Route4Me](https://virtserver.swaggerhub.com/Route4Me)
+**Since**: 1.0.13
+
+| Param | Type | Description |
+| --- | --- | --- |
+| id | Number
| User ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### teamManagement.update(id, user, [callback])
+
+Update the sub-user by specifying the path parameter ID and by sending the
+corresponding body payload with the sub-user's parameters..
+
+**See**: [https://virtserver.swaggerhub.com/Route4Me](https://virtserver.swaggerhub.com/Route4Me)
+**Since**: 1.0.13
+
+| Param | Type | Description |
+| --- | --- | --- |
+| id | Number
| User ID. |
+| user | Object
| Sub-user properties. |
+| user.new_password | String
| Password. |
+| user.new_member_picture | String
| Member picture. |
+| user.member_first_name | String
| First name. |
+| user.member_last_name | String
| Last name. |
+| user.member_email | String
| E-mail. |
+| user.member_company | String
| Company. |
+| user.member_type | String
| Member type. |
+| user.OWNER_MEMBER_ID | Number
| Owner member ID. |
+| user.member_phone | String
| Phone. |
+| user.date_of_birth | String
| Date of birth. |
+| user.user_reg_state_id | Number
| User state ID. |
+| user.user_reg_country_id | Number
| User country ID. |
+| user.DriverHourlyRate | Number
| Drive hourly rate. |
+| user.HIDE_ROUTED_ADDRESSES | Boolean
| Hide routed addresses. |
+| user.HIDE_VISITED_ADDRESSES | Boolean
| Hide visited addresses. |
+| user.HIDE_NONFUTURE_ROUTES | Boolean
| Hide nonfuture routes. |
+| user.READONLY_USER | Boolean
| Readonly user. |
+| user.SHOW_SUSR_ADDR | Boolean
| Show sub-user addresses. |
+| user.SHOW_SUSR_ORDERS | Boolean
| Show sub-user orders. |
+| user.SHOW_ALL_DRIVERS | Boolean
| Show all drivers. |
+| user.SHOW_ALL_VEHICLES | Boolean
| Show all vehicles. |
+| user.display_max_routes_future_days | Boolean
| Display max routes. |
+| user.vendor_id | Number
| Vendoe ID. |
+| user.driving_rate | Number
| Driving rate. |
+| user.working_rate | Number
| Working rate. |
+| user.mile_rate | Number
| Mile rate. |
+| user.idling_rate | Number
| Idling rate. |
+| user.timezone | String
| Timezone. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### teamManagement.bulkInsert(users, [options], [callback])
+
+Add multiple sub-users to the User account by sending the corresponding
+body payload with the array of the sub-users' parameters
+
+**See**: [https://virtserver.swaggerhub.com/Route4Me](https://virtserver.swaggerhub.com/Route4Me)
+**Since**: 1.0.13
+
+| Param | Type | Description |
+| --- | --- | --- |
+| users | Array.<Object>
| Array of sub-user properties. |
+| users[].new_password | String
| Password. |
+| users[].new_member_picture | String
| Member picture. |
+| users[].member_first_name | String
| First name. |
+| users[].member_last_name | String
| Last name. |
+| users[].member_email | String
| E-mail. |
+| users[].member_company | String
| Company. |
+| users[].member_type | String
| Member type. |
+| users[].OWNER_MEMBER_ID | Number
| Owner member ID. |
+| users[].member_phone | String
| Phone. |
+| users[].date_of_birth | String
| Date of birth. |
+| users[].user_reg_state_id | Number
| User state ID. |
+| users[].user_reg_country_id | Number
| User country ID. |
+| users[].DriverHourlyRate | Number
| Drive hourly rate. |
+| users[].HIDE_ROUTED_ADDRESSES | Boolean
| Hide routed addresses. |
+| users[].HIDE_VISITED_ADDRESSES | Boolean
| Hide visited addresses. |
+| users[].HIDE_NONFUTURE_ROUTES | Boolean
| Hide nonfuture routes. |
+| users[].READONLY_USER | Boolean
| Readonly user. |
+| users[].SHOW_SUSR_ADDR | Boolean
| Show sub-user addresses. |
+| users[].SHOW_SUSR_ORDERS | Boolean
| Show sub-user orders. |
+| users[].SHOW_ALL_DRIVERS | Boolean
| Show all drivers. |
+| users[].SHOW_ALL_VEHICLES | Boolean
| Show all vehicles. |
+| users[].display_max_routes_future_days | Boolean
| Display max routes. |
+| users[].vendor_id | Number
| Vendoe ID. |
+| users[].driving_rate | Number
| Driving rate. |
+| users[].working_rate | Number
| Working rate. |
+| users[].mile_rate | Number
| Mile rate. |
+| users[].idling_rate | Number
| Idling rate. |
+| users[].timezone | String
| Timezone. |
+| [options] | Object
| Insert options. |
+| [options.api_key] | String
| User API key. |
+| [options.conflicts] | String
| Conflict resolving rule. Possible values: 'fail', 'overwrite' and 'skip'. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
diff --git a/src/resources/team-management.js b/src/resources/team-management.js
new file mode 100644
index 0000000..4864105
--- /dev/null
+++ b/src/resources/team-management.js
@@ -0,0 +1,231 @@
+"use strict"
+
+/**
+ * Notes facility
+ *
+ * @category TeamManagement
+ */
+class TeamManagement {
+ /**
+ * Constructor
+ *
+ * @see {@link https://route4me.io/docs/#tracking}
+ * @since 1.0.13
+ * @private
+ *
+ * @param {RequestManager} requestManager - Request Manager
+ * @return {TeamManagement} - Team Management
+ */
+ constructor(requestManager) {
+ this.r = requestManager
+ }
+
+ /**
+ * Add a new sub-user to the Member account by sending the corresponding
+ * body payload with the sub-users' parameters.
+ *
+ * @see {@link https://virtserver.swaggerhub.com/Route4Me}
+ * @since 1.0.13
+ *
+ * @param {Object} user - Sub-user properties.
+ * @param {String} user.new_password - Password.
+ * @param {String} user.new_member_picture - Member picture.
+ * @param {String} user.member_first_name - First name.
+ * @param {String} user.member_last_name - Last name.
+ * @param {String} user.member_email - E-mail.
+ * @param {String} user.member_company - Company.
+ * @param {String} user.member_type - Member type.
+ * @param {Number} user.OWNER_MEMBER_ID - Owner member ID.
+ * @param {String} user.member_phone - Phone.
+ * @param {String} user.date_of_birth - Date of birth.
+ * @param {Number} user.user_reg_state_id - User state ID.
+ * @param {Number} user.user_reg_country_id - User country ID.
+ * @param {Number} user.DriverHourlyRate - Drive hourly rate.
+ * @param {Boolean} user.HIDE_ROUTED_ADDRESSES - Hide routed addresses.
+ * @param {Boolean} user.HIDE_VISITED_ADDRESSES - Hide visited addresses.
+ * @param {Boolean} user.HIDE_NONFUTURE_ROUTES - Hide nonfuture routes.
+ * @param {Boolean} user.READONLY_USER - Readonly user.
+ * @param {Boolean} user.SHOW_SUSR_ADDR - Show sub-user addresses.
+ * @param {Boolean} user.SHOW_SUSR_ORDERS - Show sub-user orders.
+ * @param {Boolean} user.SHOW_ALL_DRIVERS - Show all drivers.
+ * @param {Boolean} user.SHOW_ALL_VEHICLES - Show all vehicles.
+ * @param {Boolean} user.display_max_routes_future_days - Display max routes.
+ * @param {Number} user.vendor_id - Vendoe ID.
+ * @param {Number} user.driving_rate - Driving rate.
+ * @param {Number} user.working_rate - Working rate.
+ * @param {Number} user.mile_rate - Mile rate.
+ * @param {Number} user.idling_rate - Idling rate.
+ * @param {String} user.timezone - Timezone.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ create(user, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/team/users",
+ body: user,
+ validationContext: "RouteStatus.ResponseTeams",
+ }, callback)
+ }
+
+ /**
+ * View all existing sub-users associated with the Member’s account.
+ *
+ * @see {@link https://virtserver.swaggerhub.com/Route4Me}
+ * @since 1.0.13
+ *
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ list(callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: "/api/v5.0/team/users",
+ validationContext: "RouteStatus.ResponseTeams",
+ }, callback)
+ }
+
+ /**
+ * Get the sub-user by specifying the path parameter ID.
+ *
+ * @see {@link https://virtserver.swaggerhub.com/Route4Me}
+ * @since 1.0.13
+ *
+ * @param {Number} id - User ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ get(id, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: `/api/v5.0/team/users/${id}`,
+ validationContext: "RouteStatus.ResponseTeams",
+ }, callback)
+ }
+
+ /**
+ * Delete the sub-user by specifying the path parameter ID.
+ *
+ * @see {@link https://virtserver.swaggerhub.com/Route4Me}
+ * @since 1.0.13
+ *
+ * @param {Number} id - User ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ delete(id, callback) {
+ return this.r._makeRequest5({
+ method: "DELETE",
+ path: `/api/v5.0/team/users/${id}`,
+ validationContext: "RouteStatus.ResponseTeams",
+ }, callback)
+ }
+
+ /**
+ * Update the sub-user by specifying the path parameter ID and by sending the
+ * corresponding body payload with the sub-user's parameters..
+ *
+ * @see {@link https://virtserver.swaggerhub.com/Route4Me}
+ * @since 1.0.13
+ *
+ * @param {Number} id - User ID.
+ * @param {Object} user - Sub-user properties.
+ * @param {String} user.new_password - Password.
+ * @param {String} user.new_member_picture - Member picture.
+ * @param {String} user.member_first_name - First name.
+ * @param {String} user.member_last_name - Last name.
+ * @param {String} user.member_email - E-mail.
+ * @param {String} user.member_company - Company.
+ * @param {String} user.member_type - Member type.
+ * @param {Number} user.OWNER_MEMBER_ID - Owner member ID.
+ * @param {String} user.member_phone - Phone.
+ * @param {String} user.date_of_birth - Date of birth.
+ * @param {Number} user.user_reg_state_id - User state ID.
+ * @param {Number} user.user_reg_country_id - User country ID.
+ * @param {Number} user.DriverHourlyRate - Drive hourly rate.
+ * @param {Boolean} user.HIDE_ROUTED_ADDRESSES - Hide routed addresses.
+ * @param {Boolean} user.HIDE_VISITED_ADDRESSES - Hide visited addresses.
+ * @param {Boolean} user.HIDE_NONFUTURE_ROUTES - Hide nonfuture routes.
+ * @param {Boolean} user.READONLY_USER - Readonly user.
+ * @param {Boolean} user.SHOW_SUSR_ADDR - Show sub-user addresses.
+ * @param {Boolean} user.SHOW_SUSR_ORDERS - Show sub-user orders.
+ * @param {Boolean} user.SHOW_ALL_DRIVERS - Show all drivers.
+ * @param {Boolean} user.SHOW_ALL_VEHICLES - Show all vehicles.
+ * @param {Boolean} user.display_max_routes_future_days - Display max routes.
+ * @param {Number} user.vendor_id - Vendoe ID.
+ * @param {Number} user.driving_rate - Driving rate.
+ * @param {Number} user.working_rate - Working rate.
+ * @param {Number} user.mile_rate - Mile rate.
+ * @param {Number} user.idling_rate - Idling rate.
+ * @param {String} user.timezone - Timezone.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ update(id, user, callback) {
+ return this.r._makeRequest5({
+ method: "PATCH",
+ path: `/api/v5.0/team/users/${id}`,
+ body: user,
+ validationContext: "RouteStatus.ResponseTeams",
+ }, callback)
+ }
+
+ /**
+ * Add multiple sub-users to the User account by sending the corresponding
+ * body payload with the array of the sub-users' parameters
+ *
+ * @see {@link https://virtserver.swaggerhub.com/Route4Me}
+ * @since 1.0.13
+ *
+ * @param {Object[]} users - Array of sub-user properties.
+ * @param {String} users[].new_password - Password.
+ * @param {String} users[].new_member_picture - Member picture.
+ * @param {String} users[].member_first_name - First name.
+ * @param {String} users[].member_last_name - Last name.
+ * @param {String} users[].member_email - E-mail.
+ * @param {String} users[].member_company - Company.
+ * @param {String} users[].member_type - Member type.
+ * @param {Number} users[].OWNER_MEMBER_ID - Owner member ID.
+ * @param {String} users[].member_phone - Phone.
+ * @param {String} users[].date_of_birth - Date of birth.
+ * @param {Number} users[].user_reg_state_id - User state ID.
+ * @param {Number} users[].user_reg_country_id - User country ID.
+ * @param {Number} users[].DriverHourlyRate - Drive hourly rate.
+ * @param {Boolean} users[].HIDE_ROUTED_ADDRESSES - Hide routed addresses.
+ * @param {Boolean} users[].HIDE_VISITED_ADDRESSES - Hide visited addresses.
+ * @param {Boolean} users[].HIDE_NONFUTURE_ROUTES - Hide nonfuture routes.
+ * @param {Boolean} users[].READONLY_USER - Readonly user.
+ * @param {Boolean} users[].SHOW_SUSR_ADDR - Show sub-user addresses.
+ * @param {Boolean} users[].SHOW_SUSR_ORDERS - Show sub-user orders.
+ * @param {Boolean} users[].SHOW_ALL_DRIVERS - Show all drivers.
+ * @param {Boolean} users[].SHOW_ALL_VEHICLES - Show all vehicles.
+ * @param {Boolean} users[].display_max_routes_future_days - Display max routes.
+ * @param {Number} users[].vendor_id - Vendoe ID.
+ * @param {Number} users[].driving_rate - Driving rate.
+ * @param {Number} users[].working_rate - Working rate.
+ * @param {Number} users[].mile_rate - Mile rate.
+ * @param {Number} users[].idling_rate - Idling rate.
+ * @param {String} users[].timezone - Timezone.
+ *
+ * @param {Object} [options] - Insert options.
+ * @param {String} [options.api_key] - User API key.
+ * @param {String} [options.conflicts] - Conflict resolving rule.
+ * Possible values: 'fail', 'overwrite' and 'skip'.
+ *
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ bulkInsert(users, options, callback) {
+ let opt = options || {}
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof opt) {
+ cb = opt
+ opt = {}
+ }
+
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/team/bulk-insert",
+ qs: opt,
+ body: { users },
+ validationContext: "RouteStatus.ResponseTeams",
+ }, cb)
+ }
+}
+
+module.exports = TeamManagement
diff --git a/test/resources/team_management.spec.js b/test/resources/team_management.spec.js
new file mode 100644
index 0000000..858260d
--- /dev/null
+++ b/test/resources/team_management.spec.js
@@ -0,0 +1,211 @@
+"use strict"
+
+const request = require("superagent")
+const saMock = require("superagent-mocker")(request)
+
+const helper = require("./../helper")
+
+const route4me = require("./../../dist")
+
+const testApiKey = "11111111111111111111111111111111"
+
+
+describe(helper.toSuiteName(__filename), () => {
+ describe("SDK methods", () => {
+ const route4meClient = new route4me.Route4Me(testApiKey)
+ const resource = route4meClient.TeamManagement
+ let req
+
+ beforeEach(() => {
+ req = null
+ saMock.get("*", (r) => { req = r; req.method = "GET"; return { body: {} } })
+ saMock.post("*", (r) => { req = r; req.method = "POST"; return { body: {} } })
+ saMock.del("*", (r) => { req = r; req.method = "DELETE"; return { body: {} } })
+ saMock.put("*", (r) => { req = r; req.method = "PUT"; return { body: {} } })
+ saMock.patch("*", (r) => { req = r; req.method = "PATCH"; return { body: {} } })
+ })
+
+ afterEach(() => {
+ saMock.clearRoutes()
+ })
+
+ describe("create", () => {
+ const user = {
+ new_password: "12345",
+ member_first_name: "John",
+ member_last_name: "Doe",
+ member_email: "john_doe@company.com",
+ member_company: "The Best Company",
+ member_type: "SUB_ACCOUNT_DRIVER",
+ OWNER_MEMBER_ID: 1058501
+ };
+
+ it("should call route4me", (done) => {
+ resource.create(user, (err, res) => {
+ expect(err).not.exist
+ expect(res).exist
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/team/users",
+ null,
+ {
+ new_password: "12345",
+ member_first_name: "John",
+ member_last_name: "Doe",
+ member_email: "john_doe@company.com",
+ member_company: "The Best Company",
+ member_type: "SUB_ACCOUNT_DRIVER",
+ OWNER_MEMBER_ID: 1058501
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("list", () => {
+ it("should call route4me", (done) => {
+ resource.list((err, res) => {
+ expect(err).not.exist
+ expect(res).exist
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/team/users",
+ null,
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("get", () => {
+ it("should call route4me", (done) => {
+
+ const member_id = 2355524
+
+ resource.get(member_id, (err, res) => {
+ expect(err).not.exist
+ expect(res).exist
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/team/users/2355524",
+ null,
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("delete", () => {
+ it("should call route4me", (done) => {
+
+ const member_id = 2355524
+
+ resource.delete(member_id, (err, res) => {
+ expect(err).not.exist
+ expect(res).exist
+ helper.expectRequest(req,
+ "DELETE",
+ route4meClient.baseUrl5() + "/api/v5.0/team/users/2355524",
+ null,
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("update", () => {
+ it("should call route4me", (done) => {
+
+ const member_id = 2355524
+
+ const user = {
+ HIDE_ROUTED_ADDRESSES: true
+ }
+
+ resource.update(member_id, user, (err, res) => {
+ expect(err).not.exist
+ expect(res).exist
+ helper.expectRequest(req,
+ "PATCH",
+ route4meClient.baseUrl5() + "/api/v5.0/team/users/2355524",
+ null,
+ {
+ HIDE_ROUTED_ADDRESSES: true
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("bulkInsert", () => {
+ const users = [{
+ new_password: "12345",
+ member_first_name: "John",
+ member_last_name: "Doe",
+ member_email: "john_doe@company.com",
+ member_company: "The Best Company",
+ member_type: "SUB_ACCOUNT_DRIVER",
+ OWNER_MEMBER_ID: 1058501
+ }]
+
+ const options = {
+ conflicts: "overwrite"
+ }
+
+ it("should call route4me bulkInsert with options", (done) => {
+ resource.bulkInsert(users, options, (err, res) => {
+ expect(err).not.exist
+ expect(res).exist
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/team/bulk-insert",
+ {
+ "conflicts": "overwrite"
+ },
+ {
+ users: [{
+ new_password: "12345",
+ member_first_name: "John",
+ member_last_name: "Doe",
+ member_email: "john_doe@company.com",
+ member_company: "The Best Company",
+ member_type: "SUB_ACCOUNT_DRIVER",
+ OWNER_MEMBER_ID: 1058501
+ }]
+ }
+ )
+ done()
+ })
+ })
+
+ it("should call route4me bulkInsert without options", (done) => {
+ resource.bulkInsert(users, (err, res) => {
+ expect(err).not.exist
+ expect(res).exist
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/team/bulk-insert",
+ null,
+ {
+ users: [{
+ new_password: "12345",
+ member_first_name: "John",
+ member_last_name: "Doe",
+ member_email: "john_doe@company.com",
+ member_company: "The Best Company",
+ member_type: "SUB_ACCOUNT_DRIVER",
+ OWNER_MEMBER_ID: 1058501
+ }]
+ }
+ )
+ done()
+ })
+ })
+ })
+ })
+})
From f8f74fb84ee551eac43d2e2f165248343e78f2ad Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Fri, 2 Sep 2022 13:11:38 +0300
Subject: [PATCH 2/9] Added API v5 Vehicles functions: create, lest, update and
etc.
---
book/en/code/VehiclesV5.md | 43 +++
package.json | 2 +-
src/resources/address-book-v5.js | 2 -
src/resources/team-management.js | 2 +-
src/resources/vehicles-v5.js | 594 +++++++++++++++++++++++++++++++
5 files changed, 639 insertions(+), 4 deletions(-)
create mode 100644 book/en/code/VehiclesV5.md
create mode 100644 src/resources/vehicles-v5.js
diff --git a/book/en/code/VehiclesV5.md b/book/en/code/VehiclesV5.md
new file mode 100644
index 0000000..f0d8ca9
--- /dev/null
+++ b/book/en/code/VehiclesV5.md
@@ -0,0 +1,43 @@
+
+
+## VehiclesV5 ℗
+
+Vehicles facility
+
+**Category**: VehiclesV5
+**Access**: private
+**See**: [https://route4me.io/docs/#vehicles](https://route4me.io/docs/#vehicles)
+**Since**: 1.0.14
+
+* [VehiclesV5](#VehiclesV5) ℗
+ * [new VehiclesV5(requestManager)](#new_VehiclesV5_new)
+ * [.list([callback])](#VehiclesV5+list)
+
+
+
+### new VehiclesV5(requestManager)
+
+Constructor
+
+**Returns**: Vehicles
- - Vehicles facility
+
+| Param | Type | Description |
+| --- | --- | --- |
+| requestManager | RequestManager
| Request Manager |
+
+
+
+### vehiclesV5.list([callback])
+
+Get vehicles that belong to the Route4Me account
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Todo**
+
+- [ ] Fix error in API docs: there the method utilizes `POST`-http-method to get results
+
+
+| Param | Type |
+| --- | --- |
+| [callback] | module:route4me-node~RequestCallback.<jsonschema:Vehicles.ResponseMany>
|
+
diff --git a/package.json b/package.json
index 06599fd..af8484d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "route4me-node",
- "version": "1.0.12",
+ "version": "1.0.14",
"description": "Access Route4Me's logistics-as-a-service API using our Node.js SDK",
"main": "./dist/",
"browser": "./dist/browser/route4me.js",
diff --git a/src/resources/address-book-v5.js b/src/resources/address-book-v5.js
index fcb2ab2..84049f4 100644
--- a/src/resources/address-book-v5.js
+++ b/src/resources/address-book-v5.js
@@ -1,7 +1,5 @@
"use strict"
-// const utils = require("./../utils")
-
/**
* AddressBookV5 facility
*
diff --git a/src/resources/team-management.js b/src/resources/team-management.js
index 4864105..1128877 100644
--- a/src/resources/team-management.js
+++ b/src/resources/team-management.js
@@ -209,7 +209,7 @@ class TeamManagement {
*
* @param {module:route4me-node~RequestCallback} [callback]
*/
- bulkInsert(users, options, callback) {
+ bulkInsert(users, options, callback) {
let opt = options || {}
let cb = callback
diff --git a/src/resources/vehicles-v5.js b/src/resources/vehicles-v5.js
new file mode 100644
index 0000000..2e1f23f
--- /dev/null
+++ b/src/resources/vehicles-v5.js
@@ -0,0 +1,594 @@
+"use strict"
+
+const utils = require("./../utils")
+
+/**
+ * Vehicles facility API v5
+ *
+ * @category VehiclesV5
+ * @since 1.0.14
+ */
+class VehiclesV5 {
+ /**
+ * Constructor
+ *
+ * @see {@link https://route4me.io/docs/#vehicles}
+ * @since 0.1.14
+ * @private
+ *
+ * @param {RequestManager} requestManager - Request Manager
+ * @return {VehiclesV5} - Vehicles facility
+ */
+ constructor(requestManager) {
+ this.r = requestManager
+ }
+
+ /**
+ * Create a new Vehicle in the user"s account by sending the corresponding
+ * body payload with the Vehicle parameters.
+ * The paramater fuel_type is required in the vehicle creating process.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} data - Vehicle properties.
+ * @param {String} data.vehicle_id - A unique identification 32-char string
+ * of the vehicle.
+ * @param {Number} data.member_id - An unique identification number of the member.
+ * @param {Boolean} data.is_deleted - If true, the vehicle is deleted.
+ * @param {String} data.vehicle_alias - Internal name of the vehicle.
+ * @param {String} data.vehicle_vin - Vehicle VIN number
+ * @param {Number} data.vehicle_reg_state_id - An ID of the state,
+ * where vehicle was registered.
+ * @param {Number} data.vehicle_reg_country_id - An ID of the country,
+ * where vehicle was registered.
+ * @param {String} data.vehicle_license_plate - A license plate of the vehicle
+ * @param {String} data.vehicle_type_id - Vehicle type ID
+ * Possible values: "sedan", "suv", "pickup_truck", "van", "18wheeler", "cabin", "hatchback",
+ * "motorcyle", "waste_disposal", "tree_cutting", "bigrig", "cement_mixer",
+ * "livestock_carrier", "dairy","tractor_trailer"
+ *
+ * @param {String} data.timestamp_added - When the vehicle was added.
+ * @param {String} data.vehicle_make - Vehicle maker brend.
+ * Possible values: "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc",
+ * "hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi",
+ * "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota",
+ * "volvo", "western star"
+ *
+ * @param {Number} data.vehicle_model_year - A year of the vehicle model.
+ * @param {String} data.vehicle_model - A model of the vehicle.
+ * @param {Number} data.vehicle_year_acquired - A year of the vehicle acquisition.
+ * @param {Number} data.vehicle_cost_new - A cost of the new vehicle.
+ * @param {Boolean} data.purchased_new - If true, the vehicle was purchased new.
+ * @param {String} data.license_start_date - A start date of the license.
+ * @param {String} data.license_end_date - An end date of the license.
+ * @param {Boolean} data.is_operational - If true, the vehicle is operational.
+ * @param {String} data.fuel_type - A type of the fuel.
+ * Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel",
+ * "electric", "hybrid"
+ *
+ * @param {Number} data.external_telematics_vehicle_id - External telematics vehicle ID.
+ * @param {Number} data.timestamp_removed - When he vehicle was removed.
+ * @param {Number} data.vehicle_profile_id - Vehicle profile ID.
+ * @param {Number} data.fuel_consumption_city - Fuel consumption in the city area.
+ * @param {Number} data.fuel_consumption_highway - Fuel consumption in the highway area.
+ * @param {String} data.fuel_consumption_city_unit - Fuel consumption unit in the city area.
+ * @param {String} data.fuel_consumption_highway_unit - Fuel consumption unit
+ * in the highway area.
+ * @param {Number} data.mpg_city - Miles per gallon in the city area.
+ * @param {Number} data.mpg_highway - Miles per gallon in the highway area.
+ * @param {String} data.fuel_consumption_city_uf_value - Fuel consumption UF value
+ * in the city area.
+ * @param {String} data.fuel_consumption_highway_uf_value - Fuel consumption UF value
+ * in the highway area.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ create(data, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles",
+ body: data,
+ validationContext: "Vehicles.ResponseVehicles200",
+ }, callback)
+ }
+
+ /**
+ * Display the list of Vehicles.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} [options] - Request options.
+ * @param {Number} [options.page = 1] - The requested page.
+ * @param {Number} [options.per_page = 100] - The number of Vehicles per page.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ list(options, callback) {
+ let opt = options || {}
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof opt) {
+ cb = opt
+ opt = {}
+ }
+
+ return this.r._makeRequest5({
+ method: "GET",
+ path: "/api/v5.0/vehicles",
+ qs: opt,
+ validationContext: "Vehicles.ResponseVehicles200",
+ }, cb)
+ }
+
+ /**
+ * Get the paginated list of Vehicles.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} [options] - Request options.
+ * @param {Number} [options.page = 1] - The requested page.
+ * @param {Number} [options.per_page = 100] - The number of Vehicles per page.
+ * @param {String[]} [options.order_by] - Sorting field and its sorting direction,
+ * e.g.: [["vehicle_type_id", "asc"], ["vehicle_alias", "desc"]]
+ * @param {String} [options.show = "active"] - Choose a scope to get.
+ * Possible values: "pending", "deleted", "all" and "active"
+ * @param {String} [options.filters] - Search value.
+ *
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ getVehiclesPaginated(options, callback) {
+ let opt = options || {}
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof opt) {
+ cb = opt
+ opt = {}
+ } else if (opt.filters) {
+ opt = utils.clone(opt)
+ opt.filters = { search_query: opt.filters }
+ }
+
+ return this.r._makeRequest5({
+ method: "GET",
+ path: "/api/v5.0/vehicles/paginate",
+ qs: opt,
+ validationContext: "Vehicles.ResponseVehicles200",
+ }, cb)
+ }
+
+ /**
+ * Get the Vehicle by specifying the path parameter ID.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} vehicleId - Vehicle ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ get(vehicleId, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: `/api/v5.0/vehicles/${vehicleId}`,
+ validationContext: "Vehicles.ResponseVehicles200",
+ }, callback)
+ }
+
+ /**
+ * Delete the Vehicle by specifying the path parameter ID.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} vehicleId - Vehicle ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ delete(vehicleId, callback) {
+ return this.r._makeRequest5({
+ method: "DELETE",
+ path: `/api/v5.0/vehicles/${vehicleId}`,
+ validationContext: "Vehicles.ResponseVehicles200",
+ }, callback)
+ }
+
+ /**
+ * Update the Vehicle by specifying the path parameter ID and by sending
+ * the corresponding body payload with the Vehicle's parameters.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} vehicleId - Vehicle ID.
+ * @param {Object} data - Vehicle properties.
+ * @param {String} data.vehicle_id - A unique identification 32-char string
+ * of the vehicle.
+ * @param {Number} data.member_id - An unique identification number of the member.
+ * @param {Boolean} data.is_deleted - If true, the vehicle is deleted.
+ * @param {String} data.vehicle_alias - Internal name of the vehicle.
+ * @param {String} data.vehicle_vin - Vehicle VIN number
+ * @param {Number} data.vehicle_reg_state_id - An ID of the state,
+ * where vehicle was registered.
+ * @param {Number} data.vehicle_reg_country_id - An ID of the country,
+ * where vehicle was registered.
+ * @param {String} data.vehicle_license_plate - A license plate of the vehicle
+ * @param {String} data.vehicle_type_id - Vehicle type ID
+ * Possible values: "sedan", "suv", "pickup_truck", "van", "18wheeler", "cabin", "hatchback",
+ * "motorcyle", "waste_disposal", "tree_cutting", "bigrig", "cement_mixer",
+ * "livestock_carrier", "dairy","tractor_trailer"
+ *
+ * @param {String} data.timestamp_added - When the vehicle was added.
+ * @param {String} data.vehicle_make - Vehicle maker brend.
+ * Possible values: "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc",
+ * "hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi",
+ * "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota",
+ * "volvo", "western star"
+ *
+ * @param {Number} data.vehicle_model_year - A year of the vehicle model.
+ * @param {String} data.vehicle_model - A model of the vehicle.
+ * @param {Number} data.vehicle_year_acquired - A year of the vehicle acquisition.
+ * @param {Number} data.vehicle_cost_new - A cost of the new vehicle.
+ * @param {Boolean} data.purchased_new - If true, the vehicle was purchased new.
+ * @param {String} data.license_start_date - A start date of the license.
+ * @param {String} data.license_end_date - An end date of the license.
+ * @param {Boolean} data.is_operational - If true, the vehicle is operational.
+ * @param {String} data.fuel_type - A type of the fuel.
+ * Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel",
+ * "electric", "hybrid"
+ *
+ * @param {Number} data.external_telematics_vehicle_id - External telematics vehicle ID.
+ * @param {Number} data.timestamp_removed - When he vehicle was removed.
+ * @param {Number} data.vehicle_profile_id - Vehicle profile ID.
+ * @param {Number} data.fuel_consumption_city - Fuel consumption in the city area.
+ * @param {Number} data.fuel_consumption_highway - Fuel consumption in the highway area.
+ * @param {String} data.fuel_consumption_city_unit - Fuel consumption unit in the city area.
+ * @param {String} data.fuel_consumption_highway_unit - Fuel consumption unit
+ * in the highway area.
+ * @param {Number} data.mpg_city - Miles per gallon in the city area.
+ * @param {Number} data.mpg_highway - Miles per gallon in the highway area.
+ * @param {String} data.fuel_consumption_city_uf_value - Fuel consumption UF value
+ * in the city area.
+ * @param {String} data.fuel_consumption_highway_uf_value - Fuel consumption UF value
+ * in the highway area.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ update(vehicleId, data, callback) {
+ return this.r._makeRequest5({
+ method: "PATCH",
+ path: `/api/v5.0/vehicles/${vehicleId}`,
+ body: data,
+ validationContext: "Vehicles.ResponseVehicles200",
+ }, callback)
+ }
+
+ /**
+ * Get the Vehicle track by specifying the path parameter ID.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} vehicleId - Vehicle ID.
+ * @param {Object} [options] - Request options.
+ * @param {String} [options.start] - Filter by start date.
+ * @param {String} [options.end] - Filter by end date.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ getTrack(vehicleId, options, callback) {
+ let opt = options || {}
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof opt) {
+ cb = opt
+ opt = {}
+ }
+
+ return this.r._makeRequest5({
+ method: "GET",
+ path: `/api/v5.0/vehicles/${vehicleId}/track`,
+ qs: opt,
+ validationContext: "Vehicles.VehicleTrack",
+ }, cb)
+ }
+
+ /**
+ * Temporary assign the vehicle to a member by sending the corresponding body payload.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} data - Vehicle properties.
+ * @param {String} [data.vehicle_id] - A unique identification 32-char string
+ * of the vehicle.
+ * @param {String} [data.vehicle_license_plate] - A license plate of the vehicle
+ * @param {Number} data.assigned_member_id - A unique ID of a member assigned to
+ * the vehicle.
+ * @param {Number} data.expires_at - When will the assignment of a member
+ * to a vehicle expire (Unix timestamp).
+ * @param {Boolean} [data.force-assignment] - If true, the temporary assignment of
+ * a member to a vehicle will be forced.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ assign(data, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/assign",
+ body: data,
+ validationContext: "Vehicles.ResponseTemporalVehicles",
+ }, callback)
+ }
+
+ /**
+ * Get the list of Vehicle Profiles.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} [options] - Request options.
+ * @param {Number} [options.with_pagination = 1] - If equal to 0, the Vehicle Profiles list
+ * is not paginated, otherwise it is paginated.
+ * @param {Number} [options.page = 1] - The requested page.
+ * @param {Number} [options.per_page = 100] - The number of Vehicles per page.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ getProfiles(options, callback) {
+ let opt = options || {}
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof opt) {
+ cb = opt
+ opt = {}
+ }
+
+ return this.r._makeRequest5({
+ method: "GET",
+ path: "/api/v5.0/vehicle-profiles",
+ qs: opt,
+ validationContext: "Vehicles.ResponseVehicleProfiles200",
+ }, cb)
+ }
+
+ /**
+ * Create a new Vehicle Profile by sending the corresponding body payload with
+ * the Vehicle Profile's parameters.
+ * Note: If the profile is created with is_predefined = 1, you cannot update
+ * or delete it later.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} data - Profile properties.
+ * @param {String} data.vehicle_profile_id -A unique ID of the vehicle profile.
+ * @param {Number} data.root_member_id - A unique ID of the root member.
+ * @param {String} data.name - The name of a vehicle profile.
+ * @param {Number} data.height - The height of a vehicle.
+ * @param {Number} data.width - The width of a vehicle.
+ * @param {Number} data.length - The length of a vehicle.
+ * @param {Number} data.weight - The weight of a vehicle.
+ * @param {Number} data.max_weight_per_axle - The maximum weight that can be carrie
+ * per vehicle axle.
+ * @param {String} data.created_at - When the vehicle profile was created.
+ * @param {String} data.updated_at - When the vehicle profile was updated.
+ * @param {String} data.deleted_at - When the vehicle profile was deleted.
+ * @param {String} data.fuel_type - A type of the fuel.
+ * Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel",
+ * "electric", "hybrid"
+ *
+ * @param {Number} data.fuel_consumption_city - Average fuel consumption in a city area.
+ * @param {Number} data.fuel_consumption_highway - Average fuel consumption in a highway area.
+ * @param {String} data.hazmat_type - A hazardous material type the vehicle carry.
+ * Possible values: "general", "explosives", "flammable", "inhalants", "caustic", "radioactive"
+ *
+ * @param {Boolean} data.is_predefined - If true, the vehicle profile is predefined.
+ * Note: When is_predefined = true, a vehicle profile is not updatable or removable.
+ * @param {Boolean} data.is_default - If true, the vehicle profile is default.
+ * @param {String} data.height_units - The units in which the vehicle height is measured.
+ * @param {String} data.width_units - The units in which the vehicle height is measured.
+ * @param {String} data.length_units - The units in which the vehicle length is measured.
+ * @param {String} data.weight_units - The units in which the vehicle weight is measured.
+ * @param {String} data.max_weight_per_axle_units - The units in which the maximum weight per
+ * axle of a vehicle is measured.
+ * @param {String} data.fuel_consumption_city_unit - The units in which fuel consumption
+ * is measured in a city area.
+ * @param {String} data.fuel_consumption_highway_unit - The units in which fuel consumption
+ * is measured in a highway area.
+ * @param {String} data.height_uf_value - User-friendly value of a vehicle's height.
+ * @param {String} data.width_uf_value - User-friendly value of a vehicle's width.
+ * @param {String} data.length_uf_value - User-friendly value of a vehicle's length.
+ * @param {String} data.weight_uf_value - User-friendly value of a vehicle's weight.
+ * @param {String} data.max_weight_per_axle_uf_value - User-friendly value of a vehicle's
+ * maximum weight per axle.
+ * @param {String} data.fuel_consumption_city_uf_value - User-friendly value of a vehicle's
+ * fuel consumption in a city area.
+ * @param {String} data.fuel_consumption_highway_uf_value - User-friendly value of a vehicle's
+ * fuel consumption in a highway area.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ createProfile(data, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicle-profiles",
+ body: data,
+ validationContext: "Vehicles.ResponseVehicleProfile200",
+ }, callback)
+ }
+
+ /**
+ * Get the Vehicle Profile by specifying the path parameter ID.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} vehicleId - Vehicle ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ getProfile(vehicleId, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: `/api/v5.0/vehicle-profiles/${vehicleId}`,
+ validationContext: "Vehicles.ResponseVehicleProfile200",
+ }, callback)
+ }
+
+ /**
+ * Delete the Vehicle Profile by specifying the path parameter ID
+ * Note: If the profile is created with is_predefined=1, you cannot update or delete it later.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} vehicleId - Vehicle ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ deleteProfile(vehicleId, callback) {
+ return this.r._makeRequest5({
+ method: "DELETE",
+ path: `/api/v5.0/vehicle-profiles/${vehicleId}`,
+ validationContext: "Vehicles.ResponseVehicleProfile200",
+ }, callback)
+ }
+
+ /**
+ * Update the Vehicle Profile by specifying the path parameter ID and by sending
+ * the corresponding body payload with the Vehicle Profile's parameters.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} vehicleId - Vehicle ID.
+ * @param {Object} data - Profile properties.
+ * @param {String} data.vehicle_profile_id -A unique ID of the vehicle profile.
+ * @param {Number} data.root_member_id - A unique ID of the root member.
+ * @param {String} data.name - The name of a vehicle profile.
+ * @param {Number} data.height - The height of a vehicle.
+ * @param {Number} data.width - The width of a vehicle.
+ * @param {Number} data.length - The length of a vehicle.
+ * @param {Number} data.weight - The weight of a vehicle.
+ * @param {Number} data.max_weight_per_axle - The maximum weight that can be carrie
+ * per vehicle axle.
+ * @param {String} data.created_at - When the vehicle profile was created.
+ * @param {String} data.updated_at - When the vehicle profile was updated.
+ * @param {String} data.deleted_at - When the vehicle profile was deleted.
+ * @param {String} data.fuel_type - A type of the fuel.
+ * Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel",
+ * "electric", "hybrid"
+ *
+ * @param {Number} data.fuel_consumption_city - Average fuel consumption in a city area.
+ * @param {Number} data.fuel_consumption_highway - Average fuel consumption in a highway area.
+ * @param {String} data.hazmat_type - A hazardous material type the vehicle carry.
+ * Possible values: "general", "explosives", "flammable", "inhalants", "caustic", "radioactive"
+ *
+ * @param {Boolean} data.is_predefined - If true, the vehicle profile is predefined.
+ * Note: When is_predefined = true, a vehicle profile is not updatable or removable.
+ * @param {Boolean} data.is_default - If true, the vehicle profile is default.
+ * @param {String} data.height_units - The units in which the vehicle height is measured.
+ * @param {String} data.width_units - The units in which the vehicle height is measured.
+ * @param {String} data.length_units - The units in which the vehicle length is measured.
+ * @param {String} data.weight_units - The units in which the vehicle weight is measured.
+ * @param {String} data.max_weight_per_axle_units - The units in which the maximum weight per
+ * axle of a vehicle is measured.
+ * @param {String} data.fuel_consumption_city_unit - The units in which fuel consumption
+ * is measured in a city area.
+ * @param {String} data.fuel_consumption_highway_unit - The units in which fuel consumption
+ * is measured in a highway area.
+ * @param {String} data.height_uf_value - User-friendly value of a vehicle's height.
+ * @param {String} data.width_uf_value - User-friendly value of a vehicle's width.
+ * @param {String} data.length_uf_value - User-friendly value of a vehicle's length.
+ * @param {String} data.weight_uf_value - User-friendly value of a vehicle's weight.
+ * @param {String} data.max_weight_per_axle_uf_value - User-friendly value of a vehicle's
+ * maximum weight per axle.
+ * @param {String} data.fuel_consumption_city_uf_value - User-friendly value of a vehicle's
+ * fuel consumption in a city area.
+ * @param {String} data.fuel_consumption_highway_uf_value - User-friendly value of a vehicle's
+ * fuel consumption in a highway area.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ updateProfile(vehicleId, data, callback) {
+ return this.r._makeRequest5({
+ method: "PATCH",
+ path: `/api/v5.0/vehicle-profiles/${vehicleId}`,
+ body: data,
+ validationContext: "Vehicles.ResponseVehicleProfile200",
+ }, callback)
+ }
+
+ /**
+ * Search for the Vehicle by sending the corresponding body payload
+ * with Vehicles ids and location.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} data - Vehicle properties.
+ * @param {String[]} data.vehicle_ids - An array of the vehicle IDs.
+ * @param {Number} data.lat - Latitude
+ * @param {Number} data.lng - Longitude
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ search(data, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/search",
+ body: data,
+ validationContext: "Vehicles.VehiclesSearchList",
+ }, callback)
+ }
+
+ /**
+ * Execute the Vehicle's Order by sending the corresponding body payload with
+ * the corresponding location, and Vehicle ID.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} data - Vehicle properties.
+ * @param {String} data.vehicle_id - A unique identification 32-char string of the vehicle.
+ * @param {Number} data.lat - Latitude
+ * @param {Number} data.lng - Longitude
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ execute(data, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/execute",
+ body: data,
+ validationContext: "Vehicles.inline_response_200",
+ }, callback)
+ }
+
+ /**
+ * Get the Vehicle Profile by license plate.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {String} vehicleLicensePlate - A license plate of the vehicle
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ license(vehicleLicensePlate, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: "/api/v5.0/vehicles/license",
+ qs: { vehicle_license_plate: vehicleLicensePlate },
+ validationContext: "Vehicles.ResponseVehicleLicense",
+ }, callback)
+ }
+
+ /**
+ * Get the latest know vehicle's locations.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {String[]} vehicleIds - Filter vehicles by ids.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ location(vehicleIds, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: "/api/v5.0/vehicles/location",
+ qs: { ids: vehicleIds.toString() },
+ validationContext: "Vehicles.inline_response_200_1",
+ }, callback)
+ }
+}
+
+module.exports = VehiclesV5
From 239a9c8d53273d5ccf152323db74a4a6d383a0a2 Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Sat, 10 Sep 2022 12:45:06 +0300
Subject: [PATCH 3/9] Added Vehicles v5 API functions. Added patch to have
indices in query string.
---
book/en/SUMMARY.md | 2 +
book/en/code/Route4Me.md | 16 +
book/en/code/VehiclesV5.md | 673 ++++++++++++++++++-
package.json | 2 +
src/request-manager.js | 5 +
src/resources/vehicles-v5.js | 414 +++++++++++-
src/route4me.js | 14 +
src/utils.js | 227 +++++++
test/resources/address-book-v5.spec.js | 1 -
test/resources/team_management.spec.js | 10 +-
test/resources/vehicles-v5.spec.js | 866 +++++++++++++++++++++++++
11 files changed, 2195 insertions(+), 35 deletions(-)
create mode 100644 test/resources/vehicles-v5.spec.js
diff --git a/book/en/SUMMARY.md b/book/en/SUMMARY.md
index c55cba9..e1fead1 100644
--- a/book/en/SUMMARY.md
+++ b/book/en/SUMMARY.md
@@ -39,6 +39,8 @@
### V5
* [AddressBookV5](code/AddressBookV5.md)
+ * [TeamManagement](code/TeamManagement.md)
+ * [VehiclesV5](code/VehiclesV5.md)
{% include "code/index.md" %}
diff --git a/book/en/code/Route4Me.md b/book/en/code/Route4Me.md
index d5b7e79..d076fde 100644
--- a/book/en/code/Route4Me.md
+++ b/book/en/code/Route4Me.md
@@ -97,9 +97,11 @@ Main members of the instanse of `Route4Me` class:
* [Orders ](Orders)
* [OrderCustomFields](OrderCustomFields)
* [Routes ](Routes)
+* [TeamManagement ](TeamManagement)
* [Territories ](Territories)
* [Tracking ](Tracking)
* [Vehicles ](Vehicles)
+* [VehiclesV5 ](VehiclesV5)
Each member corresponds to an bunch of methods, described in API-documentation,
but the most methods in this SDK have unified names:
@@ -135,9 +137,11 @@ For most use cases it is necessary:
* [.Optimizations](#Route4Me+Optimizations) : Optimizations
* [.Orders](#Route4Me+Orders) : Orders
* [.Routes](#Route4Me+Routes) : Routes
+ * [.TeamManagement](#Route4Me+TeamManagement) : TeamManagement
* [.Territories](#Route4Me+Territories) : Territories
* [.Tracking](#Route4Me+Tracking) : Tracking
* [.Vehicles](#Route4Me+Vehicles) : Vehicles
+ * [.VehiclesV5](#Route4Me+VehiclesV5) : VehiclesV5
* [.version](#Route4Me+version) ⇒ string
* [.baseUrl()](#Route4Me+baseUrl) ⇒ string
* [.baseUrl5()](#Route4Me+baseUrl5) ⇒ string
@@ -237,6 +241,12 @@ Create new API client
**Routes** related API calls
**Since**: 0.1.8
+
+
+### route4Me.TeamManagement : TeamManagement
+
+**TeamManagement** related API calls
+
### route4Me.Territories : Territories
@@ -255,6 +265,12 @@ Create new API client
**Vehicles** related API calls
+
+
+### route4Me.VehiclesV5 : VehiclesV5
+
+**VehiclesV5** related API calls
+
### route4Me.version ⇒ string
diff --git a/book/en/code/VehiclesV5.md b/book/en/code/VehiclesV5.md
index f0d8ca9..20b57d3 100644
--- a/book/en/code/VehiclesV5.md
+++ b/book/en/code/VehiclesV5.md
@@ -2,7 +2,7 @@
## VehiclesV5 ℗
-Vehicles facility
+Vehicles facility API v5
**Category**: VehiclesV5
**Access**: private
@@ -11,7 +11,36 @@ Vehicles facility
* [VehiclesV5](#VehiclesV5) ℗
* [new VehiclesV5(requestManager)](#new_VehiclesV5_new)
- * [.list([callback])](#VehiclesV5+list)
+ * [.create(data, [callback])](#VehiclesV5+create)
+ * [.list([options], [callback])](#VehiclesV5+list)
+ * [.getVehiclesPaginated([options], [callback])](#VehiclesV5+getVehiclesPaginated)
+ * [.get(vehicleId, [callback])](#VehiclesV5+get)
+ * [.delete(vehicleId, [callback])](#VehiclesV5+delete)
+ * [.update(vehicleId, data, [callback])](#VehiclesV5+update)
+ * [.getTrack(vehicleId, [options], [callback])](#VehiclesV5+getTrack)
+ * [.assign(data, [callback])](#VehiclesV5+assign)
+ * [.getProfiles([options], [callback])](#VehiclesV5+getProfiles)
+ * [.createProfile(data, [callback])](#VehiclesV5+createProfile)
+ * [.getProfile(profileId, [callback])](#VehiclesV5+getProfile)
+ * [.deleteProfile(profileId, [callback])](#VehiclesV5+deleteProfile)
+ * [.updateProfile(vehicleId, data, [callback])](#VehiclesV5+updateProfile)
+ * [.search(data, [callback])](#VehiclesV5+search)
+ * [.execute(data, [callback])](#VehiclesV5+execute)
+ * [.getVehicleProfileByLicense(vehicleLicensePlate, [callback])](#VehiclesV5+getVehicleProfileByLicense)
+ * [.location(vehicleIds, [callback])](#VehiclesV5+location)
+ * [.bulkUpdate(vehicles, [callback])](#VehiclesV5+bulkUpdate)
+ * [.bulkDelete(vehicleIds, [callback])](#VehiclesV5+bulkDelete)
+ * [.bulkActivate([vehicleIds], [callback])](#VehiclesV5+bulkActivate)
+ * [.bulkDeactivate([vehicleIds], [callback])](#VehiclesV5+bulkDeactivate)
+ * [.bulkRestore([vehicleIds], [callback])](#VehiclesV5+bulkRestore)
+ * [.syncPending(data, [callback])](#VehiclesV5+syncPending)
+ * [.jobTrackerStatus(jobId, [callback])](#VehiclesV5+jobTrackerStatus)
+ * [.jobTrackerResult(jobId, [callback])](#VehiclesV5+jobTrackerResult)
+ * [.listCapacityProfiles([options], [callback])](#VehiclesV5+listCapacityProfiles)
+ * [.createCapacityProfiles(data, [callback])](#VehiclesV5+createCapacityProfiles)
+ * [.getCapacityProfiles(id, [callback])](#VehiclesV5+getCapacityProfiles)
+ * [.deleteCapacityProfiles(id, [callback])](#VehiclesV5+deleteCapacityProfiles)
+ * [.updateCapacityProfiles(id, data, [callback])](#VehiclesV5+updateCapacityProfiles)
@@ -19,25 +48,649 @@ Vehicles facility
Constructor
-**Returns**: Vehicles
- - Vehicles facility
+**Returns**: [VehiclesV5
](#VehiclesV5) - - Vehicles facility
| Param | Type | Description |
| --- | --- | --- |
| requestManager | RequestManager
| Request Manager |
+
+
+### vehiclesV5.create(data, [callback])
+
+Create a new Vehicle in the user"s account by sending the corresponding
+body payload with the Vehicle parameters.
+The paramater fuel_type is required in the vehicle creating process.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| data | Object
| Vehicle properties. |
+| data.vehicle_id | String
| A unique identification 32-char string of the vehicle. |
+| data.member_id | Number
| An unique identification number of the member. |
+| data.is_deleted | Boolean
| If true, the vehicle is deleted. |
+| data.vehicle_alias | String
| Internal name of the vehicle. |
+| data.vehicle_vin | String
| Vehicle VIN number |
+| data.vehicle_reg_state_id | Number
| An ID of the state, where vehicle was registered. |
+| data.vehicle_reg_country_id | Number
| An ID of the country, where vehicle was registered. |
+| data.vehicle_license_plate | String
| A license plate of the vehicle |
+| data.vehicle_type_id | String
| Vehicle type ID Possible values: "sedan", "suv", "pickup_truck", "van", "18wheeler", "cabin", "hatchback", "motorcyle", "waste_disposal", "tree_cutting", "bigrig", "cement_mixer", "livestock_carrier", "dairy","tractor_trailer" |
+| data.timestamp_added | String
| When the vehicle was added. |
+| data.vehicle_make | String
| Vehicle maker brend. Possible values: "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc", "hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi", "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota", "volvo", "western star" |
+| data.vehicle_model_year | Number
| A year of the vehicle model. |
+| data.vehicle_model | String
| A model of the vehicle. |
+| data.vehicle_year_acquired | Number
| A year of the vehicle acquisition. |
+| data.vehicle_cost_new | Number
| A cost of the new vehicle. |
+| data.purchased_new | Boolean
| If true, the vehicle was purchased new. |
+| data.license_start_date | String
| A start date of the license. |
+| data.license_end_date | String
| An end date of the license. |
+| data.is_operational | Boolean
| If true, the vehicle is operational. |
+| data.fuel_type | String
| A type of the fuel. Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel", "electric", "hybrid" |
+| data.external_telematics_vehicle_id | Number
| External telematics vehicle ID. |
+| data.timestamp_removed | Number
| When he vehicle was removed. |
+| data.vehicle_profile_id | Number
| Vehicle profile ID. |
+| data.fuel_consumption_city | Number
| Fuel consumption in the city area. |
+| data.fuel_consumption_highway | Number
| Fuel consumption in the highway area. |
+| data.fuel_consumption_city_unit | String
| Fuel consumption unit in the city area. |
+| data.fuel_consumption_highway_unit | String
| Fuel consumption unit in the highway area. |
+| data.mpg_city | Number
| Miles per gallon in the city area. |
+| data.mpg_highway | Number
| Miles per gallon in the highway area. |
+| data.fuel_consumption_city_uf_value | String
| Fuel consumption UF value in the city area. |
+| data.fuel_consumption_highway_uf_value | String
| Fuel consumption UF value in the highway area. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
-### vehiclesV5.list([callback])
+### vehiclesV5.list([options], [callback])
+
+Display the list of Vehicles.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| [options] | Object
| | Request options. |
+| [options.page] | Number
| 1
| The requested page. |
+| [options.per_page] | Number
| 100
| The number of Vehicles per page. |
+| [callback] | module:route4me-node~RequestCallback
| | |
+
+
+
+### vehiclesV5.getVehiclesPaginated([options], [callback])
+
+Get the paginated list of Vehicles.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| [options] | Object
| | Request options. |
+| [options.page] | Number
| 1
| The requested page. |
+| [options.per_page] | Number
| 100
| The number of Vehicles per page. |
+| [options.order_by] | Array.<String>
| | Sorting field and its sorting direction, e.g.: [["vehicle_type_id", "asc"], ["vehicle_alias", "desc"]] |
+| [options.show] | String
| "active"
| Choose a scope to get. Possible values: "pending", "deleted", "all" and "active" |
+| [options.search_query] | String
| | Search value. |
+| [callback] | module:route4me-node~RequestCallback
| | |
+
+
+
+### vehiclesV5.get(vehicleId, [callback])
+
+Get the Vehicle by specifying the path parameter ID.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicleId | String
| Vehicle ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.delete(vehicleId, [callback])
+
+Delete the Vehicle by specifying the path parameter ID.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicleId | String
| Vehicle ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.update(vehicleId, data, [callback])
+
+Update the Vehicle by specifying the path parameter ID and by sending
+the corresponding body payload with the Vehicle's parameters.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicleId | String
| Vehicle ID. |
+| data | Object
| Vehicle properties. |
+| data.vehicle_id | String
| A unique identification 32-char string of the vehicle. |
+| data.member_id | Number
| An unique identification number of the member. |
+| data.is_deleted | Boolean
| If true, the vehicle is deleted. |
+| data.vehicle_alias | String
| Internal name of the vehicle. |
+| data.vehicle_vin | String
| Vehicle VIN number |
+| data.vehicle_reg_state_id | Number
| An ID of the state, where vehicle was registered. |
+| data.vehicle_reg_country_id | Number
| An ID of the country, where vehicle was registered. |
+| data.vehicle_license_plate | String
| A license plate of the vehicle |
+| data.vehicle_type_id | String
| Vehicle type ID Possible values: "sedan", "suv", "pickup_truck", "van", "18wheeler", "cabin", "hatchback", "motorcyle", "waste_disposal", "tree_cutting", "bigrig", "cement_mixer", "livestock_carrier", "dairy","tractor_trailer" |
+| data.timestamp_added | String
| When the vehicle was added. |
+| data.vehicle_make | String
| Vehicle maker brend. Possible values: "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc", "hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi", "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota", "volvo", "western star" |
+| data.vehicle_model_year | Number
| A year of the vehicle model. |
+| data.vehicle_model | String
| A model of the vehicle. |
+| data.vehicle_year_acquired | Number
| A year of the vehicle acquisition. |
+| data.vehicle_cost_new | Number
| A cost of the new vehicle. |
+| data.purchased_new | Boolean
| If true, the vehicle was purchased new. |
+| data.license_start_date | String
| A start date of the license. |
+| data.license_end_date | String
| An end date of the license. |
+| data.is_operational | Boolean
| If true, the vehicle is operational. |
+| data.fuel_type | String
| A type of the fuel. Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel", "electric", "hybrid" |
+| data.external_telematics_vehicle_id | Number
| External telematics vehicle ID. |
+| data.timestamp_removed | Number
| When he vehicle was removed. |
+| data.vehicle_profile_id | Number
| Vehicle profile ID. |
+| data.fuel_consumption_city | Number
| Fuel consumption in the city area. |
+| data.fuel_consumption_highway | Number
| Fuel consumption in the highway area. |
+| data.fuel_consumption_city_unit | String
| Fuel consumption unit in the city area. |
+| data.fuel_consumption_highway_unit | String
| Fuel consumption unit in the highway area. |
+| data.mpg_city | Number
| Miles per gallon in the city area. |
+| data.mpg_highway | Number
| Miles per gallon in the highway area. |
+| data.fuel_consumption_city_uf_value | String
| Fuel consumption UF value in the city area. |
+| data.fuel_consumption_highway_uf_value | String
| Fuel consumption UF value in the highway area. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.getTrack(vehicleId, [options], [callback])
+
+Get the Vehicle track by specifying the path parameter ID.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicleId | String
| Vehicle ID. |
+| [options] | Object
| Request options. |
+| [options.start] | String
| Filter by start date. |
+| [options.end] | String
| Filter by end date. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.assign(data, [callback])
+
+Temporary assign the vehicle to a member by sending the corresponding body payload.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| data | Object
| Vehicle properties. |
+| [data.vehicle_id] | String
| A unique identification 32-char string of the vehicle. |
+| [data.vehicle_license_plate] | String
| A license plate of the vehicle |
+| data.assigned_member_id | Number
| A unique ID of a member assigned to the vehicle. |
+| data.expires_at | Number
| When will the assignment of a member to a vehicle expire (Unix timestamp). |
+| [data.force-assignment] | Boolean
| If true, the temporary assignment of a member to a vehicle will be forced. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.getProfiles([options], [callback])
+
+Get the list of Vehicle Profiles.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| [options] | Object
| | Request options. |
+| [options.with_pagination] | Number
| 1
| If equal to 0, the Vehicle Profiles list is not paginated, otherwise it is paginated. |
+| [options.page] | Number
| 1
| The requested page. |
+| [options.per_page] | Number
| 100
| The number of Vehicles per page. |
+| [callback] | module:route4me-node~RequestCallback
| | |
+
+
+
+### vehiclesV5.createProfile(data, [callback])
+
+Create a new Vehicle Profile by sending the corresponding body payload with
+the Vehicle Profile's parameters.
+Note: If the profile is created with is_predefined = 1, you cannot update
+or delete it later.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| data | Object
| Profile properties. |
+| data.vehicle_profile_id | String
| A unique ID of the vehicle profile. |
+| data.root_member_id | Number
| A unique ID of the root member. |
+| data.name | String
| The name of a vehicle profile. |
+| data.height | Number
| The height of a vehicle. |
+| data.width | Number
| The width of a vehicle. |
+| data.length | Number
| The length of a vehicle. |
+| data.weight | Number
| The weight of a vehicle. |
+| data.max_weight_per_axle | Number
| The maximum weight that can be carrie per vehicle axle. |
+| data.created_at | String
| When the vehicle profile was created. |
+| data.updated_at | String
| When the vehicle profile was updated. |
+| data.deleted_at | String
| When the vehicle profile was deleted. |
+| data.fuel_type | String
| A type of the fuel. Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel", "electric", "hybrid" |
+| data.fuel_consumption_city | Number
| Average fuel consumption in a city area. |
+| data.fuel_consumption_highway | Number
| Average fuel consumption in a highway area. |
+| data.hazmat_type | String
| A hazardous material type the vehicle carry. Possible values: "general", "explosives", "flammable", "inhalants", "caustic", "radioactive" |
+| data.is_predefined | Boolean
| If true, the vehicle profile is predefined. Note: When is_predefined = true, a vehicle profile is not updatable or removable. |
+| data.is_default | Boolean
| If true, the vehicle profile is default. |
+| data.height_units | String
| The units in which the vehicle height is measured. |
+| data.width_units | String
| The units in which the vehicle height is measured. |
+| data.length_units | String
| The units in which the vehicle length is measured. |
+| data.weight_units | String
| The units in which the vehicle weight is measured. |
+| data.max_weight_per_axle_units | String
| The units in which the maximum weight per axle of a vehicle is measured. |
+| data.fuel_consumption_city_unit | String
| The units in which fuel consumption is measured in a city area. |
+| data.fuel_consumption_highway_unit | String
| The units in which fuel consumption is measured in a highway area. |
+| data.height_uf_value | String
| User-friendly value of a vehicle's height. |
+| data.width_uf_value | String
| User-friendly value of a vehicle's width. |
+| data.length_uf_value | String
| User-friendly value of a vehicle's length. |
+| data.weight_uf_value | String
| User-friendly value of a vehicle's weight. |
+| data.max_weight_per_axle_uf_value | String
| User-friendly value of a vehicle's maximum weight per axle. |
+| data.fuel_consumption_city_uf_value | String
| User-friendly value of a vehicle's fuel consumption in a city area. |
+| data.fuel_consumption_highway_uf_value | String
| User-friendly value of a vehicle's fuel consumption in a highway area. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.getProfile(profileId, [callback])
+
+Get the Vehicle Profile by specifying the path parameter ID.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| profileId | Number
| Vehicle ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.deleteProfile(profileId, [callback])
+
+Delete the Vehicle Profile by specifying the path parameter ID
+Note: If the profile is created with is_predefined=1, you cannot update or delete it later.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| profileId | Number
| Vehicle ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.updateProfile(vehicleId, data, [callback])
+
+Update the Vehicle Profile by specifying the path parameter ID and by sending
+the corresponding body payload with the Vehicle Profile's parameters.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicleId | String
| Vehicle ID. |
+| data | Object
| Profile properties. |
+| data.vehicle_profile_id | String
| A unique ID of the vehicle profile. |
+| data.root_member_id | Number
| A unique ID of the root member. |
+| data.name | String
| The name of a vehicle profile. |
+| data.height | Number
| The height of a vehicle. |
+| data.width | Number
| The width of a vehicle. |
+| data.length | Number
| The length of a vehicle. |
+| data.weight | Number
| The weight of a vehicle. |
+| data.max_weight_per_axle | Number
| The maximum weight that can be carrie per vehicle axle. |
+| data.created_at | String
| When the vehicle profile was created. |
+| data.updated_at | String
| When the vehicle profile was updated. |
+| data.deleted_at | String
| When the vehicle profile was deleted. |
+| data.fuel_type | String
| A type of the fuel. Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel", "electric", "hybrid" |
+| data.fuel_consumption_city | Number
| Average fuel consumption in a city area. |
+| data.fuel_consumption_highway | Number
| Average fuel consumption in a highway area. |
+| data.hazmat_type | String
| A hazardous material type the vehicle carry. Possible values: "general", "explosives", "flammable", "inhalants", "caustic", "radioactive" |
+| data.is_predefined | Boolean
| If true, the vehicle profile is predefined. Note: When is_predefined = true, a vehicle profile is not updatable or removable. |
+| data.is_default | Boolean
| If true, the vehicle profile is default. |
+| data.height_units | String
| The units in which the vehicle height is measured. |
+| data.width_units | String
| The units in which the vehicle height is measured. |
+| data.length_units | String
| The units in which the vehicle length is measured. |
+| data.weight_units | String
| The units in which the vehicle weight is measured. |
+| data.max_weight_per_axle_units | String
| The units in which the maximum weight per axle of a vehicle is measured. |
+| data.fuel_consumption_city_unit | String
| The units in which fuel consumption is measured in a city area. |
+| data.fuel_consumption_highway_unit | String
| The units in which fuel consumption is measured in a highway area. |
+| data.height_uf_value | String
| User-friendly value of a vehicle's height. |
+| data.width_uf_value | String
| User-friendly value of a vehicle's width. |
+| data.length_uf_value | String
| User-friendly value of a vehicle's length. |
+| data.weight_uf_value | String
| User-friendly value of a vehicle's weight. |
+| data.max_weight_per_axle_uf_value | String
| User-friendly value of a vehicle's maximum weight per axle. |
+| data.fuel_consumption_city_uf_value | String
| User-friendly value of a vehicle's fuel consumption in a city area. |
+| data.fuel_consumption_highway_uf_value | String
| User-friendly value of a vehicle's fuel consumption in a highway area. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.search(data, [callback])
+
+Search for the Vehicle by sending the corresponding body payload
+with Vehicles ids and location.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| data | Object
| Vehicle properties. |
+| data.vehicle_ids | Array.<String>
| An array of the vehicle IDs. |
+| data.lat | Number
| Latitude |
+| data.lng | Number
| Longitude |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.execute(data, [callback])
+
+Execute the Vehicle's Order by sending the corresponding body payload with
+the corresponding location, and Vehicle ID.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| data | Object
| Vehicle properties. |
+| data.vehicle_id | String
| A unique identification 32-char string of the vehicle. |
+| data.lat | Number
| Latitude |
+| data.lng | Number
| Longitude |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.getVehicleProfileByLicense(vehicleLicensePlate, [callback])
+
+Get the Vehicle Profile by license plate.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicleLicensePlate | String
| A license plate of the vehicle |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.location(vehicleIds, [callback])
+
+Get the latest know vehicle's locations.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicleIds | Array.<String>
| Filter vehicles by ids. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.bulkUpdate(vehicles, [callback])
+
+Update the Vehicle list asynchronously by sending the corresponding body payload
+with the Vehicles list with their parameters.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicles | Array.<Object>
| Vehicle properties. |
+| vehicles.vehicle_id | String
| A unique identification 32-char string of the vehicle. |
+| vehicles.vehicle_alias | String
| Internal name of the vehicle. |
+| vehicles.vehicle_vin | String
| Vehicle VIN number |
+| vehicles.vehicle_reg_state_id | Number
| An ID of the state, where vehicle was registered. |
+| vehicles.vehicle_reg_country_id | Number
| An ID of the country, where vehicle was registered. |
+| vehicles.vehicle_license_plate | String
| A license plate of the vehicle |
+| vehicles.vehicle_type_id | String
| Vehicle type ID Possible values: "sedan", "suv", "pickup_truck", "van", "18wheeler", "cabin", "hatchback", "motorcyle", "waste_disposal", "tree_cutting", "bigrig", "cement_mixer", "livestock_carrier", "dairy","tractor_trailer" |
+| vehicles.vehicle_make | String
| Vehicle maker brend. Possible values: "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc", "hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi", "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota", "volvo", "western star" |
+| vehicles.vehicle_model_year | Number
| A year of the vehicle model. |
+| vehicles.vehicle_model | String
| A model of the vehicle. |
+| vehicles.vehicle_year_acquired | Number
| A year of the vehicle acquisition. |
+| vehicles.fuel_type | String
| A type of the fuel. Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel", "electric", "hybrid" |
+| vehicles.vehicle_profile_id | Number
| Vehicle profile ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.bulkDelete(vehicleIds, [callback])
+
+Delete the Vehicles from the list of their ids asynchronously.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| vehicleIds | Array.<String>
| Vehicle IDs to delete. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.bulkActivate([vehicleIds], [callback])
+
+Activate the Vehicles from the list of their ids asynchronously.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| [vehicleIds] | Array.<String>
| Array of the vehicle ids to activate. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.bulkDeactivate([vehicleIds], [callback])
+
+Deactivate the Vehicles from the list of their ids asynchronously.
-Get vehicles that belong to the Route4Me account
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| [vehicleIds] | Array.<String>
| Array of the vehicle ids to deactivate. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.bulkRestore([vehicleIds], [callback])
+
+Restore the Vehicles from the list of their ids asynchronously.
**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
-**Todo**
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| [vehicleIds] | Array.<String>
| Array of the vehicle ids to restore. |
+| [callback] | module:route4me-node~RequestCallback
| |
-- [ ] Fix error in API docs: there the method utilizes `POST`-http-method to get results
+
+### vehiclesV5.syncPending(data, [callback])
+
+Sync a Pending Vehicle from Telematics.
+Sync the Vehicle by sending the corresponding body payload with the Vehicle's parameters
+and by specifiying `vehicle_alias`, `r4m_telematics_gateway_connection_id`
+and `r4m_telematics_gateway_vehicle_id` in this body payload.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
-| Param | Type |
-| --- | --- |
-| [callback] | module:route4me-node~RequestCallback.<jsonschema:Vehicles.ResponseMany>
|
+| Param | Type | Description |
+| --- | --- | --- |
+| data | Object
| Vehicle properties. |
+| data.vehicle_alias | String
| Internal name of the vehicle. |
+| data.vehicle_vin | String
| Vehicle VIN number |
+| data.vehicle_reg_state_id | Number
| An ID of the state, where vehicle was registered. |
+| data.vehicle_reg_country_id | Number
| An ID of the country, where vehicle was registered. |
+| data.vehicle_license_plate | String
| A license plate of the vehicle |
+| data.vehicle_type_id | String
| Vehicle type ID Possible values: "sedan", "suv", "pickup_truck", "van", "18wheeler", "cabin", "hatchback", "motorcyle", "waste_disposal", "tree_cutting", "bigrig", "cement_mixer", "livestock_carrier", "dairy","tractor_trailer" |
+| data.vehicle_make | String
| Vehicle maker brend. Possible values: "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc", "hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi", "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota", "volvo", "western star" |
+| data.vehicle_model_year | Number
| A year of the vehicle model. |
+| data.vehicle_model | String
| A model of the vehicle. |
+| data.vehicle_year_acquired | Number
| A year of the vehicle acquisition. |
+| data.fuel_type | String
| A type of the fuel. Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel", "electric", "hybrid" |
+| data.external_telematics_vehicle_id | Number
| External telematics vehicle ID. |
+| data.r4m_telematics_gateway_connection_id | Number
| A unique ID of the Route4Me telematics gateway connection. |
+| data.r4m_telematics_gateway_vehicle_id | Number
| A unique ID of the Route4Me telematics gateway vehicle. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.jobTrackerStatus(jobId, [callback])
+
+View Job Tracker Status.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| jobId | String
| Current Job ID.. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.jobTrackerResult(jobId, [callback])
+
+View Job Tracker Result.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| jobId | String
| Current Job ID.. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.listCapacityProfiles([options], [callback])
+
+List all the Vehicle Capacity Profiles.
+Filtering Data: Send Vehicle Capacity Profile attribute's name with
+the corresponding value, e.g. max_volume = 99.99
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| [options] | Object
| | Request options. |
+| [options.mergePagesParam] | Boolean
| false
| Paginate all the data into one page only. |
+| [options.page] | Number
| 1
| The requested page. |
+| [options.per_page] | Number
| 100
| The number of Vehicles per page. |
+| [options.order_by] | Array.<String>
| | Sorting field and its sorting direction, e.g.: [["max_volume", "asc"], ["max_revenue", "desc"]] |
+| [options.filters] | String
| | Search value. |
+| [callback] | module:route4me-node~RequestCallback
| | |
+
+
+
+### vehiclesV5.createCapacityProfiles(data, [callback])
+
+Create a new Vehicle Capacity Profile.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| data | Object
| Capacity profile properties. |
+| data.vehicle_capacity_profile_id | Number
| A unique ID of a vehicle capacity profile. |
+| data.root_member_id | Number
| A unique ID of the root member. |
+| data.name | string
| The name of a vehicle capacity profile. |
+| data.max_volume | Number
| The maximum volume a veicle can carry. |
+| data.max_weight | Number
| The maximum weight a vehicle can carry. |
+| data.max_items_number | Number
| The maximum number of items a vehicle can carry. |
+| data.max_revenue | Number
| The maximum revenue an owner company can gain from a vehicle. |
+| data.max_volume_unit | String
| A unit in which maximum volume is measured. |
+| data.max_weight_unit | String
| A unit in which maximum weight is measured. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.getCapacityProfiles(id, [callback])
+
+Get a Vehicle Capacity Profile by its ID.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| id | Number
| Vehicle Capacity Profile ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.deleteCapacityProfiles(id, [callback])
+
+Delete the Vehicle Capacity Profile by its ID.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| id | Number
| Vehicle Capacity Profile ID. |
+| [callback] | module:route4me-node~RequestCallback
| |
+
+
+
+### vehiclesV5.updateCapacityProfiles(id, data, [callback])
+
+Update the Vehicle Capacity Profile by its ID.
+
+**See**: [https://route4me.io/docs/#get-vehicles](https://route4me.io/docs/#get-vehicles)
+**Since**: 1.0.14
+
+| Param | Type | Description |
+| --- | --- | --- |
+| id | Number
| Vehicle Capacity Profile ID. |
+| data | Object
| Capacity profile properties. |
+| data.vehicle_capacity_profile_id | Number
| A unique ID of a vehicle capacity profile. |
+| data.root_member_id | Number
| A unique ID of the root member. |
+| data.name | Number
| The name of a vehicle capacity profile. |
+| data.max_volume | Number
| The maximum volume a veicle can carry. |
+| data.max_weight | Number
| The maximum weight a vehicle can carry. |
+| data.max_items_number | Number
| The maximum number of items a vehicle can carry. |
+| data.max_revenue | Number
| The maximum revenue an owner company can gain from a vehicle. |
+| data.created_at | String
| When the vehicle capacity profile was created. |
+| data.updated_at | String
| When the vehicle capacity profile was updated. |
+| data.deleted_at | String
| When the vehicle capacity profile was deleted. |
+| data.max_volume_unit | String
| A unit in which maximum volume is measured. |
+| data.max_weight_unit | String
| A unit in which maximum weight is measured. |
+| [callback] | module:route4me-node~RequestCallback
| |
diff --git a/package.json b/package.json
index af8484d..ef98c3c 100644
--- a/package.json
+++ b/package.json
@@ -61,9 +61,11 @@
},
"homepage": "http://route4me.com",
"dependencies": {
+ "cookiejar": "^2.1.3",
"debug": "^4.3.2",
"del": "^6.0.0",
"platform": "^1.3.6",
+ "qs": "^6.10.3",
"superagent": "^7.1.1"
},
"devDependencies": {
diff --git a/src/request-manager.js b/src/request-manager.js
index e221481..441a070 100644
--- a/src/request-manager.js
+++ b/src/request-manager.js
@@ -2,6 +2,7 @@
const request = require("superagent")
const errors = require("./errors")
+const utils = require("./utils")
class ResponseHandler {
constructor(PromiseConstructor, logger, validate, validateContext, callback, returns) {
@@ -248,6 +249,10 @@ class RequestManager {
.accept("application/json")
.query(qs)
+ if (options.indices) {
+ utils.patchRequest.bind(req)(req)
+ }
+
if (form) {
req.type("multipart/form-data")
.field(form)
diff --git a/src/resources/vehicles-v5.js b/src/resources/vehicles-v5.js
index 2e1f23f..0b16dae 100644
--- a/src/resources/vehicles-v5.js
+++ b/src/resources/vehicles-v5.js
@@ -133,7 +133,7 @@ class VehiclesV5 {
* e.g.: [["vehicle_type_id", "asc"], ["vehicle_alias", "desc"]]
* @param {String} [options.show = "active"] - Choose a scope to get.
* Possible values: "pending", "deleted", "all" and "active"
- * @param {String} [options.filters] - Search value.
+ * @param {String} [options.search_query] - Search value.
*
* @param {module:route4me-node~RequestCallback} [callback]
*/
@@ -144,15 +144,13 @@ class VehiclesV5 {
if (undefined === cb && "function" === typeof opt) {
cb = opt
opt = {}
- } else if (opt.filters) {
- opt = utils.clone(opt)
- opt.filters = { search_query: opt.filters }
}
return this.r._makeRequest5({
method: "GET",
path: "/api/v5.0/vehicles/paginate",
qs: opt,
+ indices: true,
validationContext: "Vehicles.ResponseVehicles200",
}, cb)
}
@@ -163,7 +161,7 @@ class VehiclesV5 {
* @see {@link https://route4me.io/docs/#get-vehicles}
* @since 1.0.14
*
- * @param {Object} vehicleId - Vehicle ID.
+ * @param {String} vehicleId - Vehicle ID.
* @param {module:route4me-node~RequestCallback} [callback]
*/
get(vehicleId, callback) {
@@ -180,7 +178,7 @@ class VehiclesV5 {
* @see {@link https://route4me.io/docs/#get-vehicles}
* @since 1.0.14
*
- * @param {Object} vehicleId - Vehicle ID.
+ * @param {String} vehicleId - Vehicle ID.
* @param {module:route4me-node~RequestCallback} [callback]
*/
delete(vehicleId, callback) {
@@ -198,7 +196,7 @@ class VehiclesV5 {
* @see {@link https://route4me.io/docs/#get-vehicles}
* @since 1.0.14
*
- * @param {Object} vehicleId - Vehicle ID.
+ * @param {String} vehicleId - Vehicle ID.
* @param {Object} data - Vehicle properties.
* @param {String} data.vehicle_id - A unique identification 32-char string
* of the vehicle.
@@ -266,7 +264,7 @@ class VehiclesV5 {
* @see {@link https://route4me.io/docs/#get-vehicles}
* @since 1.0.14
*
- * @param {Object} vehicleId - Vehicle ID.
+ * @param {String} vehicleId - Vehicle ID.
* @param {Object} [options] - Request options.
* @param {String} [options.start] - Filter by start date.
* @param {String} [options.end] - Filter by end date.
@@ -356,7 +354,7 @@ class VehiclesV5 {
* @since 1.0.14
*
* @param {Object} data - Profile properties.
- * @param {String} data.vehicle_profile_id -A unique ID of the vehicle profile.
+ * @param {String} data.vehicle_profile_id - A unique ID of the vehicle profile.
* @param {Number} data.root_member_id - A unique ID of the root member.
* @param {String} data.name - The name of a vehicle profile.
* @param {Number} data.height - The height of a vehicle.
@@ -417,13 +415,13 @@ class VehiclesV5 {
* @see {@link https://route4me.io/docs/#get-vehicles}
* @since 1.0.14
*
- * @param {Object} vehicleId - Vehicle ID.
+ * @param {Number} profileId - Vehicle ID.
* @param {module:route4me-node~RequestCallback} [callback]
*/
- getProfile(vehicleId, callback) {
+ getProfile(profileId, callback) {
return this.r._makeRequest5({
method: "GET",
- path: `/api/v5.0/vehicle-profiles/${vehicleId}`,
+ path: `/api/v5.0/vehicle-profiles/${profileId}`,
validationContext: "Vehicles.ResponseVehicleProfile200",
}, callback)
}
@@ -435,13 +433,13 @@ class VehiclesV5 {
* @see {@link https://route4me.io/docs/#get-vehicles}
* @since 1.0.14
*
- * @param {Object} vehicleId - Vehicle ID.
+ * @param {Number} profileId - Vehicle ID.
* @param {module:route4me-node~RequestCallback} [callback]
*/
- deleteProfile(vehicleId, callback) {
+ deleteProfile(profileId, callback) {
return this.r._makeRequest5({
method: "DELETE",
- path: `/api/v5.0/vehicle-profiles/${vehicleId}`,
+ path: `/api/v5.0/vehicle-profiles/${profileId}`,
validationContext: "Vehicles.ResponseVehicleProfile200",
}, callback)
}
@@ -453,7 +451,7 @@ class VehiclesV5 {
* @see {@link https://route4me.io/docs/#get-vehicles}
* @since 1.0.14
*
- * @param {Object} vehicleId - Vehicle ID.
+ * @param {String} vehicleId - Vehicle ID.
* @param {Object} data - Profile properties.
* @param {String} data.vehicle_profile_id -A unique ID of the vehicle profile.
* @param {Number} data.root_member_id - A unique ID of the root member.
@@ -560,10 +558,10 @@ class VehiclesV5 {
* @see {@link https://route4me.io/docs/#get-vehicles}
* @since 1.0.14
*
- * @param {String} vehicleLicensePlate - A license plate of the vehicle
+ * @param {String} vehicleLicensePlate - A license plate of the vehicle
* @param {module:route4me-node~RequestCallback} [callback]
*/
- license(vehicleLicensePlate, callback) {
+ getVehicleProfileByLicense(vehicleLicensePlate, callback) {
return this.r._makeRequest5({
method: "GET",
path: "/api/v5.0/vehicles/license",
@@ -585,10 +583,388 @@ class VehiclesV5 {
return this.r._makeRequest5({
method: "GET",
path: "/api/v5.0/vehicles/location",
- qs: { ids: vehicleIds.toString() },
+ qs: { ids: vehicleIds },
+ indices: true,
validationContext: "Vehicles.inline_response_200_1",
}, callback)
}
+
+ /**
+ * Update the Vehicle list asynchronously by sending the corresponding body payload
+ * with the Vehicles list with their parameters.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object[]} vehicles - Vehicle properties.
+ * @param {String} vehicles.vehicle_id - A unique identification
+ * 32-char string of the vehicle.
+ * @param {String} vehicles.vehicle_alias - Internal name of the vehicle.
+ * @param {String} vehicles.vehicle_vin - Vehicle VIN number
+ * @param {Number} vehicles.vehicle_reg_state_id - An ID of the state,
+ * where vehicle was registered.
+ * @param {Number} vehicles.vehicle_reg_country_id - An ID of the country,
+ * where vehicle was registered.
+ * @param {String} vehicles.vehicle_license_plate - A license plate of the vehicle
+ * @param {String} vehicles.vehicle_type_id - Vehicle type ID
+ * Possible values: "sedan", "suv", "pickup_truck", "van", "18wheeler", "cabin", "hatchback",
+ * "motorcyle", "waste_disposal", "tree_cutting", "bigrig", "cement_mixer",
+ * "livestock_carrier", "dairy","tractor_trailer"
+ *
+ * @param {String} vehicles.vehicle_make - Vehicle maker brend.
+ * Possible values: "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc",
+ * "hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi",
+ * "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota",
+ * "volvo", "western star"
+ *
+ * @param {Number} vehicles.vehicle_model_year - A year of the vehicle model.
+ * @param {String} vehicles.vehicle_model - A model of the vehicle.
+ * @param {Number} vehicles.vehicle_year_acquired - A year of the vehicle acquisition.
+ * @param {String} vehicles.fuel_type - A type of the fuel.
+ * Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel",
+ * "electric", "hybrid"
+ *
+ * @param {Number} vehicles.vehicle_profile_id - Vehicle profile ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ bulkUpdate(vehicles, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/bulk/update",
+ body: { vehicles },
+ validationContext: "Vehicles.Accepted",
+ }, callback)
+ }
+
+ /**
+ * Delete the Vehicles from the list of their ids asynchronously.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {String[]} vehicleIds - Vehicle IDs to delete.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ bulkDelete(vehicleIds, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/bulk/delete",
+ qs: { vehicle_ids: vehicleIds },
+ indices: true,
+ validationContext: "Vehicles.Accepted",
+ }, callback)
+ }
+
+ /**
+ * Activate the Vehicles from the list of their ids asynchronously.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {String[]} [vehicleIds] - Array of the vehicle ids to activate.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ bulkActivate(vehicleIds, callback) {
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof vehicleIds) {
+ cb = vehicleIds
+
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/bulk/activate",
+ validationContext: "Vehicles.Accepted",
+ }, cb)
+ }
+
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/bulk/activate",
+ qs: { vehicle_ids: vehicleIds },
+ indices: true,
+ validationContext: "Vehicles.Accepted",
+ }, cb)
+ }
+
+ /**
+ * Deactivate the Vehicles from the list of their ids asynchronously.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {String[]} [vehicleIds] - Array of the vehicle ids to deactivate.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ bulkDeactivate(vehicleIds, callback) {
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof vehicleIds) {
+ cb = vehicleIds
+
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/bulk/deactivate",
+ validationContext: "Vehicles.Accepted",
+ }, cb)
+ }
+
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/bulk/deactivate",
+ qs: { vehicle_ids: vehicleIds },
+ indices: true,
+ validationContext: "Vehicles.Accepted",
+ }, cb)
+ }
+
+ /**
+ * Restore the Vehicles from the list of their ids asynchronously.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {String[]} [vehicleIds] - Array of the vehicle ids to restore.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ bulkRestore(vehicleIds, callback) {
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof vehicleIds) {
+ cb = vehicleIds
+
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/bulk/restore",
+ validationContext: "Vehicles.Accepted",
+ }, cb)
+ }
+
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/bulk/restore",
+ qs: { vehicle_ids: vehicleIds },
+ indices: true,
+ validationContext: "Vehicles.Accepted",
+ }, cb)
+ }
+
+ /**
+ * Sync a Pending Vehicle from Telematics.
+ * Sync the Vehicle by sending the corresponding body payload with the Vehicle's parameters
+ * and by specifiying `vehicle_alias`, `r4m_telematics_gateway_connection_id`
+ * and `r4m_telematics_gateway_vehicle_id` in this body payload.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} data - Vehicle properties.
+ * @param {String} data.vehicle_alias - Internal name of the vehicle.
+ * @param {String} data.vehicle_vin - Vehicle VIN number
+ * @param {Number} data.vehicle_reg_state_id - An ID of the state,
+ * where vehicle was registered.
+ * @param {Number} data.vehicle_reg_country_id - An ID of the country,
+ * where vehicle was registered.
+ * @param {String} data.vehicle_license_plate - A license plate of the vehicle
+ * @param {String} data.vehicle_type_id - Vehicle type ID
+ * Possible values: "sedan", "suv", "pickup_truck", "van", "18wheeler", "cabin", "hatchback",
+ * "motorcyle", "waste_disposal", "tree_cutting", "bigrig", "cement_mixer",
+ * "livestock_carrier", "dairy","tractor_trailer"
+ *
+ * @param {String} data.vehicle_make - Vehicle maker brend.
+ * Possible values: "american coleman", "bmw", "chevrolet", "ford", "freightliner", "gmc",
+ * "hino", "honda", "isuzu", "kenworth", "mack", "mercedes-benz", "mitsubishi",
+ * "navistar", "nissan", "peterbilt", "renault", "scania", "sterling", "toyota",
+ * "volvo", "western star"
+ *
+ * @param {Number} data.vehicle_model_year - A year of the vehicle model.
+ * @param {String} data.vehicle_model - A model of the vehicle.
+ * @param {Number} data.vehicle_year_acquired - A year of the vehicle acquisition.
+ * @param {String} data.fuel_type - A type of the fuel.
+ * Possible values: "unleaded 87", "unleaded 89", "unleaded 91", "unleaded 93", "diesel",
+ * "electric", "hybrid"
+ *
+ * @param {Number} data.external_telematics_vehicle_id - External telematics vehicle ID.
+ * @param {Number} data.r4m_telematics_gateway_connection_id - A unique ID of the Route4Me
+ * telematics gateway connection.
+ * @param {Number} data.r4m_telematics_gateway_vehicle_id - A unique ID of the Route4Me
+ * telematics gateway vehicle.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ syncPending(data, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicles/sync/pending",
+ body: data,
+ validationContext: "Vehicles.ResponseVehicle200",
+ }, callback)
+ }
+
+ /**
+ * View Job Tracker Status.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {String} jobId - Current Job ID..
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ jobTrackerStatus(jobId, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: `/api/v5.0/vehicles/job-tracker/status/${jobId}`,
+ validationContext: "Vehicles.Accepted",
+ }, callback)
+ }
+
+ /**
+ * View Job Tracker Result.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {String} jobId - Current Job ID..
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ jobTrackerResult(jobId, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: `/api/v5.0/vehicles/job-tracker/result/${jobId}`,
+ validationContext: "Vehicles.Accepted",
+ }, callback)
+ }
+
+ /**
+ * List all the Vehicle Capacity Profiles.
+ * Filtering Data: Send Vehicle Capacity Profile attribute's name with
+ * the corresponding value, e.g. max_volume = 99.99
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} [options] - Request options.
+ * @param {Boolean} [options.mergePagesParam = false] - Paginate all the data into
+ * one page only.
+ * @param {Number} [options.page = 1] - The requested page.
+ * @param {Number} [options.per_page = 100] - The number of Vehicles per page.
+ * @param {String[]} [options.order_by] - Sorting field and its sorting direction,
+ * e.g.: [["max_volume", "asc"], ["max_revenue", "desc"]]
+ * @param {String} [options.filters] - Search value.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ listCapacityProfiles(options, callback) {
+ let opt = options || {}
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof opt) {
+ cb = opt
+ opt = {}
+ } else if (opt.filters) {
+ opt = utils.clone(opt)
+ opt.filters = { search_query: opt.filters }
+ }
+
+ return this.r._makeRequest5({
+ method: "GET",
+ path: "/api/v5.0/vehicle-capacity-profiles",
+ qs: opt,
+ indices: true,
+ validationContext: "Vehicles.ResponsePaginatedVehicleCapacityProfile",
+ }, cb)
+ }
+
+ /**
+ * Create a new Vehicle Capacity Profile.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Object} data - Capacity profile properties.
+ * @param {Number} data.vehicle_capacity_profile_id - A unique ID of a vehicle capacity profile.
+ * @param {Number} data.root_member_id - A unique ID of the root member.
+ * @param {string} data.name - The name of a vehicle capacity profile.
+ * @param {Number} data.max_volume - The maximum volume a veicle can carry.
+ * @param {Number} data.max_weight - The maximum weight a vehicle can carry.
+ * @param {Number} data.max_items_number - The maximum number of items a vehicle can carry.
+ * @param {Number} data.max_revenue - The maximum revenue an owner company
+ * can gain from a vehicle.
+ * @param {String} data.max_volume_unit - A unit in which maximum volume is measured.
+ * @param {String} data.max_weight_unit - A unit in which maximum weight is measured.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ createCapacityProfiles(data, callback) {
+ return this.r._makeRequest5({
+ method: "POST",
+ path: "/api/v5.0/vehicle-capacity-profiles",
+ body: data,
+ validationContext: "Vehicles.ResponseVehicleCapacityProfile200",
+ }, callback)
+ }
+
+ /**
+ * Get a Vehicle Capacity Profile by its ID.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Number} id - Vehicle Capacity Profile ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ getCapacityProfiles(id, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ path: `/api/v5.0/vehicle-capacity-profiles/${id}`,
+ validationContext: "Vehicles.ResponseVehicleCapacityProfile200",
+ }, callback)
+ }
+
+ /**
+ * Delete the Vehicle Capacity Profile by its ID.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Number} id - Vehicle Capacity Profile ID.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ deleteCapacityProfiles(id, callback) {
+ return this.r._makeRequest5({
+ method: "DELETE",
+ path: `/api/v5.0/vehicle-capacity-profiles/${id}`,
+ validationContext: "Vehicles.ResponseVehicleCapacityProfile200",
+ }, callback)
+ }
+
+ /**
+ * Update the Vehicle Capacity Profile by its ID.
+ *
+ * @see {@link https://route4me.io/docs/#get-vehicles}
+ * @since 1.0.14
+ *
+ * @param {Number} id - Vehicle Capacity Profile ID.
+ * @param {Object} data - Capacity profile properties.
+ * @param {Number} data.vehicle_capacity_profile_id - A unique ID of a vehicle capacity profile.
+ * @param {Number} data.root_member_id - A unique ID of the root member.
+ * @param {Number} data.name - The name of a vehicle capacity profile.
+ * @param {Number} data.max_volume - The maximum volume a veicle can carry.
+ * @param {Number} data.max_weight - The maximum weight a vehicle can carry.
+ * @param {Number} data.max_items_number - The maximum number of items a vehicle can carry.
+ * @param {Number} data.max_revenue - The maximum revenue an owner company can
+ * gain from a vehicle.
+ * @param {String} data.created_at - When the vehicle capacity profile was created.
+ * @param {String} data.updated_at - When the vehicle capacity profile was updated.
+ * @param {String} data.deleted_at - When the vehicle capacity profile was deleted.
+ * @param {String} data.max_volume_unit - A unit in which maximum volume is measured.
+ * @param {String} data.max_weight_unit - A unit in which maximum weight is measured.
+ * @param {module:route4me-node~RequestCallback} [callback]
+ */
+ updateCapacityProfiles(id, data, callback) {
+ return this.r._makeRequest5({
+ method: "PATCH",
+ path: `/api/v5.0/vehicle-capacity-profiles/${id}`,
+ body: data,
+ validationContext: "Vehicles.ResponseVehicleCapacityProfile200",
+ }, callback)
+ }
}
module.exports = VehiclesV5
diff --git a/src/route4me.js b/src/route4me.js
index 21b198a..9652ea6 100644
--- a/src/route4me.js
+++ b/src/route4me.js
@@ -15,9 +15,11 @@ const Notes = require("./resources/notes")
const Optimizations = require("./resources/optimizations")
const Orders = require("./resources/orders")
const Routes = require("./resources/routes")
+const TeamManagement = require("./resources/team-management")
const Territories = require("./resources/territories")
const Tracking = require("./resources/tracking")
const Vehicles = require("./resources/vehicles")
+const VehiclesV5 = require("./resources/vehicles-v5")
const packageJson = require("./../package.json") // eslint-disable-line import/no-dynamic-require
const utils = require("./utils")
@@ -47,9 +49,11 @@ const RequestManager = require("./request-manager")
* * [Orders ]{@link Orders}
* * [OrderCustomFields]{@link OrderCustomFields}
* * [Routes ]{@link Routes}
+ * * [TeamManagement ]{@link TeamManagement}
* * [Territories ]{@link Territories}
* * [Tracking ]{@link Tracking}
* * [Vehicles ]{@link Vehicles}
+ * * [VehiclesV5 ]{@link VehiclesV5}
*
* Each member corresponds to an bunch of methods, described in API-documentation,
* but the most methods in this SDK have unified names:
@@ -190,6 +194,11 @@ class Route4Me {
* @since 0.1.8
*/
this.Routes = new Routes(req)
+ /**
+ * **TeamManagement** related API calls
+ * @type {TeamManagement}
+ */
+ this.TeamManagement = new TeamManagement(req)
/**
* **Territories** related API calls
* @type {Territories}
@@ -205,6 +214,11 @@ class Route4Me {
* @type {Vehicles}
*/
this.Vehicles = new Vehicles(req)
+ /**
+ * **VehiclesV5** related API calls
+ * @type {VehiclesV5}
+ */
+ this.VehiclesV5 = new VehiclesV5(req)
this._logger.debug({ msg: "initialized", version: Route4Me.version })
diff --git a/src/utils.js b/src/utils.js
index b874532..c52d9c6 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -218,6 +218,233 @@ function toIsoDateString(d) {
return d.toISOString().substring(0, 10)
}
+// ( added by 0x000f, 20220910
+// bc superagent has hardcoded "indices: false" it prevent to have array indexes in query string
+// also added dependencies to project 'cookiejar' and 'qs'
+// use in request-manager.js RequestManager._makeRequest()
+
+/* eslint-disable func-names, yoda, no-new-object, no-param-reassign, no-var, vars-on-top,
+global-require, prefer-destructuring, prefer-arrow-callback, no-plusplus, no-return-assign,
+no-func-assign, eqeqeq, no-shadow, no-sequences, no-restricted-syntax */
+function patchRequest(Request) {
+ const parse = require("url").parse
+ const qs = require("qs")
+ const https = require("https")
+ const http = require("http")
+ const CookieJar = require("cookiejar")
+
+ const exports = {
+ protocols: {
+ "http:": http,
+ "https:": https,
+ "http2:": null // TODO: add http2
+ }
+ }
+
+ const hasOwn = Object.hasOwn || function (object, property) {
+ if (object == null) {
+ throw new TypeError("Cannot convert undefined or null to object")
+ }
+ return Object.prototype.hasOwnProperty.call(new Object(object), property)
+ }
+
+ function _typeof(obj) {
+ "@babel/helpers - typeof"
+
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator
+ ? function (obj) {
+ return typeof obj
+ }
+ : function (obj) {
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
+ }, _typeof(obj)
+ }
+
+ Request.request = function () {
+ var _this4 = this
+
+ if (this.req) return this.req
+ var options = {}
+
+ try {
+ var query = qs.stringify(this.qs, {
+ // ( changed by 0x000f
+ // indices: false,
+ indices: true,
+ // changed by 0x000f )
+ strictNullHandling: true
+ })
+
+ if (query) {
+ this.qs = {}
+
+ this._query.push(query)
+ }
+
+ this._finalizeQueryString()
+ } catch (err) {
+ return this.emit("error", err)
+ }
+
+ var url = this.url
+ var retries = this._retries // Capture backticks as-is from the final query string built above.
+ // Note: this'll only find backticks entered in req.query(String)
+ // calls, because qs.stringify unconditionally encodes backticks.
+
+ var queryStringBackticks
+
+ if (url.includes("`")) {
+ var queryStartIndex = url.indexOf("?")
+
+ if (queryStartIndex !== -1) {
+ var queryString = url.slice(queryStartIndex + 1)
+ queryStringBackticks = queryString.match(/`|%60/g)
+ }
+ } // default to http://
+
+ if (url.indexOf("http") !== 0) url = "http://".concat(url)
+ url = parse(url) // See https://github.com/visionmedia/superagent/issues/1367
+
+ if (queryStringBackticks) {
+ var i = 0
+ url.query = url.query.replace(/%60/g, function () {
+ return queryStringBackticks[i++]
+ })
+ url.search = "?".concat(url.query)
+ url.path = url.pathname + url.search
+ } // support unix sockets
+
+ if (/^https?\+unix:/.test(url.protocol) === true) {
+ // get the protocol
+ url.protocol = "".concat(url.protocol.split("+")[0], ":") // get the socket, path
+
+ var unixParts = url.path.match(/^([^/]+)(.+)$/)
+ options.socketPath = unixParts[1].replace(/%2F/g, "/")
+ url.path = unixParts[2]
+ } // Override IP address of a hostname
+
+ if (this._connectOverride) {
+ var _url = url
+ var hostname = _url.hostname
+ var match = hostname in this._connectOverride ? this._connectOverride[hostname] : this._connectOverride["*"]
+
+ if (match) {
+ // backup the real host
+ if (!this._header.host) {
+ this.set("host", url.host)
+ }
+
+ var newHost
+ var newPort
+
+ if (_typeof(match) === "object") {
+ newHost = match.host
+ newPort = match.port
+ } else {
+ newHost = match
+ newPort = url.port
+ } // wrap [ipv6]
+
+ url.host = /:/.test(newHost) ? "[".concat(newHost, "]") : newHost
+
+ if (newPort) {
+ url.host += ":".concat(newPort)
+ url.port = newPort
+ }
+
+ url.hostname = newHost
+ }
+ } // options
+
+ options.method = this.method
+ options.port = url.port
+ options.path = url.path
+ options.host = url.hostname
+ options.ca = this._ca
+ options.key = this._key
+ options.pfx = this._pfx
+ options.cert = this._cert
+ options.passphrase = this._passphrase
+ options.agent = this._agent
+ options.lookup = this._lookup
+ options.rejectUnauthorized = typeof this._disableTLSCerts === "boolean" ? !this._disableTLSCerts : process.env.NODE_TLS_REJECT_UNAUTHORIZED !== "0" // Allows request.get('https://1.2.3.4/').set('Host', 'example.com')
+
+ if (this._header.host) {
+ options.servername = this._header.host.replace(/:\d+$/, "")
+ }
+
+ if (this._trustLocalhost && /^(?:localhost|127\.0\.0\.\d+|(0*:)+:0*1)$/.test(url.hostname)) {
+ options.rejectUnauthorized = false
+ } // initiate request
+
+ var module_ = this._enableHttp2 ? exports.protocols["http2:"].setProtocol(url.protocol) : exports.protocols[url.protocol] // request
+
+ this.req = module_.request(options)
+ var req = this.req // set tcp no delay
+
+ req.setNoDelay(true)
+
+ if (options.method !== "HEAD") {
+ req.setHeader("Accept-Encoding", "gzip, deflate")
+ }
+
+ this.protocol = url.protocol
+ this.host = url.host // expose events
+
+ req.once("drain", function () {
+ _this4.emit("drain")
+ })
+ req.on("error", function (error) {
+ // flag abortion here for out timeouts
+ // because node will emit a faux-error "socket hang up"
+ // when request is aborted before a connection is made
+ // if not the same, we are in the **old** (cancelled) request,
+ // so need to continue (same as for above)
+ if (_this4._aborted) return
+
+ // if we've received a response then we don't want to let
+ // an error in the request blow up the response
+ if (_this4._retries !== retries) return
+
+ if (_this4.response) return
+
+ _this4.callback(error)
+ }) // auth
+
+ if (url.auth) {
+ var auth = url.auth.split(":")
+ this.auth(auth[0], auth[1])
+ }
+
+ if (this.username && this.password) {
+ this.auth(this.username, this.password)
+ }
+
+ for (var key in this.header) {
+ if (hasOwn(this.header, key)) req.setHeader(key, this.header[key])
+ } // add cookies
+
+ if (this.cookies) {
+ if (hasOwn(this._header, "cookie")) {
+ // merge
+ var temporaryJar = new CookieJar.CookieJar()
+ temporaryJar.setCookies(this._header.cookie.split(""))
+ temporaryJar.setCookies(this.cookies.split(""))
+ req.setHeader("Cookie", temporaryJar.getCookies(CookieJar.CookieAccessInfo.All).toValueString())
+ } else {
+ req.setHeader("Cookie", this.cookies)
+ }
+ }
+ return req
+ }
+}
+/* eslint-disable func-names, yoda, no-new-object, no-param-reassign, no-var, vars-on-top,
+global-require, prefer-destructuring, prefer-arrow-callback, no-plusplus, no-return-assign,
+no-func-assign, eqeqeq, no-shadow, no-sequences, no-restricted-syntax */
+
+exports.patchRequest = patchRequest
+// added by 0x000f, 20220910 )
+
exports.ILogger = ILogger
exports.CustomInternalPostProcessing = CustomInternalPostProcessing
diff --git a/test/resources/address-book-v5.spec.js b/test/resources/address-book-v5.spec.js
index 1af3209..47a086a 100644
--- a/test/resources/address-book-v5.spec.js
+++ b/test/resources/address-book-v5.spec.js
@@ -1,7 +1,6 @@
"use strict"
const request = require("superagent")
-const sinon = require("sinon")
const saMock = require("superagent-mocker")(request)
const helper = require("./../helper")
diff --git a/test/resources/team_management.spec.js b/test/resources/team_management.spec.js
index 858260d..5a360ce 100644
--- a/test/resources/team_management.spec.js
+++ b/test/resources/team_management.spec.js
@@ -18,11 +18,11 @@ describe(helper.toSuiteName(__filename), () => {
beforeEach(() => {
req = null
- saMock.get("*", (r) => { req = r; req.method = "GET"; return { body: {} } })
- saMock.post("*", (r) => { req = r; req.method = "POST"; return { body: {} } })
- saMock.del("*", (r) => { req = r; req.method = "DELETE"; return { body: {} } })
- saMock.put("*", (r) => { req = r; req.method = "PUT"; return { body: {} } })
- saMock.patch("*", (r) => { req = r; req.method = "PATCH"; return { body: {} } })
+ saMock.get("*", (r) => { req = r; req.method = "GET"; return { body: {} } })
+ saMock.post("*", (r) => { req = r; req.method = "POST"; return { body: {} } })
+ saMock.del("*", (r) => { req = r; req.method = "DELETE"; return { body: {} } })
+ saMock.put("*", (r) => { req = r; req.method = "PUT"; return { body: {} } })
+ saMock.patch("*", (r) => { req = r; req.method = "PATCH"; return { body: {} } })
})
afterEach(() => {
diff --git a/test/resources/vehicles-v5.spec.js b/test/resources/vehicles-v5.spec.js
new file mode 100644
index 0000000..9847d8e
--- /dev/null
+++ b/test/resources/vehicles-v5.spec.js
@@ -0,0 +1,866 @@
+"use strict"
+
+const request = require("superagent")
+const saMock = require("superagent-mocker")(request)
+
+const helper = require("../helper")
+
+const route4me = require("./../../dist")
+
+const testApiKey = "11111111111111111111111111111111"
+
+
+describe(helper.toSuiteName(__filename), () => {
+ describe("SDK methods", () => {
+ const route4meClient = new route4me.Route4Me(testApiKey)
+ const resource = route4meClient.VehiclesV5
+ let req
+
+ beforeEach(() => {
+ req = null
+ saMock.get("*", (r) => { req = r; req.method = "GET"; return { "body": {} } })
+ saMock.post("*", (r) => { req = r; req.method = "POST"; return { "body": {} } })
+ saMock.del("*", (r) => { req = r; req.method = "DELETE"; return { "body": {} } })
+ saMock.put("*", (r) => { req = r; req.method = "PUT"; return { "body": {} } })
+ saMock.patch("*", (r) => { req = r; req.method = "PATCH"; return { "body": {} } })
+ })
+
+ afterEach(() => {
+ saMock.clearRoutes()
+ })
+
+ describe("create", () => {
+ const data = {
+ member_id: 205318,
+ vehicle_alias: 'FORD FIKUS',
+ vehicle_vin: '1NPAX6EX50743',
+ fuel_type: 'diesel'
+ };
+
+ it("should call route4me", (done) => {
+ resource.create(data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles",
+ null,
+ {
+ member_id: 205318,
+ vehicle_alias: 'FORD FIKUS',
+ vehicle_vin: '1NPAX6EX50743',
+ fuel_type: 'diesel'
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("list", () => {
+ const options = {
+ page: 1,
+ per_page: 10
+ };
+
+ it("should call route4me with options", (done) => {
+ resource.list(options, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles",
+ {
+ "page": "1",
+ "per_page": "10"
+ },
+ null
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without options", (done) => {
+ resource.list((err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("getVehiclesPaginated", () => {
+ const options = {
+ page: 1,
+ per_page: 10,
+ show: "all",
+ search_query: "TST 15"
+ };
+
+ it("should call route4me with options", (done) => {
+ resource.getVehiclesPaginated(options, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/paginate",
+ {
+ "page": "1",
+ "per_page": "10",
+ "show": "all",
+ "search_query": "TST 15"
+ },
+ null
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without options", (done) => {
+ resource.getVehiclesPaginated((err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/paginate",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("get", () => {
+ const vehicle_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+
+ it("should call route4me", (done) => {
+ resource.get(vehicle_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/004ADB6E1335BA6BCE4FB8A89E6311",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("delete", () => {
+ const vehicle_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+
+ it("should call route4me", (done) => {
+ resource.delete(vehicle_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "DELETE",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/004ADB6E1335BA6BCE4FB8A89E6311",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("update", () => {
+ const vehicle_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+ const data = {
+ member_id: 205318,
+ vehicle_alias: 'FORD F750 TST SUPER'
+ };
+
+ it("should call route4me", (done) => {
+ resource.update(vehicle_id, data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "PATCH",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/004ADB6E1335BA6BCE4FB8A89E6311",
+ {},
+ {
+ member_id: 205318,
+ vehicle_alias: 'FORD F750 TST SUPER'
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("getTrack", () => {
+ const vehicle_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+ const options = {
+ start: "2020-01-01",
+ end: "2022-12-31"
+ };
+
+ it("should call route4me with options", (done) => {
+ resource.getTrack(vehicle_id, options, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/004ADB6E1335BA6BCE4FB8A89E6311/track",
+ {
+ "start": "2020-01-01",
+ "end": "2022-12-31"
+ },
+ null
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without options", (done) => {
+ resource.getTrack(vehicle_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/004ADB6E1335BA6BCE4FB8A89E6311/track",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("assign", () => {
+ const data = {
+ vehicle_id: "004ADB6E1335BA6BCE4FB8A89E6311",
+ vehicle_license_plate: "CVH4561",
+ assigned_member_id: 2288930,
+ expires_at: 100
+ };
+
+ it("should call route4me", (done) => {
+ resource.assign(data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/assign",
+ null,
+ {
+ vehicle_id: "004ADB6E1335BA6BCE4FB8A89E6311",
+ vehicle_license_plate: "CVH4561",
+ assigned_member_id: 2288930,
+ expires_at: 100
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("getProfiles", () => {
+ const options = {
+ with_pagination: 1,
+ page: 2,
+ per_page: 10
+ };
+
+ it("should call route4me with options", (done) => {
+ resource.getProfiles(options, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-profiles",
+ {
+ "with_pagination": "1",
+ "page": "2",
+ "per_page": "10"
+ },
+ null
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without options", (done) => {
+ resource.getProfiles((err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-profiles",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("createProfile", () => {
+ const data = {
+ root_member_id: 205318,
+ name: "temp-prof"
+ };
+
+ it("should call route4me", (done) => {
+ resource.createProfile(data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-profiles",
+ null,
+ {
+ root_member_id: 205318,
+ name: "temp-prof"
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("getProfile", () => {
+ const profile_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+
+ it("should call route4me", (done) => {
+ resource.getProfile(profile_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-profiles/004ADB6E1335BA6BCE4FB8A89E6311",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("deleteProfile", () => {
+ const profile_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+
+ it("should call route4me", (done) => {
+ resource.deleteProfile(profile_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "DELETE",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-profiles/004ADB6E1335BA6BCE4FB8A89E6311",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("updateProfile", () => {
+ const vehicle_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+ const data = {
+ member_id: 205318,
+ vehicle_alias: 'FORD F750 TST SUPER'
+ };
+
+ it("should call route4me", (done) => {
+ resource.updateProfile(vehicle_id, data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "PATCH",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-profiles/004ADB6E1335BA6BCE4FB8A89E6311",
+ {},
+ {
+ member_id: 205318,
+ vehicle_alias: 'FORD F750 TST SUPER'
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("search", () => {
+ const data = {
+ vehicle_ids: ["004ADB6E1335BA6BCE4FB8A89E6311"],
+ lat: 71,
+ lng: 72
+ };
+
+ it("should call route4me", (done) => {
+ resource.search(data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/search",
+ {},
+ {
+ vehicle_ids: ["004ADB6E1335BA6BCE4FB8A89E6311"],
+ lat: 71,
+ lng: 72
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("execute", () => {
+ const data = {
+ vehicle_ids: ["004ADB6E1335BA6BCE4FB8A89E6311"],
+ lat: 71,
+ lng: 72
+ };
+
+ it("should call route4me", (done) => {
+ resource.execute(data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/execute",
+ {},
+ {
+ vehicle_ids: ["004ADB6E1335BA6BCE4FB8A89E6311"],
+ lat: 71,
+ lng: 72
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("getVehicleProfileByLicense", () => {
+ const license = "1HDF56";
+
+ it("should call route4me", (done) => {
+ resource.getVehicleProfileByLicense(license, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/license",
+ {
+ "vehicle_license_plate": "1HDF56"
+ },
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("location", () => {
+ const vehicle_ids = ["004ADB6E1335BA6BCE4FB8A89E6311"];
+
+ it("should call route4me", (done) => {
+ resource.location(vehicle_ids, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/location",
+ {
+ "ids": "004ADB6E1335BA6BCE4FB8A89E6311"
+ },
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("bulkUpdate", () => {
+ const vehicles = [{
+ vehicle_id: "004ADB6E1335BA6BCE4FB8A89E6311",
+ vehicle_alias: 'FORD FIKUS',
+ vehicle_vin: '1NPAX6EX50743',
+ fuel_type: 'diesel'
+ }];
+
+ it("should call route4me", (done) => {
+ resource.bulkUpdate(vehicles, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/update",
+ {},
+ {
+ vehicles: [{
+ vehicle_id: "004ADB6E1335BA6BCE4FB8A89E6311",
+ vehicle_alias: 'FORD FIKUS',
+ vehicle_vin: '1NPAX6EX50743',
+ fuel_type: 'diesel'
+ }]
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("bulkDelete", () => {
+ const vehicle_ids = ["004ADB6E1335BA6BCE4FB8A89E6311"];
+
+ it("should call route4me", (done) => {
+ resource.bulkDelete(vehicle_ids, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/delete",
+ {
+ "vehicle_ids": "004ADB6E1335BA6BCE4FB8A89E6311"
+ },
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("bulkActivate", () => {
+ const vehicle_ids = ["004ADB6E1335BA6BCE4FB8A89E6311"];
+
+ it("should call route4me with ids", (done) => {
+ resource.bulkActivate(vehicle_ids, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/activate",
+ {
+ "vehicle_ids": "004ADB6E1335BA6BCE4FB8A89E6311"
+ },
+ null
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without ids", (done) => {
+ resource.bulkActivate((err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/activate",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("bulkDeactivate", () => {
+ const vehicle_ids = ["004ADB6E1335BA6BCE4FB8A89E6311"];
+
+ it("should call route4me with ids", (done) => {
+ resource.bulkDeactivate(vehicle_ids, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/deactivate",
+ {
+ "vehicle_ids": "004ADB6E1335BA6BCE4FB8A89E6311"
+ },
+ null
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without ids", (done) => {
+ resource.bulkDeactivate((err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/deactivate",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("bulkRestore", () => {
+ const vehicle_ids = ["004ADB6E1335BA6BCE4FB8A89E6311"];
+
+ it("should call route4me with ids", (done) => {
+ resource.bulkRestore(vehicle_ids, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/restore",
+ {
+ "vehicle_ids": "004ADB6E1335BA6BCE4FB8A89E6311"
+ },
+ null
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without ids", (done) => {
+ resource.bulkRestore((err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/restore",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("syncPending", () => {
+ const data = {
+ vehicle_alias: 'FORD FIKUS',
+ vehicle_vin: '1NPAX6EX50743'
+ };
+
+ it("should call route4me", (done) => {
+ resource.syncPending(data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/sync/pending",
+ {},
+ {
+ vehicle_alias: 'FORD FIKUS',
+ vehicle_vin: '1NPAX6EX50743'
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("jobTrackerStatus", () => {
+ const job_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+
+ it("should call route4me", (done) => {
+ resource.jobTrackerStatus(job_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/job-tracker/status/004ADB6E1335BA6BCE4FB8A89E6311",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("jobTrackerResult", () => {
+ const job_id = "004ADB6E1335BA6BCE4FB8A89E6311";
+
+ it("should call route4me", (done) => {
+ resource.jobTrackerResult(job_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicles/job-tracker/result/004ADB6E1335BA6BCE4FB8A89E6311",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("listCapacityProfiles", () => {
+ const options = {
+ mergePagesParam: true,
+ page: 1,
+ per_page: 10,
+ search_query: "TST 15"
+ };
+
+ it("should call route4me with options", (done) => {
+ resource.listCapacityProfiles(options, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-capacity-profiles",
+ {
+ "mergePagesParam": "true",
+ "page": "1",
+ "per_page": "10",
+ "search_query": "TST 15"
+ },
+ null
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without options", (done) => {
+ resource.listCapacityProfiles((err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-capacity-profiles",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("createCapacityProfiles", () => {
+ const data = {
+ name: 'FORD FIKUS',
+ vehicle_capacity_profile_id: '1NPAX6EX50743'
+ };
+
+ it("should call route4me", (done) => {
+ resource.createCapacityProfiles(data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-capacity-profiles",
+ {},
+ {
+ name: 'FORD FIKUS',
+ vehicle_capacity_profile_id: '1NPAX6EX50743'
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("getCapacityProfiles", () => {
+ const profile_id = '1NPAX6EX50743'
+
+ it("should call route4me", (done) => {
+ resource.getCapacityProfiles(profile_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "GET",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-capacity-profiles/1NPAX6EX50743",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("deleteCapacityProfiles", () => {
+ const profile_id = '1NPAX6EX50743'
+
+ it("should call route4me", (done) => {
+ resource.deleteCapacityProfiles(profile_id, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "DELETE",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-capacity-profiles/1NPAX6EX50743",
+ {},
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("updateCapacityProfiles", () => {
+ const profile_id = '1NPAX6EX50743'
+ const data = {
+ root_member_id: 205318,
+ name: "MAX CAP",
+ max_volume: 15,
+ max_volume_unit: "kg"
+ };
+
+ it("should call route4me", (done) => {
+ resource.updateCapacityProfiles(profile_id, data, (err, res) => {
+ expect(err).is.null
+ expect(res).to.exist
+
+ helper.expectRequest(req,
+ "PATCH",
+ route4meClient.baseUrl5() + "/api/v5.0/vehicle-capacity-profiles/1NPAX6EX50743",
+ {},
+ {
+ root_member_id: 205318,
+ name: "MAX CAP",
+ max_volume: 15,
+ max_volume_unit: "kg"
+ }
+ )
+ done()
+ })
+ })
+ })
+ })
+})
From 6be425ae553aa0d85d4718b92da5b9d3bf4788e8 Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Mon, 10 Oct 2022 22:23:25 +0500
Subject: [PATCH 4/9] Added description, tests and examples for Advanced
constraints.
---
book/en/code/Optimizations.md | 69 ++++++++
.../optimizations-advanced-constraints.js | 85 +++++++++
...te-an-optimization-advanced-constraints.js | 94 ++++++++++
package.json | 2 +-
src/resources/optimizations.js | 163 ++++++++++++++++++
test/resources/optimizations.spec.js | 155 +++++++++++++++++
6 files changed, 567 insertions(+), 1 deletion(-)
create mode 100644 code-examples/optimizations-advanced-constraints.js
create mode 100644 examples/Optimizations/create-an-optimization-advanced-constraints.js
diff --git a/book/en/code/Optimizations.md b/book/en/code/Optimizations.md
index 92a47aa..5c41276 100644
--- a/book/en/code/Optimizations.md
+++ b/book/en/code/Optimizations.md
@@ -12,6 +12,7 @@ Optimizations facility
* [Optimizations](#Optimizations) ℗
* [new Optimizations(requestManager)](#new_Optimizations_new)
* [.create(optimization, isRedirect, [callback])](#Optimizations+create)
+ * [.create2(props, [isRedirect], callback)](#Optimizations+create2)
* [.get(id, [callback])](#Optimizations+get)
* [.list(states, options, [callback])](#Optimizations+list)
* [.update(id, data, [reoptimize], [callback])](#Optimizations+update)
@@ -45,6 +46,74 @@ Create a new optimization
| isRedirect | boolean
| |
| [callback] | module:route4me-node~RequestCallback.<jsonschema:Optimizations.Response>
| |
+
+
+### optimizations.create2(props, [isRedirect], callback)
+
+Create a new optimization with Advanced constraints
+
+**See**
+
+- [https://route4me.io/docs/#create-an-optimization](https://route4me.io/docs/#create-an-optimization)
+- [https://github.com/route4me/route4me-json-schemas/blob/master/Optimization_create.json](https://github.com/route4me/route4me-json-schemas/blob/master/Optimization_create.json)
+- [https://github.com/route4me/route4me-json-schemas/blob/master/RouteParameters.json](https://github.com/route4me/route4me-json-schemas/blob/master/RouteParameters.json)
+- [https://github.com/route4me/route4me-json-schemas/blob/master/Address.json](https://github.com/route4me/route4me-json-schemas/blob/master/Address.json)
+- [https://github.com/route4me/route4me-json-schemas/blob/master/Optimization_response.json](https://github.com/route4me/route4me-json-schemas/blob/master/Optimization_response.json)
+
+**Since**: 0.1.15
+
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| props | object
| | Optimization properties. Here are some required or useful properties, for full list of properties look at docs. |
+| props.parameters | object
| | Route Parameters. Here are some required and useful parameters, for full list of properties look at docs. |
+| props.parameters.algorithm_type | number
| | The optimization algorithm to be used. Possible values: 1 = TSP, 2 = VRP, 3 = CVRP_TW_SD, 4 = CVRP_TW_MD, 5 = TSP_TW, 6 = TSP_TW_CR, 7 = BBCVRP, 9 = ADVANCED_CVRP_TW,100 = ALG_NONE, 101 = ALG_LEGACY_DISTRIBUTED |
+| props.parameters.device_type | string
| | The type of the device that is creating this route. Possible values: "web", "iphone", "ipad", "android_phone", "android_tablet". |
+| props.parameters.distance_unit | string
| | The distance measurement unit for the route. Possible values: "mi", "km". |
+| props.parameters.route_max_duration | number
| | = 86400 - How many seconds a route can last at most. Default is 24 hours = 86400 seconds. |
+| props.parameters.route_time | number
| | = 25200 - Time when the route starts (relative to route_date) (Seconds). UTC timezone as well. Default is 07:00 UTC = 25200 seconds. |
+| props.parameters.travel_mode | number
| | The mode of travel that the directions should be optimized for. Possible values: "Driving", "Walking", "Bicycling". |
+| [props.parameters.optimize] | string
| | The driving directions will be generated biased for this selection. This has no impact on route sequencing. Possible values: "Distance", "Time", "timeWithTraffic". |
+| [props.parameters.parts] | number
| | Legacy feature which permits a user to request an example number of optimized routes. |
+| [props.parameters.route_date] | number
| | The route start date in UTC, unix timestamp seconds. Used to show users when the route will begin, also used for reporting and analytics. |
+| [props.parameters.route_name] | string
| | The name of this route. this route name will be accessible in the search API, and also will be displayed on the mobile device of a user. |
+| [props.parameters.rt] | boolean
| | The tour type of this route. rt is short for round trip, the optimization engine changes its behavior for round trip routes. |
+| [props.parameters.vehicle_capacity] | number
| | How much cargo can the vehicle carry (units, e.g. cubic meters) |
+| [props.parameters.vehicle_max_distance_mi] | number
| | Maximum distance for a single vehicle in this route (always in miles). |
+| [props.parameters.advanced_constraints] | number
| | Advanced Constraints. |
+| [props.parameters.advanced_constraints.max_cargo_weight] | number
| | Maximum cargo weight per route. |
+| [props.parameters.advanced_constraints.max_cargo_volume] | number
| | Maximum cargo volume per route. |
+| [props.parameters.advanced_constraints.max_capacity] | number
| | How much total cargo can be transported per route (units, e.g. cubic meters). |
+| [props.parameters.advanced_constraints.members_count] | number
| | Legacy feature which permits a user to request an example number of optimized routes. |
+| props.parameters.advanced_constraints.available_time_windows | Array.<array>
| | An array of the available time windows, e.g. [[43200, 72000], [TimeStart, TimeEnd]] Time Window Start in seconds: 7:00 am EST = (7 + 5) * 3600 = 43200 Time Window End in seconds: 15:00 am EST = (15 + 5) * 3600 = 72000 |
+| [props.parameters.advanced_constraints.tags] | Array.<string>
| | The driver tags specified in a team member's custom data. (e.g. 'driver skills': ["Class A CDL", "Class B CDL", "Forklift", "Skid Steer Loader", "Independent Contractor"]) |
+| [props.parameters.advanced_constraints.route4me_members_id] | Array.<number>
| | An array of the skilled driver IDs. |
+| [props.parameters.advanced_constraints.depot_address] | object
| | A depot address. |
+| props.parameters.advanced_constraints.depot_address.source_id | number
| | Source ID. |
+| props.parameters.advanced_constraints.depot_address.source_type | string
| | Source type (e.g. input_addresses). |
+| [props.parameters.advanced_constraints.location_sequence_pattern] | Array.<object>
| | The parameter is used in advanced constraints to set the stops you plan to visit each route. Note: empty string "" means any stops, for example ["", AddresssObject1, AddresssObject2, "", AddresssObject3] means any stops before AddresssObject1 and between AddresssObject2 and AddresssObject3. |
+| [props.parameters.advanced_constraints.location_sequence_pattern.alias] | string
| | Location alias |
+| [props.parameters.advanced_constraints.location_sequence_pattern.address] | string
| | Location address |
+| props.parameters.advanced_constraints.location_sequence_pattern.lat | number
| | Location latitude |
+| props.parameters.advanced_constraints.location_sequence_pattern.lng | number
| | Location longitude |
+| [props.parameters.advanced_constraints.location_sequence_pattern.time] | number
| | Location service time |
+| [props.parameters.advanced_constraints.group] | string
| | Group name of the advanced constraints. |
+| [props.depots] | Array.<object>
| | A valid array of Address objects of Depots. |
+| props.addresses | Array.<object>
| | A valid array of Address objects. Here are some required and useful properties of the Address object, for full list of properties look at docs. |
+| props.addresses.lat | number
| | Latitude. |
+| props.addresses.lng | number
| | Longitude. |
+| [props.addresses.alias] | string
| | Address Alias. |
+| [props.addresses.address] | string
| | The route Address Line 1. |
+| [props.addresses.is_depot] | boolean
| false
| This address is a depot. |
+| [props.addresses.group] | string
| | Address group. |
+| [props.addresses.time] | number
| | Service time (seconds). |
+| [props.addresses.time_window_start] | number
| | Time Window Start in seconds, relative to the route start date (midnight), UTC time zone. It is relative to start date because start time changes would shift time windows. |
+| [props.addresses.time_window_end] | number
| | Time Window End in seconds, relative to the route start date (midnight), UTC time zone. It is relative to start date because start time changes would shift time windows. |
+| [props.addresses.tags] | Array.<string>
| | Array of address tags. |
+| [props.addresses.contact_id] | number
| | Address book contact id (0 means not connected to the address book). |
+| [props.optimized_callback_url] | string
| | A URL that gets called when the optimization is solved, or if there is an error. The callback is called with a POST request. The POST data sent is: timestamp (Seconds) - Server timestamp of request sent; optimization_problem_id (Hash String) - ID of the optimization; state (Small Int) - The state can be one of the values: 4 = OPTIMIZATION_STATE_OPTIMIZED, which means the optimization was successful; 5 = OPTIMIZATION_STATE_ERROR, which means there was an error solving the optimization. Query string (GET fields). |
+| [isRedirect] | boolean
| | If set, it will be redirected. Use false for no redirection or not send. |
+| callback | RequestCallback
| | The callback that handles the response. |
+
### optimizations.get(id, [callback])
diff --git a/code-examples/optimizations-advanced-constraints.js b/code-examples/optimizations-advanced-constraints.js
new file mode 100644
index 0000000..e5ad3cf
--- /dev/null
+++ b/code-examples/optimizations-advanced-constraints.js
@@ -0,0 +1,85 @@
+const Route4Me = require("route4me-node");
+const apiKey = "11111111111111111111111111111111";
+const route4me = new Route4Me(apiKey);
+
+/////////////////////////////////////////////////////////
+// Create an Optimization with advanced constraints
+// Driver's Time Shift
+//
+
+// General Route Parameters
+const parameters = {
+ algorithm_type: 9, // ADVANCED_CVRP_TW,
+ store_route: false,
+ rt: true,
+ parts: 3,
+ route_name: "Driver Shift Example",
+ route_time: 0,
+ optimize: "Distance",
+ distance_unit: "mi",
+ device_type: "web",
+ travel_mode: "Driving",
+ vehicle_capacity: 100,
+ vehicle_max_distance_mi: 10000,
+ route_max_duration: 86400,
+ advanced_constraints: [{
+ // Schedule 1
+ max_cargo_volume: 0.0,
+ max_capacity: 200,
+ members_count: 2,
+ // Time Window Start: 2:00 am EST = 25200
+ // Time Window End: 15:50 am EST = 75000
+ available_time_windows: [[25200, 75000]],
+ tags: ["TAG001", "TAG002"],
+ }, {
+ // Schedule 2
+ max_cargo_volume: 0.0,
+ max_capacity: 500,
+ members_count: 3,
+ // Time Window Start: 7:33 am EST = 45200
+ // Time Window End: 10:16 am EST = 55000
+ // Time Window Start: 12:13 am EST = 62000
+ // Time Window End: 18:36 am EST = 85000
+ available_time_windows: [[45200, 55000], [62000, 85000]],
+ tags: ["TAG003"],
+ }
+ ]
+};
+
+// Addresses
+const addresses = [{
+ address: "1407 MCCOY, Louisville, KY, 40215",
+ lat: 38.202496,
+ lng: -85.786514,
+ time: 300,
+ tags: ["TAG001", "TAG002"]
+ }, {
+ address: "730 CECIL AVENUE, Louisville, KY, 40211",
+ lat: 38.248684,
+ lng: -85.821121,
+ time: 300,
+ tags: ["TAG001", "TAG002"]
+ }, {
+ address: "4629 HILLSIDE DRIVE, Louisville, KY, 40216",
+ lat: 38.176067,
+ lng: -85.824638,
+ time: 300,
+ tags: ["TAG003"],
+ time_window_start: 41348,
+ time_window_end: 42261
+ }
+];
+
+// Depots
+const depots = [{
+ address: "1604 PARKRIDGE PKWY, Louisville, KY, 40214",
+ is_depot: true,
+ lat: 38.141598,
+ lng: -85.793846,
+ time: 300
+}];
+
+route4me.Optimizations.create2({ parameters, addresses, depots }, (err, data) => {
+ if(err) console.log(err);
+ console.log(data);
+});
diff --git a/examples/Optimizations/create-an-optimization-advanced-constraints.js b/examples/Optimizations/create-an-optimization-advanced-constraints.js
new file mode 100644
index 0000000..d9be50d
--- /dev/null
+++ b/examples/Optimizations/create-an-optimization-advanced-constraints.js
@@ -0,0 +1,94 @@
+"use strict"
+
+/////////////////////////////////////////////////////////
+// Driver's Time Shift
+//
+const path = require("path")
+const chai = require("chai")
+const debug = require("debug")("route4me-node:examples")
+
+require("../init-examples-suite")
+const helper = require("../../test/helper")
+
+helper.describeIntegration(helper.toSuiteName(__filename), function T() {
+ this.timeout(5000)
+ this.slow(3000)
+ it(path.basename(__filename), (done) => {
+ // const Route4Me = require("route4me-node")
+ const expect = chai.expect
+ const apiKey = "11111111111111111111111111111111"
+ const route4me = new Route4Me(apiKey)
+
+ const parameters = {
+ algorithm_type: 9, // ADVANCED_CVRP_TW,
+ store_route: false,
+ rt: true,
+ parts: 3,
+ route_name: "Driver Shift Example",
+ route_time: 0,
+ optimize: "Distance",
+ distance_unit: "mi",
+ device_type: "web",
+ travel_mode: "Driving",
+ vehicle_capacity: 100,
+ vehicle_max_distance_mi: 10000,
+ route_max_duration: 86400,
+ advanced_constraints: [{
+ max_cargo_volume: 0.0,
+ max_capacity: 200,
+ members_count: 2,
+ available_time_windows: [[25200, 75000]],
+ tags: ["TAG001", "TAG002"],
+ }, {
+ max_cargo_volume: 0.0,
+ max_capacity: 500,
+ members_count: 3,
+ available_time_windows: [[45200, 55000], [62000, 85000]],
+ tags: ["TAG003"],
+ }
+ ]
+ };
+
+ const addresses = [{
+ address: "1407 MCCOY, Louisville, KY, 40215",
+ lat: 38.202496,
+ lng: -85.786514,
+ time: 300,
+ tags: ["TAG001", "TAG002"]
+ }, {
+ address: "730 CECIL AVENUE, Louisville, KY, 40211",
+ lat: 38.248684,
+ lng: -85.821121,
+ time: 300,
+ tags: ["TAG001", "TAG002"]
+ }, {
+ address: "4629 HILLSIDE DRIVE, Louisville, KY, 40216",
+ lat: 38.176067,
+ lng: -85.824638,
+ time: 300,
+ tags: ["TAG003"],
+ time_window_start: 41348,
+ time_window_end: 42261
+ }
+ ];
+
+ const depots = [{
+ address: "1604 PARKRIDGE PKWY, Louisville, KY, 40214",
+ is_depot: true,
+ lat: 38.141598,
+ lng: -85.793846,
+ time: 300
+ }];
+
+ route4me.Optimizations.create2({ parameters, addresses, depots }, (err, optimization) => {
+ debug("error ", err)
+ debug("result ", optimization)
+
+ expect(err).is.null
+ expect(optimization).exist
+ console.log(optimization)
+ });
+ // TODO: remove `done` call from examples
+ done()
+ })
+})
diff --git a/package.json b/package.json
index ef98c3c..902310b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "route4me-node",
- "version": "1.0.14",
+ "version": "1.0.15",
"description": "Access Route4Me's logistics-as-a-service API using our Node.js SDK",
"main": "./dist/",
"browser": "./dist/browser/route4me.js",
diff --git a/src/resources/optimizations.js b/src/resources/optimizations.js
index 26c2091..0e01e1b 100644
--- a/src/resources/optimizations.js
+++ b/src/resources/optimizations.js
@@ -52,6 +52,169 @@ class Optimizations {
}, callback)
}
+ /* eslint-disable max-len */
+ /**
+ * Create a new optimization with Advanced constraints
+ *
+ * @see {@link https://route4me.io/docs/#create-an-optimization}
+ * @since 0.1.15
+ *
+ * @param {object} props - Optimization properties.
+ * Here are some required or useful properties, for full list of properties look at docs.
+ * @see {@link https://github.com/route4me/route4me-json-schemas/blob/master/Optimization_create.json}
+ *
+ * @param {object} props.parameters - Route Parameters.
+ * Here are some required and useful parameters, for full list of properties look at docs.
+ * @see {@link https://github.com/route4me/route4me-json-schemas/blob/master/RouteParameters.json}
+ *
+ * @param {number} props.parameters.algorithm_type - The optimization algorithm to be used.
+ * Possible values:
+ * 1 = TSP, 2 = VRP, 3 = CVRP_TW_SD, 4 = CVRP_TW_MD, 5 = TSP_TW, 6 = TSP_TW_CR, 7 = BBCVRP,
+ * 9 = ADVANCED_CVRP_TW,100 = ALG_NONE, 101 = ALG_LEGACY_DISTRIBUTED
+ *
+ * @param {string} props.parameters.device_type - The type of the device that is
+ * creating this route.
+ * Possible values: "web", "iphone", "ipad", "android_phone", "android_tablet".
+ *
+ * @param {string} props.parameters.distance_unit - The distance measurement unit for the route.
+ * Possible values: "mi", "km".
+ *
+ * @param {number} props.parameters.route_max_duration = 86400 - How many seconds a route can last at most.
+ * Default is 24 hours = 86400 seconds.
+ *
+ * @param {number} props.parameters.route_time = 25200 - Time when the route starts
+ * (relative to route_date) (Seconds). UTC timezone as well.
+ * Default is 07:00 UTC = 25200 seconds.
+ *
+ * @param {number} props.parameters.travel_mode - The mode of travel that the directions
+ * should be optimized for.
+ * Possible values: "Driving", "Walking", "Bicycling".
+ *
+ * @param {string} [props.parameters.optimize] - The driving directions will be generated
+ * biased for this selection. This has no impact on route sequencing.
+ * Possible values: "Distance", "Time", "timeWithTraffic".
+ *
+ * @param {number} [props.parameters.parts] - Legacy feature which permits a user to
+ * request an example number of optimized routes.
+ *
+ * @param {number} [props.parameters.route_date] - The route start date in UTC, unix timestamp
+ * seconds. Used to show users when the route will begin, also used for reporting and analytics.
+ *
+ * @param {string} [props.parameters.route_name] - The name of this route. this route name will
+ * be accessible in the search API, and also will be displayed on the mobile device of a user.
+ *
+ * @param {boolean} [props.parameters.rt] - The tour type of this route. rt is short
+ * for round trip, the optimization engine changes its behavior for round trip routes.
+ *
+ * @param {number} [props.parameters.vehicle_capacity] - How much cargo can the vehicle carry
+ * (units, e.g. cubic meters)
+ *
+ * @param {number} [props.parameters.vehicle_max_distance_mi] - Maximum distance for a single vehicle
+ * in this route (always in miles).
+ *
+ * @param {number} [props.parameters.advanced_constraints] - Advanced Constraints.
+ * @param {number} [props.parameters.advanced_constraints.max_cargo_weight] - Maximum cargo weight per route.
+ * @param {number} [props.parameters.advanced_constraints.max_cargo_volume] - Maximum cargo volume per route.
+ * @param {number} [props.parameters.advanced_constraints.max_capacity] - How much total cargo
+ * can be transported per route (units, e.g. cubic meters).
+ *
+ * @param {number} [props.parameters.advanced_constraints.members_count] - Legacy feature which
+ * permits a user to request an example number of optimized routes.
+ *
+ * @param {array[]} props.parameters.advanced_constraints.available_time_windows - An array of the
+ * available time windows, e.g. [[43200, 72000], [TimeStart, TimeEnd]]
+ * Time Window Start in seconds: 7:00 am EST = (7 + 5) * 3600 = 43200
+ * Time Window End in seconds: 15:00 am EST = (15 + 5) * 3600 = 72000
+ *
+ * @param {string[]} [props.parameters.advanced_constraints.tags] - The driver tags
+ * specified in a team member's custom data. (e.g. 'driver skills':
+ * ["Class A CDL", "Class B CDL", "Forklift", "Skid Steer Loader", "Independent Contractor"])
+ *
+ * @param {number[]} [props.parameters.advanced_constraints.route4me_members_id] - An array of the skilled driver IDs.
+ * @param {object} [props.parameters.advanced_constraints.depot_address] - A depot address.
+ * @param {number} props.parameters.advanced_constraints.depot_address.source_id - Source ID.
+ * @param {string} props.parameters.advanced_constraints.depot_address.source_type - Source type (e.g. input_addresses).
+ * @param {object[]} [props.parameters.advanced_constraints.location_sequence_pattern] - The parameter is used
+ * in advanced constraints to set the stops you plan to visit each route.
+ * Note: empty string "" means any stops,
+ * for example ["", AddresssObject1, AddresssObject2, "", AddresssObject3] means any stops
+ * before AddresssObject1 and between AddresssObject2 and AddresssObject3.
+ *
+ * @param {string} [props.parameters.advanced_constraints.location_sequence_pattern.alias] - Location alias
+ * @param {string} [props.parameters.advanced_constraints.location_sequence_pattern.address] - Location address
+ * @param {number} props.parameters.advanced_constraints.location_sequence_pattern.lat - Location latitude
+ * @param {number} props.parameters.advanced_constraints.location_sequence_pattern.lng - Location longitude
+ * @param {number} [props.parameters.advanced_constraints.location_sequence_pattern.time] - Location service time
+ * @param {string} [props.parameters.advanced_constraints.group] - Group name of the advanced constraints.
+ *
+ * @param {object[]} [props.depots] - A valid array of Address objects of Depots.
+ * @param {object[]} props.addresses - A valid array of Address objects.
+ * Here are some required and useful properties of the Address object,
+ * for full list of properties look at docs.
+ * @see {@link https://github.com/route4me/route4me-json-schemas/blob/master/Address.json}
+ *
+ * @param {number} props.addresses.lat - Latitude.
+ * @param {number} props.addresses.lng - Longitude.
+ * @param {string} [props.addresses.alias] - Address Alias.
+ * @param {string} [props.addresses.address] - The route Address Line 1.
+ * @param {boolean} [props.addresses.is_depot = false] - This address is a depot.
+ * @param {string} [props.addresses.group] - Address group.
+ * @param {number} [props.addresses.time] - Service time (seconds).
+ * @param {number} [props.addresses.time_window_start] - Time Window Start in seconds, relative to
+ * the route start date (midnight), UTC time zone. It is relative to start date because start time
+ * changes would shift time windows.
+ *
+ * @param {number} [props.addresses.time_window_end] - Time Window End in seconds, relative to the
+ * route start date (midnight), UTC time zone. It is relative to start date because start time
+ * changes would shift time windows.
+ *
+ * @param {string[]} [props.addresses.tags] - Array of address tags.
+ * @param {number} [props.addresses.contact_id] - Address book contact id (0 means not connected
+ * to the address book).
+ *
+ * @param {string} [props.optimized_callback_url] - A URL that gets called when the optimization is solved,
+ * or if there is an error. The callback is called with a POST request.
+ * The POST data sent is:
+ * timestamp (Seconds) - Server timestamp of request sent;
+ * optimization_problem_id (Hash String) - ID of the optimization;
+ * state (Small Int) - The state can be one of the values:
+ * 4 = OPTIMIZATION_STATE_OPTIMIZED, which means the optimization was successful;
+ * 5 = OPTIMIZATION_STATE_ERROR, which means there was an error solving the optimization.
+ * Query string (GET fields).
+ *
+ * @param {boolean} [isRedirect] - If set, it will be redirected. Use false for no redirection or not send.
+ *
+ * @param {RequestCallback} callback - The callback that handles the response.
+ * @see {@link https://github.com/route4me/route4me-json-schemas/blob/master/Optimization_response.json}
+ */
+ create2(props, isRedirect, callback) {
+ let isRdr = isRedirect || false
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof isRdr) {
+ cb = isRdr
+ isRdr = false
+ }
+
+ if (!isRdr) {
+ return this.r._makeRequest({
+ method: "POST",
+ path: "/api.v4/optimization_problem.php",
+ qs: { redirect: 0 },
+ body: props,
+ validationContext: "Optimizations.Response",
+ }, cb)
+ }
+
+ return this.r._makeRequest({
+ method: "POST",
+ path: "/api.v4/optimization_problem.php",
+ body: props,
+ validationContext: "Optimizations.Response",
+ }, cb)
+ }
+ /* eslint-enable max-len */
+
/**
* GET a single optimization by
* [optimization_problem_id]{@link Optimizations#get~id} parameter.
diff --git a/test/resources/optimizations.spec.js b/test/resources/optimizations.spec.js
index fc3b0e5..01e510b 100644
--- a/test/resources/optimizations.spec.js
+++ b/test/resources/optimizations.spec.js
@@ -228,6 +228,161 @@ describe(helper.toSuiteName(__filename), () => {
})
})
})
+
+ describe("create2 use with advanced constraints", () => {
+ const parameters = {
+ algorithm_type: 9,
+ rt: true,
+ advanced_constraints: [{
+ max_capacity: 200,
+ tags: ["TAG001", "TAG002"],
+ }, {
+ max_capacity: 500,
+ tags: ["TAG003"],
+ }
+ ]
+ };
+
+ const addresses = [{
+ lat: 38.202496,
+ lng: -85.786514,
+ tags: ["TAG001", "TAG002"]
+ }, {
+ lat: 38.176067,
+ lng: -85.824638,
+ tags: ["TAG003"]
+ }
+ ];
+
+ it("should call create2 without depots", (done) => {
+
+ resource.create2({ parameters, addresses }, (err, res) => {
+ expect(err).is.null
+ expect(res).is.not.null
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl() + "/api.v4/optimization_problem.php",
+ { redirect: '0' },
+ {
+ parameters: {
+ algorithm_type: 9,
+ rt: true,
+ advanced_constraints: [{
+ max_capacity: 200,
+ tags: ["TAG001", "TAG002"],
+ }, {
+ max_capacity: 500,
+ tags: ["TAG003"],
+ }
+ ]
+ },
+ addresses: [{
+ lat: 38.202496,
+ lng: -85.786514,
+ tags: ["TAG001", "TAG002"]
+ }, {
+ lat: 38.176067,
+ lng: -85.824638,
+ tags: ["TAG003"]
+ }
+ ]
+ }
+ )
+ })
+ done()
+ })
+
+ it("should call create2 without depots with redirect", (done) => {
+
+ resource.create2({ parameters, addresses }, true, (err, res) => {
+ expect(err).is.null
+ expect(res).is.not.null
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl() + "/api.v4/optimization_problem.php",
+ null,
+ {
+ parameters: {
+ algorithm_type: 9,
+ rt: true,
+ advanced_constraints: [{
+ max_capacity: 200,
+ tags: ["TAG001", "TAG002"],
+ }, {
+ max_capacity: 500,
+ tags: ["TAG003"],
+ }
+ ]
+ },
+ addresses: [{
+ lat: 38.202496,
+ lng: -85.786514,
+ tags: ["TAG001", "TAG002"]
+ }, {
+ lat: 38.176067,
+ lng: -85.824638,
+ tags: ["TAG003"]
+ }
+ ]
+ }
+ )
+ })
+ done()
+ })
+
+ it("should call create2 with depots", (done) => {
+
+ const depots = [{
+ address: "1604 PARKRIDGE PKWY, Louisville, KY, 40214",
+ is_depot: true,
+ lat: 38.141598,
+ lng: -85.793846,
+ time: 300
+ }];
+
+ resource.create2({ parameters, addresses, depots }, (err, res) => {
+ expect(err).is.null
+ expect(res).is.not.null
+ helper.expectRequest(req,
+ "POST",
+ route4meClient.baseUrl() + "/api.v4/optimization_problem.php",
+ { redirect: '0' },
+ {
+ parameters: {
+ algorithm_type: 9,
+ rt: true,
+ advanced_constraints: [{
+ max_capacity: 200,
+ tags: ["TAG001", "TAG002"],
+ }, {
+ max_capacity: 500,
+ tags: ["TAG003"],
+ }
+ ]
+ },
+ addresses: [{
+ lat: 38.202496,
+ lng: -85.786514,
+ tags: ["TAG001", "TAG002"]
+ }, {
+ lat: 38.176067,
+ lng: -85.824638,
+ tags: ["TAG003"]
+ }
+ ],
+ depots: [{
+ address: "1604 PARKRIDGE PKWY, Louisville, KY, 40214",
+ is_depot: true,
+ lat: 38.141598,
+ lng: -85.793846,
+ time: 300
+ }]
+ }
+ )
+ })
+ done()
+ })
+ })
})
})
From 40bbc0acaa1937d28b743355d3bbf5a64557658f Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Tue, 18 Oct 2022 00:06:43 +0500
Subject: [PATCH 5/9] Added description, tests and examples for Advanced
constraints.
---
book/en/code/Optimizations.md | 6 +++---
.../optimizations-advanced-constraints.js | 2 +-
.../create-an-optimization-advanced-constraints.js | 2 +-
src/resources/optimizations.js | 2 +-
test/resources/optimizations.spec.js | 14 +++++++-------
5 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/book/en/code/Optimizations.md b/book/en/code/Optimizations.md
index 5c41276..a0ca075 100644
--- a/book/en/code/Optimizations.md
+++ b/book/en/code/Optimizations.md
@@ -12,7 +12,7 @@ Optimizations facility
* [Optimizations](#Optimizations) ℗
* [new Optimizations(requestManager)](#new_Optimizations_new)
* [.create(optimization, isRedirect, [callback])](#Optimizations+create)
- * [.create2(props, [isRedirect], callback)](#Optimizations+create2)
+ * [.createWithAdvancedConstraints(props, [isRedirect], callback)](#Optimizations+createWithAdvancedConstraints)
* [.get(id, [callback])](#Optimizations+get)
* [.list(states, options, [callback])](#Optimizations+list)
* [.update(id, data, [reoptimize], [callback])](#Optimizations+update)
@@ -46,9 +46,9 @@ Create a new optimization
| isRedirect | boolean
| |
| [callback] | module:route4me-node~RequestCallback.<jsonschema:Optimizations.Response>
| |
-
+
-### optimizations.create2(props, [isRedirect], callback)
+### optimizations.createWithAdvancedConstraints(props, [isRedirect], callback)
Create a new optimization with Advanced constraints
diff --git a/code-examples/optimizations-advanced-constraints.js b/code-examples/optimizations-advanced-constraints.js
index e5ad3cf..e888094 100644
--- a/code-examples/optimizations-advanced-constraints.js
+++ b/code-examples/optimizations-advanced-constraints.js
@@ -79,7 +79,7 @@ const depots = [{
time: 300
}];
-route4me.Optimizations.create2({ parameters, addresses, depots }, (err, data) => {
+route4me.Optimizations.createWithAdvancedConstraints({ parameters, addresses, depots }, (err, data) => {
if(err) console.log(err);
console.log(data);
});
diff --git a/examples/Optimizations/create-an-optimization-advanced-constraints.js b/examples/Optimizations/create-an-optimization-advanced-constraints.js
index d9be50d..ce450cc 100644
--- a/examples/Optimizations/create-an-optimization-advanced-constraints.js
+++ b/examples/Optimizations/create-an-optimization-advanced-constraints.js
@@ -80,7 +80,7 @@ helper.describeIntegration(helper.toSuiteName(__filename), function T() {
time: 300
}];
- route4me.Optimizations.create2({ parameters, addresses, depots }, (err, optimization) => {
+ route4me.Optimizations.createWithAdvancedConstraints({ parameters, addresses, depots }, (err, optimization) => {
debug("error ", err)
debug("result ", optimization)
diff --git a/src/resources/optimizations.js b/src/resources/optimizations.js
index 0e01e1b..6739898 100644
--- a/src/resources/optimizations.js
+++ b/src/resources/optimizations.js
@@ -187,7 +187,7 @@ class Optimizations {
* @param {RequestCallback} callback - The callback that handles the response.
* @see {@link https://github.com/route4me/route4me-json-schemas/blob/master/Optimization_response.json}
*/
- create2(props, isRedirect, callback) {
+ createWithAdvancedConstraints(props, isRedirect, callback) {
let isRdr = isRedirect || false
let cb = callback
diff --git a/test/resources/optimizations.spec.js b/test/resources/optimizations.spec.js
index 01e510b..023d6a1 100644
--- a/test/resources/optimizations.spec.js
+++ b/test/resources/optimizations.spec.js
@@ -229,7 +229,7 @@ describe(helper.toSuiteName(__filename), () => {
})
})
- describe("create2 use with advanced constraints", () => {
+ describe("createWithAdvancedConstraints", () => {
const parameters = {
algorithm_type: 9,
rt: true,
@@ -254,9 +254,9 @@ describe(helper.toSuiteName(__filename), () => {
}
];
- it("should call create2 without depots", (done) => {
+ it("should call createWithAdvancedConstraints without depots", (done) => {
- resource.create2({ parameters, addresses }, (err, res) => {
+ resource.createWithAdvancedConstraints({ parameters, addresses }, (err, res) => {
expect(err).is.null
expect(res).is.not.null
helper.expectRequest(req,
@@ -292,9 +292,9 @@ describe(helper.toSuiteName(__filename), () => {
done()
})
- it("should call create2 without depots with redirect", (done) => {
+ it("should call createWithAdvancedConstraints without depots with redirect", (done) => {
- resource.create2({ parameters, addresses }, true, (err, res) => {
+ resource.createWithAdvancedConstraints({ parameters, addresses }, true, (err, res) => {
expect(err).is.null
expect(res).is.not.null
helper.expectRequest(req,
@@ -330,7 +330,7 @@ describe(helper.toSuiteName(__filename), () => {
done()
})
- it("should call create2 with depots", (done) => {
+ it("should call createWithAdvancedConstraints with depots", (done) => {
const depots = [{
address: "1604 PARKRIDGE PKWY, Louisville, KY, 40214",
@@ -340,7 +340,7 @@ describe(helper.toSuiteName(__filename), () => {
time: 300
}];
- resource.create2({ parameters, addresses, depots }, (err, res) => {
+ resource.createWithAdvancedConstraints({ parameters, addresses, depots }, (err, res) => {
expect(err).is.null
expect(res).is.not.null
helper.expectRequest(req,
From 2a252787b65a1b173f97ac780b7fbe7fd42695e4 Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Sat, 12 Nov 2022 21:01:25 +0500
Subject: [PATCH 6/9] Added functions to AutomaticTerritories: createJob,
getJobStatus and getJobResult.
---
book/en/SUMMARY.md | 1 +
book/en/code/AutomaticTerritories.md | 73 ++++++++++
book/en/code/Route4Me.md | 45 +++---
gulpfile.js | 5 +
package.json | 2 +-
src/resources/automatic-territories.js | 98 +++++++++++++
src/route4me.js | 78 ++++++-----
test/resources/address-book-v5.spec.js | 6 +-
test/resources/automatic-territories.spec.js | 140 +++++++++++++++++++
9 files changed, 392 insertions(+), 56 deletions(-)
create mode 100644 book/en/code/AutomaticTerritories.md
create mode 100644 src/resources/automatic-territories.js
create mode 100644 test/resources/automatic-territories.spec.js
diff --git a/book/en/SUMMARY.md b/book/en/SUMMARY.md
index e1fead1..3f4ba2e 100644
--- a/book/en/SUMMARY.md
+++ b/book/en/SUMMARY.md
@@ -39,6 +39,7 @@
### V5
* [AddressBookV5](code/AddressBookV5.md)
+ * [AutomaticTerritories](code/AutomaticTerritories.md)
* [TeamManagement](code/TeamManagement.md)
* [VehiclesV5](code/VehiclesV5.md)
diff --git a/book/en/code/AutomaticTerritories.md b/book/en/code/AutomaticTerritories.md
new file mode 100644
index 0000000..b9c7aab
--- /dev/null
+++ b/book/en/code/AutomaticTerritories.md
@@ -0,0 +1,73 @@
+
+
+## AutomaticTerritories ℗
+
+AutomaticTerritories facility
+
+**Category**: AutomaticTerritories
+**Access**: private
+**See**: [https://route4me.io/docs/#address-book](https://route4me.io/docs/#address-book)
+**Since**: 1.0.16
+
+* [AutomaticTerritories](#AutomaticTerritories) ℗
+ * [new AutomaticTerritories(requestManager)](#new_AutomaticTerritories_new)
+ * [.createJob(addresses, [mode], [params], callback)](#AutomaticTerritories+createJob)
+ * [.getJobStatus(jobId, callback)](#AutomaticTerritories+getJobStatus)
+ * [.getJobResult(jobId, callback)](#AutomaticTerritories+getJobResult)
+
+
+
+### new AutomaticTerritories(requestManager)
+
+Constructor
+
+**Returns**: [AutomaticTerritories
](#AutomaticTerritories) - - AutomaticTerritories facility
+
+| Param | Type | Description |
+| --- | --- | --- |
+| requestManager | RequestManager
| Request Manager |
+
+
+
+### automaticTerritories.createJob(addresses, [mode], [params], callback)
+
+Create job.
+
+**Since**: 1.0.16
+
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| addresses | Array.<Object>
| | An array of the address objects. |
+| addresses.id | String
| | Address ID. |
+| addresses.lat | Number
| | Address latitude. |
+| addresses.lng | Number
| | Address longitude. |
+| [mode] | Number
| 0
| |
+| [params] | Array.<String>
| []
| An array of parameters. |
+| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.AddressBookSearchResult>
| | |
+
+
+
+### automaticTerritories.getJobStatus(jobId, callback)
+
+Check the asynchronous job status by specifying the 'job_id' path parameter.
+
+**Since**: 1.0.16
+
+| Param | Type | Description |
+| --- | --- | --- |
+| jobId | String
| Job ID to check status. |
+| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.AddressBookSearchResult>
| |
+
+
+
+### automaticTerritories.getJobResult(jobId, callback)
+
+Get the asynchronous job result by specifying the 'job_id' path parameter.
+
+**Since**: 1.0.16
+
+| Param | Type | Description |
+| --- | --- | --- |
+| jobId | String
| Job ID to get result. |
+| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.AddressBookSearchResult>
| |
+
diff --git a/book/en/code/Route4Me.md b/book/en/code/Route4Me.md
index d076fde..d509337 100644
--- a/book/en/code/Route4Me.md
+++ b/book/en/code/Route4Me.md
@@ -84,24 +84,25 @@ With `route4me` instance you should get responses from API easy-peasy.
Main members of the instanse of `Route4Me` class:
-* [ActivityFeed ](ActivityFeed)
-* [Addresses ](Addresses)
-* [AddressBook ](AddressBook)
-* [AddressBookV5 ](AddressBookV5)
-* [AddressBarcodes ](AddressBarcodes)
-* [AvoidanceZones ](AvoidanceZones)
-* [Geocoding ](Geocoding)
-* [Members ](Members)
-* [Notes ](Notes)
-* [Optimizations ](Optimizations)
-* [Orders ](Orders)
-* [OrderCustomFields](OrderCustomFields)
-* [Routes ](Routes)
-* [TeamManagement ](TeamManagement)
-* [Territories ](Territories)
-* [Tracking ](Tracking)
-* [Vehicles ](Vehicles)
-* [VehiclesV5 ](VehiclesV5)
+* [ActivityFeed ](ActivityFeed)
+* [Addresses ](Addresses)
+* [AddressBook ](AddressBook)
+* [AddressBookV5 ](AddressBookV5)
+* [AddressBarcodes ](AddressBarcodes)
+* [AutomaticTerritories](AutomaticTerritories)
+* [AvoidanceZones ](AvoidanceZones)
+* [Geocoding ](Geocoding)
+* [Members ](Members)
+* [Notes ](Notes)
+* [Optimizations ](Optimizations)
+* [Orders ](Orders)
+* [OrderCustomFields ](OrderCustomFields)
+* [Routes ](Routes)
+* [TeamManagement ](TeamManagement)
+* [Territories ](Territories)
+* [Tracking ](Tracking)
+* [Vehicles ](Vehicles)
+* [VehiclesV5 ](VehiclesV5)
Each member corresponds to an bunch of methods, described in API-documentation,
but the most methods in this SDK have unified names:
@@ -131,6 +132,7 @@ For most use cases it is necessary:
* [.AddressBookV5](#Route4Me+AddressBookV5) : AddressBookV5
* [.AddressBarcodes](#Route4Me+AddressBarcodes) : AddressBarcodes
* [.Addresses](#Route4Me+Addresses) : Addresses
+ * [.AutomaticTerritories](#Route4Me+AutomaticTerritories) : AutomaticTerritories
* [.AvoidanceZones](#Route4Me+AvoidanceZones) : AvoidanceZones
* [.Geocoding](#Route4Me+Geocoding) : Geocoding
* [.Notes](#Route4Me+Notes) : Notes
@@ -201,6 +203,13 @@ Create new API client
**Addresses** related API calls
**Since**: 0.1.8
+
+
+### route4Me.AutomaticTerritories : AutomaticTerritories
+
+**AutomaticTerritories** related API calls
+
+**Since**: 0.1.16
### route4Me.AvoidanceZones : AvoidanceZones
diff --git a/gulpfile.js b/gulpfile.js
index f8c1b6f..a9bfff6 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -144,6 +144,11 @@ gulp.task("doc:install", gulp.series(function DI() { // eslint-disable-line pref
gulp.task("watch:doc",gulp.series( ["doc:pre"], function D() { // eslint-disable-line prefer-arrow-callback
const cmd = gitbook.commands.filter(c => c.name.match(/^serve\s/i))[0]
+ console.log("****************");
+ console.log(__dirname);
+ console.log(cmd);
+ console.log("****************");
+
return cmd.exec([
path.join(__dirname),
path.join(__dirname, "tmp", "gitbook")
diff --git a/package.json b/package.json
index 902310b..b707b96 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "route4me-node",
- "version": "1.0.15",
+ "version": "1.0.16",
"description": "Access Route4Me's logistics-as-a-service API using our Node.js SDK",
"main": "./dist/",
"browser": "./dist/browser/route4me.js",
diff --git a/src/resources/automatic-territories.js b/src/resources/automatic-territories.js
new file mode 100644
index 0000000..ae75b0f
--- /dev/null
+++ b/src/resources/automatic-territories.js
@@ -0,0 +1,98 @@
+"use strict"
+
+/**
+ * AutomaticTerritories facility
+ *
+ * @category AutomaticTerritories
+ * @since 1.0.16
+ */
+class AutomaticTerritories {
+ /**
+ * Constructor
+ *
+ * @see {@link https://route4me.io/docs/#address-book}
+ * @private
+ *
+ * @param {RequestManager} requestManager - Request Manager
+ * @return {AutomaticTerritories} - AutomaticTerritories facility
+ */
+ constructor(requestManager) {
+ this.r = requestManager
+ }
+
+ /**
+ * Create job.
+ *
+ * @since 1.0.16
+ *
+ * @param {Object[]} addresses - An array of the address objects.
+ * @param {String} addresses.id - Address ID.
+ * @param {Number} addresses.lat - Address latitude.
+ * @param {Number} addresses.lng - Address longitude.
+ * @param {Number} [mode = 0]
+ * @param {String[]} [params = []] - An array of parameters.
+ * @param {module:route4me-node~RequestCallback} callback
+ */
+ createJob(addresses, mode, params, callback) {
+ let md = mode || 0
+ let prm = params || []
+ let cb = callback
+
+ if (undefined === cb && "function" === typeof prm) {
+ cb = prm
+ prm = []
+ }
+
+ if (undefined === cb && "function" === typeof md) {
+ cb = md
+ md = 0
+ }
+ return this.r._makeRequest5({
+ method: "POST",
+ url: "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories",
+ body: {
+ addresses,
+ mode: md,
+ params: prm
+ },
+ validationContext: "AutomaticTerritories.JobID",
+ }, cb)
+ }
+
+ /**
+ * Check the asynchronous job status by specifying the 'job_id' path parameter.
+ *
+ * @since 1.0.16
+ *
+ * @param {String} jobId - Job ID to check status.
+ * @param {module:route4me-node~RequestCallback} callback
+ */
+ getJobStatus(jobId, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ url: `https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories/job-tracker/status/${jobId}`,
+ validationContext: "AutomaticTerritories.ResponseStatus",
+ }, callback)
+ }
+
+ /**
+ * Get the asynchronous job result by specifying the 'job_id' path parameter.
+ *
+ * @since 1.0.16
+ *
+ * @param {String} jobId - Job ID to get result.
+ * @param {module:route4me-node~RequestCallback} callback
+ */
+ getJobResult(jobId, callback) {
+ return this.r._makeRequest5({
+ method: "GET",
+ url: `https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories/job-tracker/result/${jobId}`,
+ validationContext: "AutomaticTerritories.ResponseJob",
+ }, callback)
+ }
+}
+
+module.exports = AutomaticTerritories
diff --git a/src/route4me.js b/src/route4me.js
index 9652ea6..230c462 100644
--- a/src/route4me.js
+++ b/src/route4me.js
@@ -3,23 +3,24 @@
const debug = require("debug")("route4me")
const platform = require("platform")
-const ActivityFeed = require("./resources/activity-feed")
-const Addresses = require("./resources/addresses")
-const AddressBook = require("./resources/address-book")
-const AddressBookV5 = require("./resources/address-book-v5")
-const AddressBarcodes = require("./resources/address-barcodes")
-const AvoidanceZones = require("./resources/avoidance-zones")
-const Geocoding = require("./resources/geocoding")
-const Members = require("./resources/members")
-const Notes = require("./resources/notes")
-const Optimizations = require("./resources/optimizations")
-const Orders = require("./resources/orders")
-const Routes = require("./resources/routes")
-const TeamManagement = require("./resources/team-management")
-const Territories = require("./resources/territories")
-const Tracking = require("./resources/tracking")
-const Vehicles = require("./resources/vehicles")
-const VehiclesV5 = require("./resources/vehicles-v5")
+const ActivityFeed = require("./resources/activity-feed")
+const Addresses = require("./resources/addresses")
+const AddressBook = require("./resources/address-book")
+const AddressBookV5 = require("./resources/address-book-v5")
+const AddressBarcodes = require("./resources/address-barcodes")
+const AutomaticTerritories = require("./resources/automatic-territories")
+const AvoidanceZones = require("./resources/avoidance-zones")
+const Geocoding = require("./resources/geocoding")
+const Members = require("./resources/members")
+const Notes = require("./resources/notes")
+const Optimizations = require("./resources/optimizations")
+const Orders = require("./resources/orders")
+const Routes = require("./resources/routes")
+const TeamManagement = require("./resources/team-management")
+const Territories = require("./resources/territories")
+const Tracking = require("./resources/tracking")
+const Vehicles = require("./resources/vehicles")
+const VehiclesV5 = require("./resources/vehicles-v5")
const packageJson = require("./../package.json") // eslint-disable-line import/no-dynamic-require
const utils = require("./utils")
@@ -36,24 +37,25 @@ const RequestManager = require("./request-manager")
*
* Main members of the instanse of `Route4Me` class:
*
- * * [ActivityFeed ]{@link ActivityFeed}
- * * [Addresses ]{@link Addresses}
- * * [AddressBook ]{@link AddressBook}
- * * [AddressBookV5 ]{@link AddressBookV5}
- * * [AddressBarcodes ]{@link AddressBarcodes}
- * * [AvoidanceZones ]{@link AvoidanceZones}
- * * [Geocoding ]{@link Geocoding}
- * * [Members ]{@link Members}
- * * [Notes ]{@link Notes}
- * * [Optimizations ]{@link Optimizations}
- * * [Orders ]{@link Orders}
- * * [OrderCustomFields]{@link OrderCustomFields}
- * * [Routes ]{@link Routes}
- * * [TeamManagement ]{@link TeamManagement}
- * * [Territories ]{@link Territories}
- * * [Tracking ]{@link Tracking}
- * * [Vehicles ]{@link Vehicles}
- * * [VehiclesV5 ]{@link VehiclesV5}
+ * * [ActivityFeed ]{@link ActivityFeed}
+ * * [Addresses ]{@link Addresses}
+ * * [AddressBook ]{@link AddressBook}
+ * * [AddressBookV5 ]{@link AddressBookV5}
+ * * [AddressBarcodes ]{@link AddressBarcodes}
+ * * [AutomaticTerritories]{@link AutomaticTerritories}
+ * * [AvoidanceZones ]{@link AvoidanceZones}
+ * * [Geocoding ]{@link Geocoding}
+ * * [Members ]{@link Members}
+ * * [Notes ]{@link Notes}
+ * * [Optimizations ]{@link Optimizations}
+ * * [Orders ]{@link Orders}
+ * * [OrderCustomFields ]{@link OrderCustomFields}
+ * * [Routes ]{@link Routes}
+ * * [TeamManagement ]{@link TeamManagement}
+ * * [Territories ]{@link Territories}
+ * * [Tracking ]{@link Tracking}
+ * * [Vehicles ]{@link Vehicles}
+ * * [VehiclesV5 ]{@link VehiclesV5}
*
* Each member corresponds to an bunch of methods, described in API-documentation,
* but the most methods in this SDK have unified names:
@@ -154,6 +156,12 @@ class Route4Me {
* @since 0.1.8
*/
this.Addresses = new Addresses(req)
+ /**
+ * **AutomaticTerritories** related API calls
+ * @type {AutomaticTerritories}
+ * @since 0.1.16
+ */
+ this.AutomaticTerritories = new AutomaticTerritories(req)
/**
* **AvoidanceZones** related API calls
* @type {AvoidanceZones}
diff --git a/test/resources/address-book-v5.spec.js b/test/resources/address-book-v5.spec.js
index 47a086a..c7616eb 100644
--- a/test/resources/address-book-v5.spec.js
+++ b/test/resources/address-book-v5.spec.js
@@ -633,7 +633,8 @@ describe(helper.toSuiteName(__filename), () => {
"GET",
route4meClient.baseUrl5() + "/api/v5.0/address-book/addresses/job-tracker/status/85352155",
null,
- null )
+ null
+ )
done()
})
})
@@ -650,7 +651,8 @@ describe(helper.toSuiteName(__filename), () => {
"GET",
route4meClient.baseUrl5() + "/api/v5.0/address-book/addresses/job-tracker/result/85352155",
null,
- null )
+ null
+ )
done()
})
})
diff --git a/test/resources/automatic-territories.spec.js b/test/resources/automatic-territories.spec.js
new file mode 100644
index 0000000..58303c9
--- /dev/null
+++ b/test/resources/automatic-territories.spec.js
@@ -0,0 +1,140 @@
+"use strict"
+
+const request = require("superagent")
+const saMock = require("superagent-mocker")(request)
+
+const helper = require("./../helper")
+
+const route4me = require("./../../dist")
+
+const testApiKey = "11111111111111111111111111111111"
+
+
+describe(helper.toSuiteName(__filename), () => {
+ describe("SDK methods", () => {
+ const route4meClient = new route4me.Route4Me(testApiKey)
+ const resource = route4meClient.AutomaticTerritories
+ let req
+
+ beforeEach(() => {
+ req = null
+ saMock.get("*", (r) => { req = r; req.method = "GET"; return {} })
+ saMock.post("*", (r) => { req = r; req.method = "POST"; return {} })
+ saMock.del("*", (r) => { req = r; req.method = "DELETE"; return {} })
+ saMock.put("*", (r) => { req = r; req.method = "PUT"; return {} })
+ })
+
+ afterEach(() => {
+ saMock.clearRoutes()
+ })
+
+ describe("createJob", () => {
+ const addresses = [
+ { "id": "1", "lat": 39.86374, "lng": -86.199121 },
+ { "id": "6", "lat": 39.762472, "lng": -84.117212 }
+ ];
+
+ const mode = 0;
+ const params = []
+
+ it("should call route4me", (done) => {
+ resource.createJob(addresses, mode, params, (err, res) => {
+ expect(err).is.null
+ expect(res).is.not.null
+ helper.expectRequest(req,
+ "POST",
+ "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories",
+ {},
+ {
+ addresses: [
+ { "id": "1", "lat": 39.86374, "lng": -86.199121 },
+ { "id": "6", "lat": 39.762472, "lng": -84.117212 }
+ ],
+ mode: 0,
+ params: []
+ }
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without params", (done) => {
+ resource.createJob(addresses, mode, (err, res) => {
+ expect(err).is.null
+ expect(res).is.not.null
+ helper.expectRequest(req,
+ "POST",
+ "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories",
+ {},
+ {
+ addresses: [
+ { "id": "1", "lat": 39.86374, "lng": -86.199121 },
+ { "id": "6", "lat": 39.762472, "lng": -84.117212 }
+ ],
+ mode: 0,
+ params: []
+ }
+ )
+ done()
+ })
+ })
+
+ it("should call route4me without params and mode", (done) => {
+ resource.createJob(addresses, (err, res) => {
+ expect(err).is.null
+ expect(res).is.not.null
+ helper.expectRequest(req,
+ "POST",
+ "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories",
+ {},
+ {
+ addresses: [
+ { "id": "1", "lat": 39.86374, "lng": -86.199121 },
+ { "id": "6", "lat": 39.762472, "lng": -84.117212 }
+ ],
+ mode: 0,
+ params: []
+ }
+ )
+ done()
+ })
+ })
+ })
+
+ describe("getJobStatus", () => {
+ it("should call route4me", (done) => {
+ const jobId = "85352155";
+
+ resource.getJobStatus(jobId, (err, res) => {
+ expect(err).is.null
+ expect(res).is.not.null
+ helper.expectRequest(req,
+ "GET",
+ "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories/job-tracker/status/85352155",
+ null,
+ null
+ )
+ done()
+ })
+ })
+ })
+
+ describe("getJobResult", () => {
+ it("should call route4me", (done) => {
+ const jobId = "85352155";
+
+ resource.getJobResult(jobId, (err, res) => {
+ expect(err).is.null
+ expect(res).is.not.null
+ helper.expectRequest(req,
+ "GET",
+ "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories/job-tracker/result/85352155",
+ null,
+ null
+ )
+ done()
+ })
+ })
+ })
+ })
+})
From d49d134f4f4db4f2960dd284c8d876f157f142b1 Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Sun, 13 Nov 2022 11:59:41 +0500
Subject: [PATCH 7/9] Minor fixes.
---
book/en/code/AutomaticTerritories.md | 7 +++----
gulpfile.js | 6 ------
src/resources/automatic-territories.js | 7 +++----
3 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/book/en/code/AutomaticTerritories.md b/book/en/code/AutomaticTerritories.md
index b9c7aab..84f1bc1 100644
--- a/book/en/code/AutomaticTerritories.md
+++ b/book/en/code/AutomaticTerritories.md
@@ -6,7 +6,6 @@ AutomaticTerritories facility
**Category**: AutomaticTerritories
**Access**: private
-**See**: [https://route4me.io/docs/#address-book](https://route4me.io/docs/#address-book)
**Since**: 1.0.16
* [AutomaticTerritories](#AutomaticTerritories) ℗
@@ -43,7 +42,7 @@ Create job.
| addresses.lng | Number
| | Address longitude. |
| [mode] | Number
| 0
| |
| [params] | Array.<String>
| []
| An array of parameters. |
-| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.AddressBookSearchResult>
| | |
+| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.JobID>
| | |
@@ -56,7 +55,7 @@ Check the asynchronous job status by specifying the 'job_id' path parameter.
| Param | Type | Description |
| --- | --- | --- |
| jobId | String
| Job ID to check status. |
-| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.AddressBookSearchResult>
| |
+| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.ResponseStatus>
| |
@@ -69,5 +68,5 @@ Get the asynchronous job result by specifying the 'job_id' path parameter.
| Param | Type | Description |
| --- | --- | --- |
| jobId | String
| Job ID to get result. |
-| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.AddressBookSearchResult>
| |
+| callback | module:route4me-node~RequestCallback.<jsonschema:AutomaticTerritories.ResponseJob>
| |
diff --git a/gulpfile.js b/gulpfile.js
index a9bfff6..16044d1 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -143,12 +143,6 @@ gulp.task("doc:install", gulp.series(function DI() { // eslint-disable-line pref
gulp.task("watch:doc",gulp.series( ["doc:pre"], function D() { // eslint-disable-line prefer-arrow-callback
const cmd = gitbook.commands.filter(c => c.name.match(/^serve\s/i))[0]
-
- console.log("****************");
- console.log(__dirname);
- console.log(cmd);
- console.log("****************");
-
return cmd.exec([
path.join(__dirname),
path.join(__dirname, "tmp", "gitbook")
diff --git a/src/resources/automatic-territories.js b/src/resources/automatic-territories.js
index ae75b0f..7faea01 100644
--- a/src/resources/automatic-territories.js
+++ b/src/resources/automatic-territories.js
@@ -10,7 +10,6 @@ class AutomaticTerritories {
/**
* Constructor
*
- * @see {@link https://route4me.io/docs/#address-book}
* @private
*
* @param {RequestManager} requestManager - Request Manager
@@ -32,7 +31,7 @@ class AutomaticTerritories {
* @param {Number} [mode = 0]
* @param {String[]} [params = []] - An array of parameters.
* @param {module:route4me-node~RequestCallback} callback
+ * AutomaticTerritories.JobID>} callback
*/
createJob(addresses, mode, params, callback) {
let md = mode || 0
@@ -67,7 +66,7 @@ class AutomaticTerritories {
*
* @param {String} jobId - Job ID to check status.
* @param {module:route4me-node~RequestCallback} callback
+ * AutomaticTerritories.ResponseStatus>} callback
*/
getJobStatus(jobId, callback) {
return this.r._makeRequest5({
@@ -84,7 +83,7 @@ class AutomaticTerritories {
*
* @param {String} jobId - Job ID to get result.
* @param {module:route4me-node~RequestCallback} callback
+ * AutomaticTerritories.ResponseJob>} callback
*/
getJobResult(jobId, callback) {
return this.r._makeRequest5({
From 8c9e4208d2b550adb15082993bf366129ea6d78c Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Mon, 14 Nov 2022 23:29:26 +0300
Subject: [PATCH 8/9] Changed stage urls in class AutomaticTerritories to base5
path and added examples for functions of AutomaticTerritories
---
examples/AutomaticTerritories/create-job.js | 40 +++++++++++++++++++
examples/AutomaticTerritories/getJobResult.js | 30 ++++++++++++++
examples/AutomaticTerritories/getJobStatus.js | 30 ++++++++++++++
src/resources/automatic-territories.js | 6 +--
test/resources/automatic-territories.spec.js | 10 ++---
5 files changed, 108 insertions(+), 8 deletions(-)
create mode 100644 examples/AutomaticTerritories/create-job.js
create mode 100644 examples/AutomaticTerritories/getJobResult.js
create mode 100644 examples/AutomaticTerritories/getJobStatus.js
diff --git a/examples/AutomaticTerritories/create-job.js b/examples/AutomaticTerritories/create-job.js
new file mode 100644
index 0000000..caf64a4
--- /dev/null
+++ b/examples/AutomaticTerritories/create-job.js
@@ -0,0 +1,40 @@
+"use strict"
+
+const path = require("path")
+const chai = require("chai")
+const debug = require("debug")("route4me-node:examples")
+require("../init-examples-suite")
+const helper = require("../../test/helper")
+
+helper.describeIntegration(helper.toSuiteName(__filename), function T() {
+ this.timeout(5000)
+ this.slow(3000)
+ it(path.basename(__filename), (done) => {
+ // const Route4Me = require("route4me-node")
+ const expect = chai.expect
+ const apiKey = "11111111111111111111111111111111"
+ const route4me = new Route4Me(apiKey)
+
+ const addresses = [
+ { "id": "1", "lat": 39.86374, "lng": -86.199121 },
+ { "id": "2", "lat": 39.792024, "lng": -86.221094 },
+ { "id": "3", "lat": 39.728683, "lng": -86.210107 },
+ { "id": "4", "lat": 39.787803, "lng": -84.254541 },
+ { "id": "5", "lat": 39.728683, "lng": -84.254541 },
+ { "id": "6", "lat": 39.762472, "lng": -84.117212 }
+ ];
+
+ const mode = 0;
+ const params = []
+
+ route4me.AutomaticTerritories.createJob(addresses, mode, params, (err, res) => {
+ debug("error ", err)
+ debug("result ", res)
+ expect(err).is.null
+ expect(res).exist
+ console.log(res)
+ })
+ // TODO: remove `done` call from examples
+ done()
+ })
+})
diff --git a/examples/AutomaticTerritories/getJobResult.js b/examples/AutomaticTerritories/getJobResult.js
new file mode 100644
index 0000000..a34fda0
--- /dev/null
+++ b/examples/AutomaticTerritories/getJobResult.js
@@ -0,0 +1,30 @@
+"use strict"
+
+const path = require("path")
+const chai = require("chai")
+const debug = require("debug")("route4me-node:examples")
+require("../init-examples-suite")
+const helper = require("../../test/helper")
+
+helper.describeIntegration(helper.toSuiteName(__filename), function T() {
+ this.timeout(5000)
+ this.slow(3000)
+ it(path.basename(__filename), (done) => {
+ // const Route4Me = require("route4me-node")
+ const expect = chai.expect
+ const apiKey = "11111111111111111111111111111111"
+ const route4me = new Route4Me(apiKey)
+
+ const job_id = "468E232D9644D93501EF6261BD715622";
+
+ route4me.AutomaticTerritories.getJobResult(job_id, (err, res) => {
+ debug("error ", err)
+ debug("result ", res)
+ expect(err).is.null
+ expect(res).exist
+ console.log(res)
+ })
+ // TODO: remove `done` call from examples
+ done()
+ })
+})
diff --git a/examples/AutomaticTerritories/getJobStatus.js b/examples/AutomaticTerritories/getJobStatus.js
new file mode 100644
index 0000000..f26f867
--- /dev/null
+++ b/examples/AutomaticTerritories/getJobStatus.js
@@ -0,0 +1,30 @@
+"use strict"
+
+const path = require("path")
+const chai = require("chai")
+const debug = require("debug")("route4me-node:examples")
+require("../init-examples-suite")
+const helper = require("../../test/helper")
+
+helper.describeIntegration(helper.toSuiteName(__filename), function T() {
+ this.timeout(5000)
+ this.slow(3000)
+ it(path.basename(__filename), (done) => {
+ // const Route4Me = require("route4me-node")
+ const expect = chai.expect
+ const apiKey = "11111111111111111111111111111111"
+ const route4me = new Route4Me(apiKey)
+
+ const job_id = "468E232D9644D93501EF6261BD715622";
+
+ route4me.AutomaticTerritories.getJobStatus(job_id, (err, res) => {
+ debug("error ", err)
+ debug("result ", res)
+ expect(err).is.null
+ expect(res).exist
+ console.log(res)
+ })
+ // TODO: remove `done` call from examples
+ done()
+ })
+})
diff --git a/src/resources/automatic-territories.js b/src/resources/automatic-territories.js
index 7faea01..5c1966c 100644
--- a/src/resources/automatic-territories.js
+++ b/src/resources/automatic-territories.js
@@ -49,7 +49,7 @@ class AutomaticTerritories {
}
return this.r._makeRequest5({
method: "POST",
- url: "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories",
+ path: "/api/v5.0/automatic-territories",
body: {
addresses,
mode: md,
@@ -71,7 +71,7 @@ class AutomaticTerritories {
getJobStatus(jobId, callback) {
return this.r._makeRequest5({
method: "GET",
- url: `https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories/job-tracker/status/${jobId}`,
+ path: `/api/v5.0/automatic-territories/job-tracker/status/${jobId}`,
validationContext: "AutomaticTerritories.ResponseStatus",
}, callback)
}
@@ -88,7 +88,7 @@ class AutomaticTerritories {
getJobResult(jobId, callback) {
return this.r._makeRequest5({
method: "GET",
- url: `https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories/job-tracker/result/${jobId}`,
+ path: `/api/v5.0/automatic-territories/job-tracker/result/${jobId}`,
validationContext: "AutomaticTerritories.ResponseJob",
}, callback)
}
diff --git a/test/resources/automatic-territories.spec.js b/test/resources/automatic-territories.spec.js
index 58303c9..d2b22ab 100644
--- a/test/resources/automatic-territories.spec.js
+++ b/test/resources/automatic-territories.spec.js
@@ -43,7 +43,7 @@ describe(helper.toSuiteName(__filename), () => {
expect(res).is.not.null
helper.expectRequest(req,
"POST",
- "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories",
+ route4meClient.baseUrl5() + "/api/v5.0/automatic-territories",
{},
{
addresses: [
@@ -64,7 +64,7 @@ describe(helper.toSuiteName(__filename), () => {
expect(res).is.not.null
helper.expectRequest(req,
"POST",
- "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories",
+ route4meClient.baseUrl5() + "/api/v5.0/automatic-territories",
{},
{
addresses: [
@@ -85,7 +85,7 @@ describe(helper.toSuiteName(__filename), () => {
expect(res).is.not.null
helper.expectRequest(req,
"POST",
- "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories",
+ route4meClient.baseUrl5() + "/api/v5.0/automatic-territories",
{},
{
addresses: [
@@ -110,7 +110,7 @@ describe(helper.toSuiteName(__filename), () => {
expect(res).is.not.null
helper.expectRequest(req,
"GET",
- "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories/job-tracker/status/85352155",
+ route4meClient.baseUrl5() + "/api/v5.0/automatic-territories/job-tracker/status/85352155",
null,
null
)
@@ -128,7 +128,7 @@ describe(helper.toSuiteName(__filename), () => {
expect(res).is.not.null
helper.expectRequest(req,
"GET",
- "https://wh-staging-yx2ian2bajaskas.route4me.com/modules/api/v5.0/automatic-territories/job-tracker/result/85352155",
+ route4meClient.baseUrl5() + "/api/v5.0/automatic-territories/job-tracker/result/85352155",
null,
null
)
From d4307755e439613f3ec141ecaa2beaa649bbc902 Mon Sep 17 00:00:00 2001
From: 15 <15@mail.ru>
Date: Tue, 15 Nov 2022 20:26:50 +0300
Subject: [PATCH 9/9] Added full flow example for AutomaticTerritories.
---
examples/AutomaticTerritories/full-flow.js | 59 ++++++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100644 examples/AutomaticTerritories/full-flow.js
diff --git a/examples/AutomaticTerritories/full-flow.js b/examples/AutomaticTerritories/full-flow.js
new file mode 100644
index 0000000..c221230
--- /dev/null
+++ b/examples/AutomaticTerritories/full-flow.js
@@ -0,0 +1,59 @@
+"use strict"
+
+const path = require("path")
+const chai = require("chai")
+const debug = require("debug")("route4me-node:examples")
+require("../init-examples-suite")
+const helper = require("../../test/helper")
+
+helper.describeIntegration(helper.toSuiteName(__filename), function T() {
+ this.timeout(5000)
+ this.slow(3000)
+ it(path.basename(__filename), (done) => {
+ // const Route4Me = require("route4me-node")
+ const expect = chai.expect
+ const apiKey = "11111111111111111111111111111111"
+ const route4me = new Route4Me(apiKey)
+
+ const addresses = [
+ { "id": "1", "lat": 39.86374, "lng": -86.199121 },
+ { "id": "2", "lat": 39.792024, "lng": -86.221094 },
+ { "id": "3", "lat": 39.728683, "lng": -86.210107 },
+ { "id": "4", "lat": 39.787803, "lng": -84.254541 },
+ { "id": "5", "lat": 39.728683, "lng": -84.254541 },
+ { "id": "6", "lat": 39.762472, "lng": -84.117212 }
+ ];
+
+ const mode = 0;
+ const params = []
+
+ route4me.AutomaticTerritories.createJob(addresses, mode, params, (err, res) => {
+ debug("error ", err)
+ debug("result ", res)
+ expect(err).is.null
+ expect(res).exist
+ console.log(res)
+
+ const jobID = data.job_id
+ const hInterval = setInterval(() => {
+ route4me.AutomaticTerritories.getJobStatus(jobID, (err, data) => {
+ if(err) {
+ console.log(err)
+ return
+ }
+ console.log(data)
+
+ if(data.status === "processed") {
+ clearInterval(hInterval)
+ route4me.AutomaticTerritories.getJobResult(jobID, (err, data) => {
+ if(err) console.log(err)
+ console.log(data)
+ })
+ }
+ })
+ }, 10000)
+ })
+ // TODO: remove `done` call from examples
+ done()
+ })
+})