Skip to content

Commit 14493b1

Browse files
authored
Merge pull request #64 from route4me/v1.0.5
Added functions "get" and "save" to Address Bar-codes.
2 parents 1c7f185 + 8a071ad commit 14493b1

File tree

7 files changed

+308
-19
lines changed

7 files changed

+308
-19
lines changed

examples/Barcodes/get-barcodes.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict"
2+
3+
const path = require("path")
4+
const chai = require("chai")
5+
const debug = require("debug")("route4me-node:examples")
6+
require("../init-examples-suite")
7+
const helper = require("../../test/helper")
8+
9+
helper.describeIntegration(helper.toSuiteName(__filename), function T() {
10+
this.timeout(5000)
11+
this.slow(3000)
12+
it(path.basename(__filename), (done) => {
13+
// const Route4Me = require("route4me-node")
14+
const expect = chai.expect
15+
const apiKey = "11111111111111111111111111111111"
16+
const route4me = new Route4Me(apiKey)
17+
18+
const routeId = "893E6C33F0494572DEB2FAE34B2D3E0B"
19+
const routeDestinationId = 705601646
20+
const limit = 10;
21+
22+
route4me.AddressBarcodes.get(routeId, routeDestinationId, limit, (err, res) => {
23+
debug("error ", err)
24+
debug("result ", res)
25+
expect(err).is.null
26+
expect(res).exist
27+
console.log(res)
28+
})
29+
// TODO: remove `done` call from examples
30+
done()
31+
})
32+
})

