Skip to content

Commit 60dedc4

Browse files
committed
Upgrade soap dependency, and improve APIs
1 parent 57ac435 commit 60dedc4

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

example/index.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ const BrokerBin = require("../lib");
55
(async () => {
66

77
// Initialize the BrokerBin
8-
const bbClient = new BrokerBin({
9-
username: process.env.BROKERBIN_USERNAME
10-
, password: process.env.BROKERBIN_PASSWORD
11-
, soap_key: process.env.BROKERBIN_SOAP_KEY
12-
, soap_uri: process.env.BROKERBIN_SOAP_URI
13-
, public_key: process.env.BROKERBIN_PUBLIC_KEY
14-
})
15-
16-
// Authenticate
17-
await bbClient.authenticate()
8+
const bbClient = new BrokerBin()
189

1910
// Run a search
2011
const results = await bbClient.search("F238F", {

lib/index.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ class BrokerBin {
1414
* @function
1515
* @param {Object} auth An object containing the following data:
1616
*
17-
* - `username` (String): The BrokerBin username.
18-
* - `password` (String): The BrokerBin password.
19-
* - `soap_key` (String): The BrokerBin soap key.
20-
* - `soap_uri` (String): The BrokerBin soap uri.
21-
* - `public_key` (String): The BrokerBin public key.
17+
* - `username` (String): The BrokerBin username (or ENV variable: `BROKERBIN_USERNAME`)
18+
* - `password` (String): The BrokerBin password (or ENV variable: `BROKERBIN_PASSWORD`)
19+
* - `soap_key` (String): The BrokerBin soap key (or ENV variable: `BROKERBIN_SOAP_KEY`)
20+
* - `soap_uri` (String): The BrokerBin soap uri (or ENV variable: `BROKERBIN_SOAP_URI`)
21+
* - `public_key` (String): The BrokerBin public key (or ENV variable: `BROKERBIN_PUBLIC_KEY`)
2222
*
2323
* @return {Number} Return description.
2424
*/
25-
constructor (auth) {
25+
constructor (auth = {}) {
26+
27+
auth.username = auth.username || process.env.BROKERBIN_USERNAME
28+
auth.password = auth.password || process.env.BROKERBIN_PASSWORD
29+
auth.soap_key = auth.soap_key || process.env.BROKERBIN_SOAP_KEY
30+
auth.soap_uri = auth.soap_uri || process.env.BROKERBIN_SOAP_URI
31+
auth.public_key = auth.public_key || process.env.BROKERBIN_PUBLIC_KEY
2632

2733
const {
2834
username
@@ -84,6 +90,9 @@ class BrokerBin {
8490
* @return {Promise} Resolves with the results.
8591
*/
8692
async search (reqPart, reqOptions) {
93+
if (!this.soapUid) {
94+
await this.authenticate()
95+
}
8796
return new Promise((resolve, reject) => {
8897
reqOptions.uid = this.soapUid
8998
this.soapClient.Search({
@@ -96,7 +105,7 @@ class BrokerBin {
96105
try {
97106
res = phpunserialize(res.resParam.$value)
98107
} catch (e) {
99-
// TODO This fails silently
108+
// TODO This fails quite silently
100109
console.error(e)
101110
res = {}
102111
res.resultset = [{

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@
4242
"dependencies": {
4343
"mcrypt": "^0.1.17",
4444
"phpunserialize": "^1.0.1",
45-
"soap": "^0.36.0"
45+
"soap": "^0.43.0"
4646
}
47-
}
47+
}

0 commit comments

Comments
 (0)