Skip to content

Commit

Permalink
* Added doHealthCheck endpoint
Browse files Browse the repository at this point in the history
* Added submitSyncNumberTypeLookupRequest endpoint
* Added submitAsyncNumberTypeLookupRequest endpoint
* Added setNtAsyncCallbackUrl endpoint
* Updated README
* Updated Tests
  • Loading branch information
marcinx committed Dec 4, 2015
1 parent d313ea1 commit cc027f1
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 10 deletions.
66 changes: 62 additions & 4 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ npm install node-hlr-client
#!/usr/bin/env node

var HlrLookupClient = require("node-hlr-client");
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');

var client = new HlrLookupClient(
'username',
Expand All @@ -39,9 +41,24 @@ var client = new HlrLookupClient(
* 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"}]}
*/
client.submitSyncLookupRequest(function(response) {
console.log(response);
console.log(decoder.write(response));
}, '+491788735000');

/**
* Submits a synchronous number type lookup request. The HLR is queried in real time and results presented in the response body.
*
* @param callback - callback function(response)
* @param number - An number in international format, e.g. +4989702626
* @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
* @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
* @returns {*}
*
* 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"}]}
*/
client.submitSyncNumberTypeLookupRequest(function(response) {
console.log(decoder.write(response));
}, '+4989702626');

/**
* 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.
*
Expand All @@ -54,9 +71,24 @@ client.submitSyncLookupRequest(function(response) {
* 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"}}
*/
client.submitAsyncLookupRequest(function(response) {
console.log(response);
console.log(decoder.write(response));
}, ['+491788735000', '+491788735001']);

/**
* 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.
*
* @param callback - callback function(response)
* @param numbers - A list of numbers in international format, e.g. +4989702626,+491788735000
* @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
* @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
* @returns {*}
*
* 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"}}
*/
client.submitAsyncNumberTypeLookupRequest(function(response) {
console.log(decoder.write(response));
}, ['+4989702626', '+491788735000']);

/**
* 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
*
Expand All @@ -67,7 +99,20 @@ client.submitAsyncLookupRequest(function(response) {
* Callback example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:[email protected]\/path\/file"}}
*/
client.setAsyncCallbackUrl(function(response) {
console.log(response);
console.log(decoder.write(response));
}, 'http://user:[email protected]/path/file');

/**
* Sets the callback URL for asynchronous number type lookups.
*
* @param callback - callback function(response)
* @param url - callback url on your server
* @returns {*}
*
* Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:[email protected]\/path\/file"}}
*/
client.setNtAsyncCallbackUrl(function(response) {
console.log(decoder.write(response));
}, 'http://user:[email protected]/path/file');

/**
Expand All @@ -79,8 +124,21 @@ client.setAsyncCallbackUrl(function(response) {
* Callback example: {"success":true,"messages":[],"results":{"balance":"5878.24600"}}
*/
client.getBalance(function(response) {
console.log(response);
console.log(decoder.write(response));
});

/**
* Performs a system health check and returns a sanity report.
*
* @param callback - callback function(response)
* @returns {*}
*
* 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" } } }
*/
client.doHealthCheck(function(response) {
console.log(decoder.write(response));
});

```

**Usage Callback Handler**
Expand Down
190 changes: 190 additions & 0 deletions src/lib/node-hlr-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,64 @@ HlrLookupClient.prototype.submitSyncLookupRequest = function submitSyncLookupReq

};

/**
* Submits a synchronous number type lookup request. The HLR is queried in real time and results presented in the response body.
*
* @param callback - callback function(response)
* @param number - An number in international format, e.g. +4989702626
* @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
* @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
* @returns {*}
*
* 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"}]}
*/
HlrLookupClient.prototype.submitSyncNumberTypeLookupRequest = function submitSyncNumberTypeLookupRequest(callback, number, route, storage) {

if (!callback || typeof callback != 'function') {
return console.error('Invalid Argument: callback');
}

if (!this.validateUsage()) {
return callback(generateErrorResponse('Missing client arguments (username or password)'));
}

if (!number) {
return callback(generateErrorResponse('Missing Argument: number'));
}

if (typeof number != 'string') {
return callback(generateErrorResponse('Invalid Argument: number must be of type string'));
}

if (route) {
if (typeof route != 'string') {
return callback(generateErrorResponse('Invalid Argument: route must be of type string'));
}
}

if (storage) {
if (typeof storage != 'string') {
return callback(generateErrorResponse('Invalid Argument: storage must be of type string'));
}
}

client.post(this.url, {
data: {
action: "submitSyncNumberTypeLookupRequest",
number: number,
username: this.username,
password: this.password,
route: route ? route : null,
storage: storage ? storage : null
},
headers: {
"Content-Type": "application/json"
}
},
callback);

};

/**
* 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.
*
Expand Down Expand Up @@ -134,6 +192,64 @@ HlrLookupClient.prototype.submitAsyncLookupRequest = function submitAsyncLookupR

};

/**
* 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.
*
* @param callback - callback function(response)
* @param numbers - A list of numbers in international format, e.g. +4989702626,+491788735000
* @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
* @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
* @returns {*}
*
* 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"}}
*/
HlrLookupClient.prototype.submitAsyncNumberTypeLookupRequest = function submitAsyncNumberTypeLookupRequest(callback, numbers, route, storage) {

if (!callback || typeof callback != 'function') {
return console.error('Invalid Argument: callback');
}

if (!this.validateUsage()) {
return callback(generateErrorResponse('Missing client arguments (username or password)'));
}

if (!numbers) {
return callback(generateErrorResponse('Missing Argument: numbers'));
}

if (typeof numbers != 'object') {
return callback(generateErrorResponse('Invalid Argument: msisdns must be of type array'));
}

if (route) {
if (typeof route != 'string') {
return callback(generateErrorResponse('Invalid Argument: route must be of type string'));
}
}

if (storage) {
if (typeof storage != 'string') {
return callback(generateErrorResponse('Invalid Argument: storage must be of type string'));
}
}

client.post(this.url, {
data: {
action: "submitAsyncNumberTypeLookupRequest",
numbers: convertMsisdnsArrayToString(numbers),
username: this.username,
password: this.password,
route: route ? route : null,
storage: storage ? storage : null
},
headers: {
"Content-Type": "application/json"
}
},
callback);

};

/**
* 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
*
Expand Down Expand Up @@ -176,6 +292,48 @@ HlrLookupClient.prototype.setAsyncCallbackUrl = function setAsyncCallbackUrl(cal

};

/**
* Sets the callback URL for asynchronous number type lookups.
*
* @param callback - callback function(response)
* @param url - callback url on your server
* @returns {*}
*
* Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:[email protected]\/path\/file"}}
*/
HlrLookupClient.prototype.setNtAsyncCallbackUrl = function setNtAsyncCallbackUrl(callback, url) {

if (!callback || typeof callback != 'function') {
return console.error('Invalid Argument: callback');
}

if (!this.validateUsage()) {
return callback(generateErrorResponse('Missing client arguments (username or password)'));
}

if (!url) {
return callback(generateErrorResponse('Missing Argument: url'));
}

if (typeof url != 'string') {
return callback(generateErrorResponse('Invalid Argument: url must be of type string'));
}

client.post(this.url, {
data: {
action: "setNtAsyncCallbackUrl",
url: url,
username: this.username,
password: this.password
},
headers: {
"Content-Type": "application/json"
}
},
callback);

};

/**
* Returns the remaining balance (EUR) in your account.
*
Expand Down Expand Up @@ -208,6 +366,38 @@ HlrLookupClient.prototype.getBalance = function getBalance(callback) {

};

/**
* Performs a system health check and returns a sanity report.
*
* @param callback - callback function(response)
* @returns {*}
*
* 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" } } }
*/
HlrLookupClient.prototype.doHealthCheck = function doHealthCheck(callback) {

if (!callback || typeof callback != 'function') {
return console.error('Invalid Argument: callback');
}

if (!this.validateUsage()) {
return callback(generateErrorResponse('Missing client arguments (username or password)'));
}

client.post(this.url, {
data: {
action: "doHealthCheck",
username: this.username,
password: this.password
},
headers: {
"Content-Type": "application/json"
}
},
callback);

};

/**
* Parses an asynchronous HLR Lookup callback and returns a JSON string with the results.
*
Expand Down
6 changes: 4 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Velocity Made Good Ltd.",
"name": "node-hlr-client",
"description": "Official HLR Lookup API Node JS SDK by www.hlr-lookups.com",
"version": "0.0.10",
"version": "0.0.11",
"repository": {
"url": ""
},
Expand All @@ -11,7 +11,9 @@
"hlr",
"hlr lookup",
"hlr lookups",
"hlr lookup api"
"hlr lookup api",
"landline lookups",
"number type lookups"
],
"bin": {
"uppercaseme": "./bin/node-hlr-client"
Expand Down
Loading

0 comments on commit cc027f1

Please sign in to comment.