Skip to content

Commit

Permalink
Prototype-extension approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Jul 18, 2015
1 parent 29147ae commit 0e579d9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/client.js
@@ -1,6 +1,7 @@
'use strict';

var invariant = require('invariant');
var xtend = require('xtend/mutable');

var MapboxGeocoder = require('./services/geocoder');
var MapboxSurface = require('./services/surface');
Expand All @@ -19,14 +20,13 @@ var MapboxMatching = require('./services/matching');
function MapboxClient(accessToken) {
invariant(typeof accessToken === 'string',
'accessToken required to instantiate MapboxClient');

this.accessToken = accessToken;

this.geocoder = new MapboxGeocoder(accessToken);
this.surface = new MapboxSurface(accessToken);
this.matching = new MapboxMatching(accessToken);
this.directions = new MapboxDirections(accessToken);

}

xtend(MapboxClient.prototype,
MapboxGeocoder.prototype,
MapboxSurface.prototype,
MapboxDirections.prototype,
MapboxMatching.prototype);

module.exports = MapboxClient;
2 changes: 2 additions & 0 deletions lib/services/directions.js
Expand Up @@ -123,3 +123,5 @@ MapboxDirections.prototype.getDirections = function(waypoints, options, callback
callback(err, res.body);
});
};

module.exports = MapboxDirections;
3 changes: 2 additions & 1 deletion lib/services/geocoder.js
Expand Up @@ -17,7 +17,8 @@ var invariant = require('invariant'),
*/
function MapboxGeocoder(accessToken) {
invariant(typeof accessToken === 'string',
'accessToken required to instantiate MapboxClient');
'accessToken required to instantiate MapboxGeocoder');
console.log('geocoder constructed');
this.accessToken = accessToken;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/services/matching.js
Expand Up @@ -125,3 +125,5 @@ MapboxMatching.prototype.matching = function(trace, options, callback) {
callback(err, res.body);
});
};

module.exports = MapboxMatching;
2 changes: 2 additions & 0 deletions lib/services/surface.js
Expand Up @@ -108,3 +108,5 @@ MapboxSurface.prototype.surface = function(mapid, layer, fields, path, options,
callback(err, res.body);
});
};

module.exports = MapboxSurface;
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -37,6 +37,7 @@
"es6-template-strings": "^1.0.0",
"geojsonhint": "^1.0.1",
"invariant": "^2.1.0",
"superagent": "^1.2.0"
"superagent": "^1.2.0",
"xtend": "^4.0.0"
}
}

0 comments on commit 0e579d9

Please sign in to comment.