Skip to content

Commit

Permalink
Improve internal documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Aug 14, 2015
1 parent 58884d6 commit d66ce73
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/client.js
Expand Up @@ -28,6 +28,8 @@ var MapboxDatasets = require('./services/datasets');
*/
var MapboxClient = makeClient('MapboxClient');

// Combine all client APIs into one API for when people require()
// the main mapbox-sdk-js library.
xtend(MapboxClient.prototype,
MapboxGeocoder.prototype,
MapboxSurface.prototype,
Expand Down
3 changes: 3 additions & 0 deletions lib/constants.js
@@ -1,5 +1,8 @@
var compile = require('es6-template-strings/compile');

// We keep all of the constants that declare endpoints in one
// place, so that we could concievably update this for API layout
// revisions.
module.exports.DEFAULT_ENDPOINT = 'https://api.mapbox.com';
module.exports.API_GEOCODER_FORWARD = compile('${endpoint}/v4/geocode/${dataset}/${encodeURIComponent(forwardQuery)}.json?${query}');
module.exports.API_GEOCODER_REVERSE = compile('${endpoint}/v4/geocode/${dataset}/${location.longitude},${location.latitude}.json?${query}');
Expand Down
10 changes: 10 additions & 0 deletions lib/format_points.js
Expand Up @@ -2,6 +2,16 @@

var invariant = require('invariant');

/**
* Format waypionts in a way that's friendly to the directions and surface
* API: comma-separated latitude, longitude pairs with semicolons between
* them.
* @private
* @param {Array<Object>} waypoints array of objects with latitude and longitude
* properties
* @returns {string} formatted points
* @throws {Error} if the input is invalid
*/
function formatPoints(waypoints) {
return waypoints.map(function(location) {
invariant(typeof location.latitude === 'number' &&
Expand Down
10 changes: 10 additions & 0 deletions lib/get_user.js
@@ -1,5 +1,15 @@
'use strict';

/**
* Access tokens actually are data, and using them we can derive
* a user's username. This method attempts to do just that,
* decoding the part of the token after the first `.` into
* a username.
*
* @private
* @param {string} token an access token
* @return {string} username
*/
function getUser(token) {
var data = token.split('.')[1];
if (!data) return null;
Expand Down
11 changes: 11 additions & 0 deletions lib/make_service.js
Expand Up @@ -4,6 +4,17 @@ var invariant = require('invariant');
var constants = require('./constants');
var getUser = require('./get_user');

/**
* Services all have the same constructor pattern: you initialize them
* with an access token and options, and they validate those arguments
* in a predictable way. This is a constructor-generator that makes
* it possible to require each service's API individually.
*
* @private
* @param {string} name the name of the Mapbox API this class will access:
* this is set to the name of the function so it will show up in tracebacks
* @returns {Function} constructor function
*/
function makeService(name) {

function service(accessToken, options) {
Expand Down

0 comments on commit d66ce73

Please sign in to comment.