Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions api/mosaics.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
var Page = require('./page');
var request = require('./request');
var urls = require('./urls');
var util = require('./util');

/**
* Get metadata for a single mosaic.
* @param {string} id A mosaic identifier.
* @param {Object} options Options.
* @param {boolean} options.augmentLinks Add API key to links for image
* resources in the response. True by default.
* @param {function(function())} options.terminator A function that is called
* with a function that can be called back to terminate the request.
* @return {Promise.<Object>} A promise that resolves to mosaic metadata or is
Expand All @@ -28,9 +25,6 @@ function get(id, options) {
terminator: options.terminator
};
return request.get(config).then(function(res) {
if (options.augmentLinks !== false) {
util.augmentMosaicLinks(res.body);
}
return res.body;
});
}
Expand All @@ -39,8 +33,6 @@ function get(id, options) {
* Get a collection of mosaic metadata.
* @param {Object} query A query object.
* @param {Object} options Options.
* @param {boolean} options.augmentLinks Add API key to links for image
* resources in the response. True by default.
* @param {function(function())} options.terminator A function that is called
* with a function that can be called back to terminate the request.
* @return {Promise.<module:planet-client/api/page~Page>} A promise that
Expand All @@ -56,12 +48,6 @@ function search(query, options) {
terminator: options.terminator
};
return request.get(config).then(function(res) {
if (options.augmentLinks !== false) {
var mosaics = res.body.mosaics;
for (var i = 0, ii = mosaics.length; i < ii; ++i) {
util.augmentMosaicLinks(mosaics[i]);
}
}
return new Page(res.body, search);
});
}
Expand Down
22 changes: 0 additions & 22 deletions api/quads.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
var Page = require('./page');
var request = require('./request');
var urls = require('./urls');
var util = require('./util');

/**
* Get metadata for a mosaic quad.
* @param {string} mosaicId A mosaic identifier.
* @param {string} quadId A quad identifier.
* @param {Object} options Options.
* @param {boolean} options.augmentLinks Add API key to links for image
* resources in the response. True by default.
* @param {function(function())} options.terminator A function that is called
* with a function that can be called back to terminate the request.
* @return {Promise.<Object>} A promise that resolves to quad metadata or is
Expand All @@ -29,9 +26,6 @@ function get(mosaicId, quadId, options) {
terminator: options.terminator
};
return request.get(config).then(function(res) {
if (options.augmentLinks !== false) {
util.augmentQuadLinks(res.body);
}
return res.body;
});
}
Expand All @@ -41,8 +35,6 @@ function get(mosaicId, quadId, options) {
* @param {string} mosaicId A mosaic identifier.
* @param {Object} query A query object.
* @param {Object} options Options.
* @param {boolean} options.augmentLinks Add API key to links for image
* resources in the response. True by default.
* @param {function(function())} options.terminator A function that is called
* with a function that can be called back to terminate the request.
* @return {Promise.<module:planet-client/api/page~Page>} A promise that
Expand All @@ -58,12 +50,6 @@ function search(mosaicId, query, options) {
terminator: options.terminator
};
return request.get(config).then(function(res) {
if (options.augmentLinks !== false) {
var quads = res.body.features;
for (var i = 0, ii = quads.length; i < ii; ++i) {
util.augmentQuadLinks(quads[i]);
}
}
return new Page(res.body, search.bind(null, mosaicId));
});
}
Expand All @@ -73,8 +59,6 @@ function search(mosaicId, query, options) {
* @param {string} mosaicId A mosaic identifier.
* @param {string} quadId A quad identifier.
* @param {Object} options Options.
* @param {boolean} options.augmentLinks Add API key to links for image
* resources in the response. True by default.
* @param {function(function())} options.terminator A function that is called
* with a function that can be called back to terminate the request.
* @return {Promise.<Object>} A promise that resolves to quad metadata or is
Expand All @@ -89,12 +73,6 @@ function scenes(mosaicId, quadId, options) {
terminator: options.terminator
};
return request.get(config).then(function(res) {
if (options.augmentLinks !== false) {
var features = res.body.features;
for (var i = 0, ii = features.length; i < ii; ++i) {
util.augmentSceneLinks(features[i]);
}
}
return res.body;
});
}
Expand Down
14 changes: 0 additions & 14 deletions api/scenes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
var Page = require('./page');
var request = require('./request');
var urls = require('./urls');
var util = require('./util');

/**
* Get metadata for a single scene.
* @param {Object|string} scene An object with scene id and type properties. If
* a string is provided, it is assumed to be the id, and the type will be
* set to 'ortho'.
* @param {Object} options Options.
* @param {boolean} options.augmentLinks Add API key to links for image
* resources in the response. True by default.
* @param {function(function())} options.terminator A function that is called
* with a function that can be called back to terminate the request.
* @return {Promise.<Object>} A promise that resolves to scene metadata or is
Expand All @@ -36,9 +33,6 @@ function get(scene, options) {
terminator: options.terminator
};
return request.get(config).then(function(res) {
if (options.augmentLinks !== false) {
util.augmentSceneLinks(res.body);
}
return res.body;
});
}
Expand All @@ -47,8 +41,6 @@ function get(scene, options) {
* Get a collection of scene metadata based on a query.
* @param {Object} query A query object.
* @param {Object} options Options.
* @param {boolean} options.augmentLinks Add API key to links for image
* resources in the response. True by default.
* @param {function(function())} options.terminator A function that is called
* with a function that can be called back to terminate the request.
* @return {Promise.<module:planet-client/api/page~Page>} A promise that
Expand All @@ -72,12 +64,6 @@ function search(query, options) {
terminator: options.terminator
};
return request.get(config).then(function(res) {
if (options.augmentLinks !== false) {
var scenes = res.body.features;
for (var i = 0, ii = scenes.length; i < ii; ++i) {
util.augmentSceneLinks(scenes[i]);
}
}
return new Page(res.body, search);
});
}
Expand Down
60 changes: 0 additions & 60 deletions api/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

var querystring = require('querystring');

var authStore = require('./auth-store');

function addQueryParams(link, params) {
var baseHash = link.split('#');
var base = baseHash[0];
Expand All @@ -23,61 +21,6 @@ function addQueryParams(link, params) {
return parts[0] + '?' + search + (hash ? ('#' + hash) : '');
}

function augmentSceneLinks(scene) {
var properties = scene.properties;
var key = authStore.getKey();

if (key) {
var links = properties.links;
links.full = addQueryParams(links.full, {'api_key': key});
links.thumbnail = addQueryParams(links.thumbnail, {'api_key': key});
links['square_thumbnail'] = addQueryParams(
links['square_thumbnail'], {'api_key': key});

var products = properties.data.products;
for (var type in products) {
var product = products[type];
for (var format in product) {
product[format] = addQueryParams(product[format], {'api_key': key});
}
}
}

return scene;
}

function augmentQuadLinks(quad) {
var key = authStore.getKey();

if (key) {
var links = quad.properties.links;
if (links.full) {
links.full = addQueryParams(links.full, {'api_key': key});
}
if (links.thumbnail) {
links.thumbnail = addQueryParams(links.thumbnail, {'api_key': key});
}
}

return quad;
}

function augmentMosaicLinks(mosaic) {
var key = authStore.getKey();

if (key) {
var links = mosaic.links;
if (links.tiles) {
links.tiles = addQueryParams(links.tiles, {'api_key': key});
}
if (links.quadmap) {
links.quadmap = addQueryParams(links.quadmap, {'api_key': key});
}
}

return mosaic;
}

/**
* Simplified polyfill for ES6 Object.assign.
* @param {Object} target The target object.
Expand All @@ -96,7 +39,4 @@ function assign(target, src) {
}

exports.addQueryParams = addQueryParams;
exports.augmentMosaicLinks = augmentMosaicLinks;
exports.augmentQuadLinks = augmentQuadLinks;
exports.augmentSceneLinks = augmentSceneLinks;
exports.assign = assign;
2 changes: 1 addition & 1 deletion cli/find-scenes.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function main(opts) {
return resolveQuery(opts)
.then(function(query) {
log.debug('query: %j', query);
return fetch(scenes.search(query, {augmentLinks: false}), [], opts.limit);
return fetch(scenes.search(query), [], opts.limit);
}).then(function(features) {
return JSON.stringify({
type: 'FeatureCollection',
Expand Down
76 changes: 0 additions & 76 deletions test/api/mosaics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,43 +71,6 @@ describe('api/mosaics', function() {
}).catch(done);
});

it('augments links if key is set', function(done) {
auth.setKey('my-key');

request.get = function(config) {
return Promise.resolve({
body: mosaic
});
};

var promise = mosaics.get('one');

promise.then(function(got) {
assert.equal(got.links.tiles,
'https://s{0-3}.example.com/v0/mosaics/one/{z}/{x}/{y}.png' +
'?api_key=my-key');
done();
}).catch(done);
});

it('can be told not to augment links', function(done) {
auth.setKey('my-key');

request.get = function(config) {
return Promise.resolve({
body: mosaic
});
};

var promise = mosaics.get('one', {augmentLinks: false});

promise.then(function(got) {
assert.equal(got.links.tiles,
'https://s{0-3}.example.com/v0/mosaics/one/{z}/{x}/{y}.png');
done();
}).catch(done);
});

});

describe('search()', function() {
Expand Down Expand Up @@ -143,45 +106,6 @@ describe('api/mosaics', function() {
}).catch(done);
});

it('augments links if key is set', function(done) {
auth.setKey('my-key');

request.get = function(config) {
return Promise.resolve({
body: {
mosaics: [mosaic],
links: {}
}
});
};

mosaics.search({}).then(function(got) {
assert.equal(got.data.mosaics[0].links.tiles,
'https://s{0-3}.example.com/v0/mosaics/one/{z}/{x}/{y}.png?' +
'api_key=my-key');
done();
}).catch(done);
});

it('can be told not to augment links', function(done) {
auth.setKey('my-key');

request.get = function(config) {
return Promise.resolve({
body: {
mosaics: [mosaic],
links: {}
}
});
};

mosaics.search({}, {augmentLinks: false}).then(function(got) {
assert.equal(got.data.mosaics[0].links.tiles,
'https://s{0-3}.example.com/v0/mosaics/one/{z}/{x}/{y}.png');
done();
}).catch(done);
});

});

});
Loading