examples/Barcodes/save-barcodes.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"use strict"
2+
3+
const path = require("path")
4+
const chai = require("chai")
5+
const debug = require("debug")("route4me-node:examples")
6+
require("../init-examples-suite")
7+
const helper = require("../../test/helper")
8+
9+
helper.describeIntegration(helper.toSuiteName(__filename), function T() {
10+
this.timeout(5000)
11+
this.slow(3000)
12+
it(path.basename(__filename), (done) => {
13+
// const Route4Me = require("route4me-node")
14+
const expect = chai.expect
15+
const apiKey = "11111111111111111111111111111111"
16+
const route4me = new Route4Me(apiKey)
17+
18+
const data = {
19+
barcodes: [{
20+
barcode: "some barcode",
21+
lat: 1,
22+
lng: 2,
23+
timestamp_date: 3,
24+
timestamp_utc: 4,
25+
scanned_at: "2022-03-17 00:01:02",
26+
scan_type: "QR-code"
27+
}, {
28+
barcode: "ye some barcode",
29+
lat: 5,
30+
lng: 6,
31+
timestamp_date: 7,
32+
timestamp_utc: 8,
33+
scanned_at: "2022-03-18 01:02:03",
34+
scan_type: "QR-code"
35+
}],
36+
route_destination_id: 1,
37+
route_id: "C50594BD37618FA8B28EE6A86FEFD9D1"
38+
};
39+
40+
route4me.AddressBarcodes.save(data, (err, res) => {
41+
debug("error ", err)
42+
debug("result ", res)
43+
expect(err).is.null
44+
expect(res).exist
45+
console.log(res)
46+
})
47+
// TODO: remove `done` call from examples
48+
done()
49+
})
50+
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "route4me-node",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Access Route4Me's logistics-as-a-service API using our Node.js SDK",
55
"main": "./dist/",
66
"browser": "./dist/browser/route4me.js",

src/resources/address-barcodes.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"use strict"
2+
3+
/**
4+
* AddressBarcodes facility
5+
*
6+
* @category AddressBarcodes
7+
*/
8+
class AddressBarcodes {
9+
/**
10+
* Constructor
11+
*
12+
* @see {@link https://route4me.io/docs/#address-barcode}
13+
* @since 0.1.8
14+
* @private
15+
*
16+
* @param {RequestManager} requestManager - Request Manager
17+
* @return {AddressBarcodes} - AddressBarcodes facility
18+
*/
19+
constructor(requestManager) {
20+
this.r = requestManager
21+
}
22+
23+
/**
24+
* Save a AddressBarcodes.
25+
*
26+
* @see {@link https://route4me.io/docs/#save-a-barcode}
27+
* @since 1.0.5
28+
*
29+
* @param {object} data - Valid AddressBarcodes data.
30+
* @param {string} data.route_id - route ID.
31+
* @param {number} data.route_destination_id - route destination ID.
32+
* @param {array} data.barcodes - array of barcode objects.
33+
* @param {string} data.barcodes.barcode - barcode data.
34+
* @param {number} data.barcodes.lat - latitude.
35+
* @param {number} data.barcodes.lng - longitude.
36+
* @param {number} data.barcodes.timestamp_date - local date.
37+
* @param {number} data.barcodes.timestamp_utc - UTC date.
38+
* @param {string} data.barcodes.scanned_at - scan date as string "Y-M-D H:M:S".
39+
* @param {string} data.barcodes.scan_type - barcode scan type.
40+
*
41+
* @param {module:route4me-node~RequestCallback<jsonschema:
42+
* AddressBarcodes.AddressBarcodes>} [callback]
43+
*/
44+
save(data, callback) {
45+
return this.r._makeRequest5({
46+
method: "POST",
47+
path: "/api/v5.0/address-barcodes",
48+
body: data,
49+
validationContext: "Barcodes.save" // utils.CustomInternalPostProcessing.fromJsonWithStatus,
50+
}, callback)
51+
}
52+
53+
/**
54+
* Get address barcodes by a specified route ID.
55+
*
56+
* @see {@link https://route4me.io/docs/#get-address-barcodes}
57+
* @since 1.0.5
58+
*
59+
* @param {string} routeId - Route ID
60+
* @param {number} routeDestinationId - Route destination ID
61+
* @param {number} limit - Number of barcodes returning by request
62+
* @param {string} cursor - Cursor ID, on first call must be null
63+
*
64+
* @param {module:route4me-node~RequestCallback<jsonschema:
65+
* AddressBarcodes.AddressBookSearchResult>} [callback]
66+
*/
67+
get(routeId, routeDestinationId, limit, cursor, callback) {
68+
const qs = {
69+
"route_id": routeId,
70+
"route_destination_id": routeDestinationId,
71+
"limit": limit
72+
}
73+
74+
let cb = callback
75+
let cr = cursor
76+
77+
if (cb === undefined && "function" === typeof cr) {
78+
cb = cr
79+
cr = null
80+
}
81+
82+
if (null !== cr && "" !== cr) qs["cursor"] = cr
83+
84+
return this.r._makeRequest5({
85+
method: "GET",
86+
path: "/api/v5.0/address-barcodes",
87+
qs,
88+
validationContext: "AddressBarcodes.AddressBarcodesGetResult",
89+
}, cb)
90+
}
91+
}
92+
93+
module.exports = AddressBarcodes

src/resources/orders.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,9 @@ class Orders {
440440
* @since 1.0.4
441441
*
442442
* @param {Object} [data] - Archive params
443-
* can have next fields
444-
* cursor: string - id of next page of orders, empty string on first call
445-
* per_page: integer - number of orders per page
446-
* filters: object
443+
* @param {string} [data.cursor] - id of next page of orders, empty string on first call
444+
* @param {number} [datap.er_page] - number of orders per page
445+
* @param {Object} [data.filters]
447446
*
448447
* @param {module:route4me-node~RequestCallback<jsonschema:Orders.Orders>} [callback]
449448
* [callback]

src/route4me.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const platform = require("platform")
66
const ActivityFeed = require("./resources/activity-feed")
77
const Addresses = require("./resources/addresses")
88
const AddressBook = require("./resources/address-book")
9+
const AddressBarcodes = require("./resources/address-barcodes")
910
const AvoidanceZones = require("./resources/avoidance-zones")
1011
const Geocoding = require("./resources/geocoding")
1112
const Members = require("./resources/members")
@@ -32,20 +33,21 @@ const RequestManager = require("./request-manager")
3233
*
3334
* Main members of the instanse of `Route4Me` class:
3435
*
35-
* * [ActivityFeed ]{@link ActivityFeed}
36-
* * [Addresses ]{@link Addresses}
37-
* * [AddressBook ]{@link AddressBook}
38-
* * [AvoidanceZones]{@link AvoidanceZones}
39-
* * [Geocoding ]{@link Geocoding}
40-
* * [Members ]{@link Members}
41-
* * [Notes ]{@link Notes}
42-
* * [Optimizations ]{@link Optimizations}
43-
* * [Orders ]{@link Orders}
44-
* * [OrderCustomFields ]{@link OrderCustomFields}
45-
* * [Routes ]{@link Routes}
46-
* * [Territories ]{@link Territories}
47-
* * [Tracking ]{@link Tracking}
48-
* * [Vehicles ]{@link Vehicles}
36+
* * [ActivityFeed ]{@link ActivityFeed}
37+
* * [Addresses ]{@link Addresses}
38+
* * [AddressBook ]{@link AddressBook}
39+
* * [AddressBarcodes ]{@link AddressBarcodes}
40+
* * [AvoidanceZones ]{@link AvoidanceZones}
41+
* * [Geocoding ]{@link Geocoding}
42+
* * [Members ]{@link Members}
43+
* * [Notes ]{@link Notes}
44+
* * [Optimizations ]{@link Optimizations}
45+
* * [Orders ]{@link Orders}
46+
* * [OrderCustomFields]{@link OrderCustomFields}
47+
* * [Routes ]{@link Routes}
48+
* * [Territories ]{@link Territories}
49+
* * [Tracking ]{@link Tracking}
50+
* * [Vehicles ]{@link Vehicles}
4951
*
5052
* Each member corresponds to an bunch of methods, described in API-documentation,
5153
* but the most methods in this SDK have unified names:
@@ -126,6 +128,12 @@ class Route4Me {
126128
* @since 0.1.8
127129
*/
128130
this.AddressBook = new AddressBook(req)
131+
/**
132+
* **AddressBarcodes** related API calls
133+
* @type {AddressBarcodes}
134+
* @since 1.0.5
135+
*/
136+
this.AddressBarcodes = new AddressBarcodes(req)
129137
/**
130138
* **Addresses** related API calls
131139
* @type {Addresses}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"use strict"
2+
3+
const request = require("superagent")
4+
const saMock = require("superagent-mocker")(request)
5+
6+
const helper = require("./../helper")
7+
const route4me = require("./../../dist")
8+
9+
const testApiKey = "11111111111111111111111111111111"
10+
11+
describe(helper.toSuiteName(__filename), () => {
12+
describe("SDK methods", () => {
13+
const route4meClient = new route4me.Route4Me(testApiKey)
14+
const resource = route4meClient.AddressBarcodes
15+
let req
16+
17+
beforeEach(() => {
18+
req = null
19+
saMock.get("*", (r) => { req = r; req.method = "GET"; return {} })
20+
saMock.post("*", (r) => { req = r; req.method = "POST"; return {} })
21+
})
22+
23+
afterEach(() => {
24+
saMock.clearRoutes()
25+
})
26+
27+
describe("get", () => {
28+
const routeId = "C50594BD37618FA8B28EE6A86FEFD9D1"
29+
const routeDestinationId = 2
30+
const limit = 10
31+
const cursor = "a"
32+
33+
it("should call route4me", (done) => {
34+
35+
resource.get(routeId, routeDestinationId, limit, cursor, (err, res) => {
36+
expect(err).is.null
37+
expect(res).is.not.null
38+
helper.expectRequest(req,
39+
"GET", "https://wh.route4me.com/modules/api/v5.0/address-barcodes",
40+
{
41+
"route_id": "C50594BD37618FA8B28EE6A86FEFD9D1",
42+
"route_destination_id": "2",
43+
"limit": "10",
44+
"cursor": "a"
45+
},
46+
null
47+
)
48+
done()
49+
})
50+
})
51+
52+
it("should call route4me without cursor", (done) => {
53+
54+
resource.get(routeId, routeDestinationId, limit, (err, res) => {
55+
expect(err).is.null
56+
expect(res).is.not.null
57+
helper.expectRequest(req,
58+
"GET", "https://wh.route4me.com/modules/api/v5.0/address-barcodes",
59+
{
60+
"route_id": "C50594BD37618FA8B28EE6A86FEFD9D1",
61+
"route_destination_id": "2",
62+
"limit": "10"
63+
},
64+
null
65+
)
66+
done()
67+
})
68+
})
69+
})
70+
71+
describe("save", () => {
72+
const data = {
73+
barcodes: [{
74+
barcode: "some barcode",
75+
lat: 1,
76+
lng: 2,
77+
timestamp_date: 3,
78+
timestamp_utc: 4,
79+
scanned_at: "2022-03-17 00:01:02",
80+
scan_type: "QR-code"
81+
}, {
82+
barcode: "ye some barcode",
83+
lat: 5,
84+
lng: 6,
85+
timestamp_date: 7,
86+
timestamp_utc: 8,
87+
scanned_at: "2022-03-18 01:02:03",
88+
scan_type: "QR-code"
89+
}],
90+
route_destination_id: 1,
91+
route_id: "C50594BD37618FA8B28EE6A86FEFD9D1"
92+
};
93+
94+
it("should call route4me", (done) => {
95+
resource.save(data, (err, res) => {
96+
expect(err).is.null
97+
expect(res).is.not.null
98+
helper.expectRequest(req,
99+
"POST", "https://wh.route4me.com/modules/api/v5.0/address-barcodes", {},
100+
data
101+
)
102+
done()
103+
})
104+
})
105+
})
106+
})
107+
})

0 commit comments

Comments
 (0)