-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from route4me/v1.0.5
Added functions "get" and "save" to Address Bar-codes.
- Loading branch information
Showing
7 changed files
with
308 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"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 routeId = "893E6C33F0494572DEB2FAE34B2D3E0B" | ||
const routeDestinationId = 705601646 | ||
const limit = 10; | ||
|
||
route4me.AddressBarcodes.get(routeId, routeDestinationId, limit, (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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"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 data = { | ||
barcodes: [{ | ||
barcode: "some barcode", | ||
lat: 1, | ||
lng: 2, | ||
timestamp_date: 3, | ||
timestamp_utc: 4, | ||
scanned_at: "2022-03-17 00:01:02", | ||
scan_type: "QR-code" | ||
}, { | ||
barcode: "ye some barcode", | ||
lat: 5, | ||
lng: 6, | ||
timestamp_date: 7, | ||
timestamp_utc: 8, | ||
scanned_at: "2022-03-18 01:02:03", | ||
scan_type: "QR-code" | ||
}], | ||
route_destination_id: 1, | ||
route_id: "C50594BD37618FA8B28EE6A86FEFD9D1" | ||
}; | ||
|
||
route4me.AddressBarcodes.save(data, (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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
"use strict" | ||
|
||
/** | ||
* AddressBarcodes facility | ||
* | ||
* @category AddressBarcodes | ||
*/ | ||
class AddressBarcodes { | ||
/** | ||
* Constructor | ||
* | ||
* @see {@link https://route4me.io/docs/#address-barcode} | ||
* @since 0.1.8 | ||
* @private | ||
* | ||
* @param {RequestManager} requestManager - Request Manager | ||
* @return {AddressBarcodes} - AddressBarcodes facility | ||
*/ | ||
constructor(requestManager) { | ||
this.r = requestManager | ||
} | ||
|
||
/** | ||
* Save a AddressBarcodes. | ||
* | ||
* @see {@link https://route4me.io/docs/#save-a-barcode} | ||
* @since 1.0.5 | ||
* | ||
* @param {object} data - Valid AddressBarcodes data. | ||
* @param {string} data.route_id - route ID. | ||
* @param {number} data.route_destination_id - route destination ID. | ||
* @param {array} data.barcodes - array of barcode objects. | ||
* @param {string} data.barcodes.barcode - barcode data. | ||
* @param {number} data.barcodes.lat - latitude. | ||
* @param {number} data.barcodes.lng - longitude. | ||
* @param {number} data.barcodes.timestamp_date - local date. | ||
* @param {number} data.barcodes.timestamp_utc - UTC date. | ||
* @param {string} data.barcodes.scanned_at - scan date as string "Y-M-D H:M:S". | ||
* @param {string} data.barcodes.scan_type - barcode scan type. | ||
* | ||
* @param {module:route4me-node~RequestCallback<jsonschema: | ||
* AddressBarcodes.AddressBarcodes>} [callback] | ||
*/ | ||
save(data, callback) { | ||
return this.r._makeRequest5({ | ||
method: "POST", | ||
path: "/api/v5.0/address-barcodes", | ||
body: data, | ||
validationContext: "Barcodes.save" // utils.CustomInternalPostProcessing.fromJsonWithStatus, | ||
}, callback) | ||
} | ||
|
||
/** | ||
* Get address barcodes by a specified route ID. | ||
* | ||
* @see {@link https://route4me.io/docs/#get-address-barcodes} | ||
* @since 1.0.5 | ||
* | ||
* @param {string} routeId - Route ID | ||
* @param {number} routeDestinationId - Route destination ID | ||
* @param {number} limit - Number of barcodes returning by request | ||
* @param {string} cursor - Cursor ID, on first call must be null | ||
* | ||
* @param {module:route4me-node~RequestCallback<jsonschema: | ||
* AddressBarcodes.AddressBookSearchResult>} [callback] | ||
*/ | ||
get(routeId, routeDestinationId, limit, cursor, callback) { | ||
const qs = { | ||
"route_id": routeId, | ||
"route_destination_id": routeDestinationId, | ||
"limit": limit | ||
} | ||
|
||
let cb = callback | ||
let cr = cursor | ||
|
||
if (cb === undefined && "function" === typeof cr) { | ||
cb = cr | ||
cr = null | ||
} | ||
|
||
if (null !== cr && "" !== cr) qs["cursor"] = cr | ||
|
||
return this.r._makeRequest5({ | ||
method: "GET", | ||
path: "/api/v5.0/address-barcodes", | ||
qs, | ||
validationContext: "AddressBarcodes.AddressBarcodesGetResult", | ||
}, cb) | ||
} | ||
} | ||
|
||
module.exports = AddressBarcodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
"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.AddressBarcodes | ||
let req | ||
|
||
beforeEach(() => { | ||
req = null | ||
saMock.get("*", (r) => { req = r; req.method = "GET"; return {} }) | ||
saMock.post("*", (r) => { req = r; req.method = "POST"; return {} }) | ||
}) | ||
|
||
afterEach(() => { | ||
saMock.clearRoutes() | ||
}) | ||
|
||
describe("get", () => { | ||
const routeId = "C50594BD37618FA8B28EE6A86FEFD9D1" | ||
const routeDestinationId = 2 | ||
const limit = 10 | ||
const cursor = "a" | ||
|
||
it("should call route4me", (done) => { | ||
|
||
resource.get(routeId, routeDestinationId, limit, cursor, (err, res) => { | ||
expect(err).is.null | ||
expect(res).is.not.null | ||
helper.expectRequest(req, | ||
"GET", "https://wh.route4me.com/modules/api/v5.0/address-barcodes", | ||
{ | ||
"route_id": "C50594BD37618FA8B28EE6A86FEFD9D1", | ||
"route_destination_id": "2", | ||
"limit": "10", | ||
"cursor": "a" | ||
}, | ||
null | ||
) | ||
done() | ||
}) | ||
}) | ||
|
||
it("should call route4me without cursor", (done) => { | ||
|
||
resource.get(routeId, routeDestinationId, limit, (err, res) => { | ||
expect(err).is.null | ||
expect(res).is.not.null | ||
helper.expectRequest(req, | ||
"GET", "https://wh.route4me.com/modules/api/v5.0/address-barcodes", | ||
{ | ||
"route_id": "C50594BD37618FA8B28EE6A86FEFD9D1", | ||
"route_destination_id": "2", | ||
"limit": "10" | ||
}, | ||
null | ||
) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe("save", () => { | ||
const data = { | ||
barcodes: [{ | ||
barcode: "some barcode", | ||
lat: 1, | ||
lng: 2, | ||
timestamp_date: 3, | ||
timestamp_utc: 4, | ||
scanned_at: "2022-03-17 00:01:02", | ||
scan_type: "QR-code" | ||
}, { | ||
barcode: "ye some barcode", | ||
lat: 5, | ||
lng: 6, | ||
timestamp_date: 7, | ||
timestamp_utc: 8, | ||
scanned_at: "2022-03-18 01:02:03", | ||
scan_type: "QR-code" | ||
}], | ||
route_destination_id: 1, | ||
route_id: "C50594BD37618FA8B28EE6A86FEFD9D1" | ||
}; | ||
|
||
it("should call route4me", (done) => { | ||
resource.save(data, (err, res) => { | ||
expect(err).is.null | ||
expect(res).is.not.null | ||
helper.expectRequest(req, | ||
"POST", "https://wh.route4me.com/modules/api/v5.0/address-barcodes", {}, | ||
data | ||
) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |