@mediocre/bloodhound
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -0,1 +1,2 @@ | ||
const NodeGeocoder = require('node-geocoder'); | ||
const PitneyBowes = require('./carriers/pitneyBowes'); | ||
@@ -5,3 +6,10 @@ const FedEx = require('./carriers/fedEx'); | ||
const geography = require('./util/geography'); | ||
function Bloodhound(options) { | ||
// Optionally specify geocoder options | ||
if (options && options.geocoder) { | ||
geography.geocoder = NodeGeocoder(options.geocoder); | ||
} | ||
// Allow PitneyBowes to cache geocode results in Redis (via petty-cache) | ||
@@ -8,0 +16,0 @@ if (options && options.pettyCache && options.pitneyBowes) { |
@@ -39,3 +39,3 @@ { | ||
}, | ||
"version": "0.3.2" | ||
"version": "0.4.0" | ||
} |
@@ -7,3 +7,2 @@ const async = require('async'); | ||
const geocoder = NodeGeocoder({ provider: 'openstreetmap' }); | ||
var pettyCache; | ||
@@ -16,3 +15,3 @@ | ||
async.retry(function(callback) { | ||
geocoder.geocode(location, callback); | ||
exports.geocoder.geocode(location, callback); | ||
}, function(err, results) { | ||
@@ -27,4 +26,9 @@ if (err) { | ||
const firstResult = results[0]; | ||
var firstResult = results[0]; | ||
// Handle Google results | ||
if (!firstResult.state && firstResult.administrativeLevels && firstResult.administrativeLevels.level1short) { | ||
firstResult.state = firstResult.administrativeLevels.level1short; | ||
} | ||
// Check to see if the first result has the data we need | ||
@@ -37,3 +41,3 @@ if (firstResult.city && firstResult.state && firstResult.zipcode) { | ||
async.retry(function(callback) { | ||
geocoder.reverse({ lat: firstResult.latitude, lon: firstResult.longitude }, callback); | ||
exports.geocoder.reverse({ lat: firstResult.latitude, lon: firstResult.longitude }, callback); | ||
}, function(err, results) { | ||
@@ -44,2 +48,9 @@ if (err) { | ||
var firstResult = results[0]; | ||
// Handle Google results | ||
if (!firstResult.state && firstResult.administrativeLevels && firstResult.administrativeLevels.level1short) { | ||
firstResult.state = firstResult.administrativeLevels.level1short; | ||
} | ||
callback(null, results[0]); | ||
@@ -116,2 +127,4 @@ }); | ||
geocode(location, callback); | ||
}); | ||
}); | ||
exports.geocoder = NodeGeocoder({ provider: 'openstreetmap' }); |
26655
533