Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added config magic

  • Loading branch information...
commit 910a3b73fffe759998b477674ce43244ae8a2f16 1 parent 6ca5ee5
@regality regality authored
Showing with 27 additions and 21 deletions.
  1. +27 −21 lib/googlemaps.js
View
48 lib/googlemaps.js
@@ -2,32 +2,38 @@ var qs = require('querystring'),
request = require('request'),
crypto = require("crypto"),
url = require('url'),
- waitress = require('waitress');
-
-var util = require('util');
-var proxy;
-var googleClientId = null;
-var googlePrivateKey = null;
-var staggerTime = 200;
+ waitress = require('waitress'),
+ util = require('util');
+// this is deprecated
exports.setProxy = function(uri) {
- proxy = uri;
-};
-
-exports.setBusinessSpecificParameters = function(clientId, privateKey) {
- // Google private keys are URL friendly base64, needs to be replaced with base64 valid characters
- googlePrivateKey = privateKey.replace(/-/g,'+').replace(/_/g,'/');
- googlePrivateKey = new Buffer(googlePrivateKey, 'base64');
- googleClientId = clientId;
+ configure('proxy', uri);
};
-exports.clearBusinessSpecificParameters = function() {
- googlePrivateKey = null;
- googleClientId = null;
+var config = {
+ 'google-client-id': null,
+ 'stagger-time': 200,
+ 'encode-polylines': true,
+ 'proxy': null,
+ set 'google-private-key'(privateKey) {
+ // Google private keys are URL friendly base64, needs to be replaced with base64 valid characters
+ this.googlePrivateKey = privateKey.replace(/-/g,'+').replace(/_/g,'/');
+ this.googlePrivateKey = new Buffer(this.googlePrivateKey, 'base64');
+ },
+ get 'google-private-key'() {
+ return this.googlePrivateKey || null;
+ }
};
-exports.setStaggerTime = function(stagger) {
- staggerTime = stagger;
+exports.configure(key, value) {
+ if (typeof key === 'object' && key !== null) {
+ var settings = key;
+ for (var key in settings) {
+ config[key] = settings[key];
+ }
+ } else {
+ config[key] = value;
+ }
};
// http://code.google.com/apis/maps/documentation/places/
@@ -371,7 +377,7 @@ var makeRequest = function(path, args, secure, callback, encoding) {
};
if (encoding) options.encoding = encoding;
- if (proxy) options.proxy = proxy;
+ if (proxy) options.proxy = config.proxy;
if (typeof callback === 'function') {
request(options, function (error, res, data) {
Please sign in to comment.
Something went wrong with that request. Please try again.