Skip to content

Commit cc027f1

Browse files
committed
* Added doHealthCheck endpoint
* Added submitSyncNumberTypeLookupRequest endpoint * Added submitAsyncNumberTypeLookupRequest endpoint * Added setNtAsyncCallbackUrl endpoint * Updated README * Updated Tests
1 parent d313ea1 commit cc027f1

File tree

4 files changed

+317
-10
lines changed

4 files changed

+317
-10
lines changed

src/README.md

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ npm install node-hlr-client
2121
#!/usr/bin/env node
2222

2323
var HlrLookupClient = require("node-hlr-client");
24+
var StringDecoder = require('string_decoder').StringDecoder;
25+
var decoder = new StringDecoder('utf8');
2426

2527
var client = new HlrLookupClient(
2628
'username',
@@ -39,9 +41,24 @@ var client = new HlrLookupClient(
3941
* Callback example: {"success":true,"results":[{"id":"e1fdf26531e4","msisdncountrycode":"DE","msisdn":"+491788735000","statuscode":"HLRSTATUS_DELIVERED","hlrerrorcodeid":null,"subscriberstatus":"SUBSCRIBERSTATUS_CONNECTED","imsi":"262031300000000","mccmnc":"26203","mcc":"262","mnc":"03","msin":"1300000000","servingmsc":"140445","servinghlr":null,"originalnetworkname":"E-Plus","originalcountryname":"Germany","originalcountrycode":"DE","originalcountryprefix":"+49","originalnetworkprefix":"178","roamingnetworkname":"Fixed Line Operators and Other Networks","roamingcountryname":"United States","roamingcountrycode":"US","roamingcountryprefix":"+1","roamingnetworkprefix":"404455","portednetworkname":null,"portedcountryname":null,"portedcountrycode":null,"portedcountryprefix":null,"portednetworkprefix":null,"isvalid":"Yes","isroaming":"Yes","isported":"No","usercharge":"0.0100","inserttime":"2014-12-28 06:22:00.328844+08","storage":"SDK-TEST-SYNC-API","route":"IP1"}]}
4042
*/
4143
client.submitSyncLookupRequest(function(response) {
42-
console.log(response);
44+
console.log(decoder.write(response));
4345
}, '+491788735000');
4446

47+
/**
48+
* Submits a synchronous number type lookup request. The HLR is queried in real time and results presented in the response body.
49+
*
50+
* @param callback - callback function(response)
51+
* @param number - An number in international format, e.g. +4989702626
52+
* @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
53+
* @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
54+
* @returns {*}
55+
*
56+
* Return example: {"success":true,"messages":[],"results":[{"id":"3cdb4e4d0ec1","number":"+4989702626","numbertype":"LANDLINE","state":"COMPLETED","isvalid":"Yes","ispossiblyported":"No","isvalidshortnumber":"No","isvanitynumber":"No","qualifiesforhlrlookup":"No","originalcarrier":null,"countrycode":"DE","mcc":null,"mnc":null,"mccmnc":null,"region":"Munich","timezones":["Europe\/Berlin"],"infotext":"This is a landline number.","usercharge":"0.0050","inserttime":"2015-12-04 13:02:48.415133+00","storage":"SYNC-API-NT-2015-12","route":"LC1"}]}
57+
*/
58+
client.submitSyncNumberTypeLookupRequest(function(response) {
59+
console.log(decoder.write(response));
60+
}, '+4989702626');
61+
4562
/**
4663
* Submits asynchronous HLR Lookups containing up to 1,000 MSISDNs per request. Results are sent back asynchronously to a callback URL on your server. Use \VmgLtd\HlrCallbackHandler to capture them.
4764
*
@@ -54,9 +71,24 @@ client.submitSyncLookupRequest(function(response) {
5471
* Callback example: {"success":true,"messages":[],"results":{"acceptedMsisdns":[{"id":"e489a092eba7","msisdn":"+491788735000"},{"id":"23ad48bf0c26","msisdn":"+491788735001"}],"rejectedMsisdns":[],"acceptedMsisdnCount":2,"rejectedMsisdnCount":0,"totalCount":2,"charge":0.02,"storage":"SDK-TEST-ASYNC-API","route":"IP4"}}
5572
*/
5673
client.submitAsyncLookupRequest(function(response) {
57-
console.log(response);
74+
console.log(decoder.write(response));
5875
}, ['+491788735000', '+491788735001']);
5976

77+
/**
78+
* Submits asynchronous number type lookups containing up to 1,000 numbers per request. Results are sent back asynchronously to a callback URL on your server.
79+
*
80+
* @param callback - callback function(response)
81+
* @param numbers - A list of numbers in international format, e.g. +4989702626,+491788735000
82+
* @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
83+
* @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
84+
* @returns {*}
85+
*
86+
* Return example: {"success":true,"messages":[],"results":{"acceptedNumbers":[{"id":"4f0820c76fb7","number":"+4989702626"},{"id":"9b9a7dab11a4","number":"+491788735000"}],"rejectedNumbers":[],"acceptedNumberCount":2,"rejectedNumberCount":0,"totalCount":2,"charge":0.01,"storage":"ASYNC-API-NT-2015-12","route":"LC1"}}
87+
*/
88+
client.submitAsyncNumberTypeLookupRequest(function(response) {
89+
console.log(decoder.write(response));
90+
}, ['+4989702626', '+491788735000']);
91+
6092
/**
6193
* Sets the callback URL for asynchronous lookups. Read more about the concept of asynchronous HLR lookups @ http://www.hlr-lookups.com/en/asynchronous-hlr-lookup-api
6294
*
@@ -67,7 +99,20 @@ client.submitAsyncLookupRequest(function(response) {
6799
* Callback example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
68100
*/
69101
client.setAsyncCallbackUrl(function(response) {
70-
console.log(response);
102+
console.log(decoder.write(response));
103+
}, 'http://user:pass@www.your-server.com/path/file');
104+
105+
/**
106+
* Sets the callback URL for asynchronous number type lookups.
107+
*
108+
* @param callback - callback function(response)
109+
* @param url - callback url on your server
110+
* @returns {*}
111+
*
112+
* Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
113+
*/
114+
client.setNtAsyncCallbackUrl(function(response) {
115+
console.log(decoder.write(response));
71116
}, 'http://user:pass@www.your-server.com/path/file');
72117

73118
/**
@@ -79,8 +124,21 @@ client.setAsyncCallbackUrl(function(response) {
79124
* Callback example: {"success":true,"messages":[],"results":{"balance":"5878.24600"}}
80125
*/
81126
client.getBalance(function(response) {
82-
console.log(response);
127+
console.log(decoder.write(response));
83128
});
129+
130+
/**
131+
* Performs a system health check and returns a sanity report.
132+
*
133+
* @param callback - callback function(response)
134+
* @returns {*}
135+
*
136+
* Return example: { "success":true, "results":{ "system":{ "state":"up" }, "routes":{ "states":{ "IP1":"up", "ST2":"up", "SV3":"up", "IP4":"up", "XT5":"up", "XT6":"up", "NT7":"up", "LC1":"up" } }, "account":{ "lookupsPermitted":true, "balance":"295.23000" } } }
137+
*/
138+
client.doHealthCheck(function(response) {
139+
console.log(decoder.write(response));
140+
});
141+
84142
```
85143

86144
**Usage Callback Handler**

src/lib/node-hlr-client.js

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,64 @@ HlrLookupClient.prototype.submitSyncLookupRequest = function submitSyncLookupReq
7676

7777
};
7878

79+
/**
80+
* Submits a synchronous number type lookup request. The HLR is queried in real time and results presented in the response body.
81+
*
82+
* @param callback - callback function(response)
83+
* @param number - An number in international format, e.g. +4989702626
84+
* @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
85+
* @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
86+
* @returns {*}
87+
*
88+
* Return example: {"success":true,"messages":[],"results":[{"id":"3cdb4e4d0ec1","number":"+4989702626","numbertype":"LANDLINE","state":"COMPLETED","isvalid":"Yes","ispossiblyported":"No","isvalidshortnumber":"No","isvanitynumber":"No","qualifiesforhlrlookup":"No","originalcarrier":null,"countrycode":"DE","mcc":null,"mnc":null,"mccmnc":null,"region":"Munich","timezones":["Europe\/Berlin"],"infotext":"This is a landline number.","usercharge":"0.0050","inserttime":"2015-12-04 13:02:48.415133+00","storage":"SYNC-API-NT-2015-12","route":"LC1"}]}
89+
*/
90+
HlrLookupClient.prototype.submitSyncNumberTypeLookupRequest = function submitSyncNumberTypeLookupRequest(callback, number, route, storage) {
91+
92+
if (!callback || typeof callback != 'function') {
93+
return console.error('Invalid Argument: callback');
94+
}
95+
96+
if (!this.validateUsage()) {
97+
return callback(generateErrorResponse('Missing client arguments (username or password)'));
98+
}
99+
100+
if (!number) {
101+
return callback(generateErrorResponse('Missing Argument: number'));
102+
}
103+
104+
if (typeof number != 'string') {
105+
return callback(generateErrorResponse('Invalid Argument: number must be of type string'));
106+
}
107+
108+
if (route) {
109+
if (typeof route != 'string') {
110+
return callback(generateErrorResponse('Invalid Argument: route must be of type string'));
111+
}
112+
}
113+
114+
if (storage) {
115+
if (typeof storage != 'string') {
116+
return callback(generateErrorResponse('Invalid Argument: storage must be of type string'));
117+
}
118+
}
119+
120+
client.post(this.url, {
121+
data: {
122+
action: "submitSyncNumberTypeLookupRequest",
123+
number: number,
124+
username: this.username,
125+
password: this.password,
126+
route: route ? route : null,
127+
storage: storage ? storage : null
128+
},
129+
headers: {
130+
"Content-Type": "application/json"
131+
}
132+
},
133+
callback);
134+
135+
};
136+
79137
/**
80138
* Submits asynchronous HLR Lookups containing up to 1,000 MSISDNs per request. Results are sent back asynchronously to a callback URL on your server. Use \VmgLtd\HlrCallbackHandler to capture them.
81139
*
@@ -134,6 +192,64 @@ HlrLookupClient.prototype.submitAsyncLookupRequest = function submitAsyncLookupR
134192

135193
};
136194

195+
/**
196+
* Submits asynchronous number type lookups containing up to 1,000 MSISDNs per request. Results are sent back asynchronously to a callback URL on your server.
197+
*
198+
* @param callback - callback function(response)
199+
* @param numbers - A list of numbers in international format, e.g. +4989702626,+491788735000
200+
* @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
201+
* @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
202+
* @returns {*}
203+
*
204+
* Return example: {"success":true,"messages":[],"results":{"acceptedNumbers":[{"id":"4f0820c76fb7","number":"+4989702626"},{"id":"9b9a7dab11a4","number":"+491788735000"}],"rejectedNumbers":[],"acceptedNumberCount":2,"rejectedNumberCount":0,"totalCount":2,"charge":0.01,"storage":"ASYNC-API-NT-2015-12","route":"LC1"}}
205+
*/
206+
HlrLookupClient.prototype.submitAsyncNumberTypeLookupRequest = function submitAsyncNumberTypeLookupRequest(callback, numbers, route, storage) {
207+
208+
if (!callback || typeof callback != 'function') {
209+
return console.error('Invalid Argument: callback');
210+
}
211+
212+
if (!this.validateUsage()) {
213+
return callback(generateErrorResponse('Missing client arguments (username or password)'));
214+
}
215+
216+
if (!numbers) {
217+
return callback(generateErrorResponse('Missing Argument: numbers'));
218+
}
219+
220+
if (typeof numbers != 'object') {
221+
return callback(generateErrorResponse('Invalid Argument: msisdns must be of type array'));
222+
}
223+
224+
if (route) {
225+
if (typeof route != 'string') {
226+
return callback(generateErrorResponse('Invalid Argument: route must be of type string'));
227+
}
228+
}
229+
230+
if (storage) {
231+
if (typeof storage != 'string') {
232+
return callback(generateErrorResponse('Invalid Argument: storage must be of type string'));
233+
}
234+
}
235+
236+
client.post(this.url, {
237+
data: {
238+
action: "submitAsyncNumberTypeLookupRequest",
239+
numbers: convertMsisdnsArrayToString(numbers),
240+
username: this.username,
241+
password: this.password,
242+
route: route ? route : null,
243+
storage: storage ? storage : null
244+
},
245+
headers: {
246+
"Content-Type": "application/json"
247+
}
248+
},
249+
callback);
250+
251+
};
252+
137253
/**
138254
* Sets the callback URL for asynchronous lookups. Read more about the concept of asynchronous HLR lookups @ http://www.hlr-lookups.com/en/asynchronous-hlr-lookup-api
139255
*
@@ -176,6 +292,48 @@ HlrLookupClient.prototype.setAsyncCallbackUrl = function setAsyncCallbackUrl(cal
176292

177293
};
178294

295+
/**
296+
* Sets the callback URL for asynchronous number type lookups.
297+
*
298+
* @param callback - callback function(response)
299+
* @param url - callback url on your server
300+
* @returns {*}
301+
*
302+
* Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
303+
*/
304+
HlrLookupClient.prototype.setNtAsyncCallbackUrl = function setNtAsyncCallbackUrl(callback, url) {
305+
306+
if (!callback || typeof callback != 'function') {
307+
return console.error('Invalid Argument: callback');
308+
}
309+
310+
if (!this.validateUsage()) {
311+
return callback(generateErrorResponse('Missing client arguments (username or password)'));
312+
}
313+
314+
if (!url) {
315+
return callback(generateErrorResponse('Missing Argument: url'));
316+
}
317+
318+
if (typeof url != 'string') {
319+
return callback(generateErrorResponse('Invalid Argument: url must be of type string'));
320+
}
321+
322+
client.post(this.url, {
323+
data: {
324+
action: "setNtAsyncCallbackUrl",
325+
url: url,
326+
username: this.username,
327+
password: this.password
328+
},
329+
headers: {
330+
"Content-Type": "application/json"
331+
}
332+
},
333+
callback);
334+
335+
};
336+
179337
/**
180338
* Returns the remaining balance (EUR) in your account.
181339
*
@@ -208,6 +366,38 @@ HlrLookupClient.prototype.getBalance = function getBalance(callback) {
208366

209367
};
210368

369+
/**
370+
* Performs a system health check and returns a sanity report.
371+
*
372+
* @param callback - callback function(response)
373+
* @returns {*}
374+
*
375+
* Return example: { "success":true, "results":{ "system":{ "state":"up" }, "routes":{ "states":{ "IP1":"up", "ST2":"up", "SV3":"up", "IP4":"up", "XT5":"up", "XT6":"up", "NT7":"up", "LC1":"up" } }, "account":{ "lookupsPermitted":true, "balance":"295.23000" } } }
376+
*/
377+
HlrLookupClient.prototype.doHealthCheck = function doHealthCheck(callback) {
378+
379+
if (!callback || typeof callback != 'function') {
380+
return console.error('Invalid Argument: callback');
381+
}
382+
383+
if (!this.validateUsage()) {
384+
return callback(generateErrorResponse('Missing client arguments (username or password)'));
385+
}
386+
387+
client.post(this.url, {
388+
data: {
389+
action: "doHealthCheck",
390+
username: this.username,
391+
password: this.password
392+
},
393+
headers: {
394+
"Content-Type": "application/json"
395+
}
396+
},
397+
callback);
398+
399+
};
400+
211401
/**
212402
* Parses an asynchronous HLR Lookup callback and returns a JSON string with the results.
213403
*

src/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Velocity Made Good Ltd.",
33
"name": "node-hlr-client",
44
"description": "Official HLR Lookup API Node JS SDK by www.hlr-lookups.com",
5-
"version": "0.0.10",
5+
"version": "0.0.11",
66
"repository": {
77
"url": ""
88
},
@@ -11,7 +11,9 @@
1111
"hlr",
1212
"hlr lookup",
1313
"hlr lookups",
14-
"hlr lookup api"
14+
"hlr lookup api",
15+
"landline lookups",
16+
"number type lookups"
1517
],
1618
"bin": {
1719
"uppercaseme": "./bin/node-hlr-client"

0 commit comments

Comments
 (0)