Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "roadrunnr", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A Node wrapper for Roadrunnr logistic serrvices", | ||
@@ -5,0 +5,0 @@ "main": "roadrunnr.js", |
@@ -78,3 +78,5 @@ # RoadRunnr NodeJs Wrapper | ||
runnr.trackShipment(id, function(error, response) { | ||
if (error == null) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log(response); | ||
@@ -88,3 +90,5 @@ } | ||
runnr.cancelShipment(id, function(error, response) { | ||
if (error == null) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log(response); | ||
@@ -98,3 +102,5 @@ } | ||
runnr.checkServiceability(orderRequest, function(error, response) { | ||
if (error == null) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log(response); | ||
@@ -120,3 +126,5 @@ } | ||
runnr.createShipment(newOrderRequest, function(error, response) { | ||
if (error == null) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log(response); | ||
@@ -146,8 +154,11 @@ } | ||
console.log(req.rawBody); | ||
res.send(req.rawBody); | ||
res.send("OK"); | ||
}); | ||
``` | ||
### Changes in v0.0.5 | ||
This wrapper now checks for errors thrown by the Roadrunnr API. Please check for errors in all API calls. | ||
--- | ||
### Submit issues | ||
You can raise an issue in this repo or mail me at sidhant@hashexclude.com |
119
roadrunnr.js
@@ -7,3 +7,3 @@ var request = require('request'); | ||
production : 'http://roadrunnr.in/', | ||
test : 'http://128.199.241.199/' | ||
test : 'http://apitest.roadrunnr.in/' | ||
}; | ||
@@ -95,7 +95,14 @@ | ||
'config' : { | ||
'CLIENT_ID' : 'YOUR-PRODUCTION-CLIENT-ID', | ||
'CLIENT_SECRET' : 'YOUR-PRODUCTION-CLIENT-SECRET' | ||
'CLIENT_ID' : 'YOUR-CLIENT-ID', | ||
'CLIENT_SECRET' : 'YOUR-CLIENT-SECRET' | ||
}, | ||
setOAuthPath : function(path) { | ||
try { | ||
fs.unlinkSync(this.oauth_json_path); | ||
} catch (e) { | ||
// console.log("No previous Roadrunnr OAuth file found"); | ||
// console.log(e); | ||
} | ||
this.oauth_json_path = path; | ||
@@ -107,2 +114,9 @@ }, | ||
this.config.CLIENT_SECRET = clientSecret; | ||
try { | ||
fs.unlinkSync(this.oauth_json_path); | ||
} catch (e) { | ||
// console.log("No previous Roadrunnr OAuth file found"); | ||
// console.log(e); | ||
} | ||
}, | ||
@@ -139,3 +153,3 @@ | ||
} else { | ||
callback(null, body); | ||
checkRRErrors(body, callback); | ||
} | ||
@@ -162,3 +176,3 @@ }); | ||
} else { | ||
callback(null, body); | ||
checkRRErrors(body, callback); | ||
} | ||
@@ -186,3 +200,3 @@ }); | ||
} else { | ||
callback(null, body); | ||
checkRRErrors(body, callback); | ||
} | ||
@@ -209,3 +223,3 @@ }); | ||
} else { | ||
callback(null, body); | ||
checkRRErrors(body, callback); | ||
} | ||
@@ -217,2 +231,3 @@ }); | ||
// Optional, requires 'geocoder' npm module | ||
// Run 'npm install geocoder' to use this method: | ||
assignLatLong : function(orderRequest, callback) { | ||
@@ -302,3 +317,89 @@ getLatLngForAddress(orderRequest.pickup.user.full_address.address, function(error, pickupGeo) { | ||
function checkRRErrors(body, callback) { | ||
var error = null; | ||
if (body.errors != null) { | ||
error = body.errors; | ||
} else if (body.status != null) { | ||
if (body.status.code != null) { | ||
error = getErrorInfo(body.status.code); | ||
} else { | ||
error = getErrorInfo(parseInt(body.status)); | ||
} | ||
} | ||
callback(error, body); | ||
} | ||
/** | ||
* Helper method to get information on Roadrunnr error codes | ||
* @param code Error code thrown by Roadrunnr APIs | ||
* @returns {{code: number, info: string}} Contains the error code and a small description of the error | ||
*/ | ||
function getErrorInfo(code) { | ||
var error = { | ||
code: 0, | ||
info: '' | ||
}; | ||
switch(code) { | ||
case 200: | ||
error = null; | ||
break; | ||
case 301: | ||
error.code = code; | ||
error.info = 'The order cannot be cancelled. Contact Roadrunnr tech support.'; | ||
break; | ||
case 310: | ||
error.code = code; | ||
error.info = 'The scheduled time is invalid. The scheduled delivery can be scheduled with a minimum of 2 hours from present time.'; | ||
break; | ||
case 312: | ||
error.code = code; | ||
error.info = 'This area is not serviceable. Distance > 8km.'; | ||
break; | ||
case 400: | ||
error.code = code; | ||
error.info = 'Bad request. Contact Roadrunnr tech support.'; | ||
break; | ||
case 404: | ||
error.code = code; | ||
error.info = 'No input file specified. Contact Roadrunnr tech support.'; | ||
break; | ||
case 422: | ||
error.code = code; | ||
error.info = 'Some error in OrderRequest. Check response body for details.'; | ||
break; | ||
case 500: | ||
error.code = code; | ||
error.info = 'Roadrunnr server error.'; | ||
break; | ||
case 706: | ||
error.code = code; | ||
error.info = 'No drivers available currently in the area. Retry in sometime.'; | ||
break; | ||
case 810: | ||
error.code = code; | ||
error.info = 'Insufficient balance in account. Please recharge to create shipments.'; | ||
break; | ||
default: | ||
error.code = code; | ||
error.info = 'Unknown error from Roadrunnr. Check response for more details or contact tech support.'; | ||
break; | ||
} | ||
return error; | ||
} | ||
/** | ||
* Helper method to read file in JSON format | ||
@@ -310,3 +411,3 @@ * | ||
*/ | ||
function readFile (path, options, callback) { | ||
function readFile(path, options, callback) { | ||
if (callback == null) { | ||
@@ -339,3 +440,3 @@ callback = options; | ||
*/ | ||
function writeFile (path, obj, options, callback) { | ||
function writeFile(path, obj, options, callback) { | ||
if (callback == null) { | ||
@@ -342,0 +443,0 @@ callback = options; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19233
420
160