diff --git a/api/mosaics.js b/api/mosaics.js index 5dc217a..cdc8e63 100644 --- a/api/mosaics.js +++ b/api/mosaics.js @@ -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.} A promise that resolves to mosaic metadata or is @@ -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; }); } @@ -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.} A promise that @@ -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); }); } diff --git a/api/quads.js b/api/quads.js index a253bb4..1f4dec1 100644 --- a/api/quads.js +++ b/api/quads.js @@ -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.} A promise that resolves to quad metadata or is @@ -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; }); } @@ -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.} A promise that @@ -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)); }); } @@ -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.} A promise that resolves to quad metadata or is @@ -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; }); } diff --git a/api/scenes.js b/api/scenes.js index 0a8966a..190a8ba 100644 --- a/api/scenes.js +++ b/api/scenes.js @@ -6,7 +6,6 @@ var Page = require('./page'); var request = require('./request'); var urls = require('./urls'); -var util = require('./util'); /** * Get metadata for a single scene. @@ -14,8 +13,6 @@ var util = require('./util'); * 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.} A promise that resolves to scene metadata or is @@ -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; }); } @@ -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.} A promise that @@ -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); }); } diff --git a/api/util.js b/api/util.js index 086525c..bd6f8d3 100644 --- a/api/util.js +++ b/api/util.js @@ -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]; @@ -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. @@ -96,7 +39,4 @@ function assign(target, src) { } exports.addQueryParams = addQueryParams; -exports.augmentMosaicLinks = augmentMosaicLinks; -exports.augmentQuadLinks = augmentQuadLinks; -exports.augmentSceneLinks = augmentSceneLinks; exports.assign = assign; diff --git a/cli/find-scenes.js b/cli/find-scenes.js index 2fc6180..84c4c04 100644 --- a/cli/find-scenes.js +++ b/cli/find-scenes.js @@ -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', diff --git a/test/api/mosaics.test.js b/test/api/mosaics.test.js index 3e42ca3..43dd6b2 100644 --- a/test/api/mosaics.test.js +++ b/test/api/mosaics.test.js @@ -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() { @@ -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); - }); - }); }); diff --git a/test/api/quads.test.js b/test/api/quads.test.js index 84c37ca..9824776 100644 --- a/test/api/quads.test.js +++ b/test/api/quads.test.js @@ -76,43 +76,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: quad - }); - }; - - var promise = quads.get('my-mosaic', 'my-quad'); - - promise.then(function(got) { - assert.equal(got.properties.links.full, - 'https://example.com/mosaics/one/quads/two/full' + - '?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: quad - }); - }; - - var promise = quads.get('my-mosaic', 'my-quad', {augmentLinks: false}); - - promise.then(function(got) { - assert.equal(got.properties.links.full, - 'https://example.com/mosaics/one/quads/two/full'); - done(); - }).catch(done); - }); - }); describe('search()', function() { @@ -148,45 +111,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: { - features: [quad], - links: {} - } - }); - }; - - quads.search('my-mosaic', {}).then(function(got) { - assert.equal(got.data.features[0].properties.links.full, - 'https://example.com/mosaics/one/quads/two/full' + - '?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: { - features: [quad], - links: {} - } - }); - }; - - quads.search('my-mosaic', {}, {augmentLinks: false}).then(function(got) { - assert.equal(got.data.features[0].properties.links.full, - 'https://example.com/mosaics/one/quads/two/full'); - done(); - }).catch(done); - }); - }); describe('scenes()', function() { @@ -237,45 +161,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: { - features: [scene], - links: {} - } - }); - }; - - quads.scenes('my-mosaic', 'my-quad').then(function(got) { - assert.equal(got.features[0].properties.links.full, - 'http://example.com/?api_key=my-key#hash'); - 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: { - features: [scene], - links: {} - } - }); - }; - - quads.scenes('my-mosaic', 'my-quad', {augmentLinks: false}) - .then(function(got) { - assert.equal(got.features[0].properties.links.full, - 'http://example.com/#hash'); - done(); - }).catch(done); - }); - }); }); diff --git a/test/api/scenes.test.js b/test/api/scenes.test.js index 2443539..1ad1a61 100644 --- a/test/api/scenes.test.js +++ b/test/api/scenes.test.js @@ -81,42 +81,6 @@ describe('api/scenes', function() { }).catch(done); }); - it('augments links if key is set', function(done) { - auth.setKey('my-key'); - - request.get = function(config) { - return Promise.resolve({ - body: scene - }); - }; - - var promise = scenes.get('bar'); - - promise.then(function(got) { - assert.equal(got.properties.links.full, - 'http://example.com/?api_key=my-key#hash'); - 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: scene - }); - }; - - var promise = scenes.get('bar', {augmentLinks: false}); - - promise.then(function(got) { - assert.equal(got.properties.links.full, - 'http://example.com/#hash'); - done(); - }).catch(done); - }); - }); describe('search()', function() { @@ -204,44 +168,6 @@ describe('api/scenes', function() { }).catch(done); }); - it('augments links if key is set', function(done) { - auth.setKey('my-key'); - - request.get = function(config) { - return Promise.resolve({ - body: { - features: [scene], - links: {} - } - }); - }; - - scenes.search({foo: 'bar'}).then(function(got) { - assert.equal(got.data.features[0].properties.links.full, - 'http://example.com/?api_key=my-key#hash'); - 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: { - features: [scene], - links: {} - } - }); - }; - - scenes.search({foo: 'bar'}, {augmentLinks: false}).then(function(got) { - assert.equal(got.data.features[0].properties.links.full, - 'http://example.com/#hash'); - done(); - }).catch(done); - }); - }); }); diff --git a/test/api/util.test.js b/test/api/util.test.js index bc4b853..0ab6967 100644 --- a/test/api/util.test.js +++ b/test/api/util.test.js @@ -1,7 +1,6 @@ /* eslint-env mocha */ var assert = require('chai').assert; -var authStore = require('../../api/auth-store'); var util = require('../../api/util'); describe('api/util', function() { @@ -58,196 +57,6 @@ describe('api/util', function() { }); - describe('augmentSceneLinks()', function() { - var scene; - - beforeEach(function() { - scene = util.assign({}, { - properties: { - links: { - 'full': 'http://example.com/#hash', - 'square_thumbnail': 'http://example.com/?foo=bar', - 'thumbnail': 'http://example.com/thumb' - }, - data: { - products: { - foo: { - bar: 'http://example.com/foo/bar' - } - } - } - } - }); - }); - - afterEach(function() { - authStore.clear(); - }); - - it('adds a API key from stored token to data URLs', function() { - // {api_key: 'my-api-key'} - var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcGlfa2V5Ijoib' + - 'XktYXBpLWtleSJ9.sYcuJzdUThIsvJGNymbobOh-nY6ZKFEqXTqwZS-4QvE'; - authStore.setToken(token); - var key = authStore.getKey(); - - var augmented = util.augmentSceneLinks(scene); - assert.equal(augmented.properties.links.full, - 'http://example.com/?api_key=' + key + '#hash'); - assert.equal(augmented.properties.links['square_thumbnail'], - 'http://example.com/?foo=bar&api_key=' + key); - assert.equal(augmented.properties.links.thumbnail, - 'http://example.com/thumb?api_key=' + key); - assert.equal(augmented.properties.data.products.foo.bar, - 'http://example.com/foo/bar?api_key=' + key); - }); - - it('adds a stored API key to data URLs', function() { - var key = 'my-key'; - authStore.setKey(key); - - var augmented = util.augmentSceneLinks(scene); - assert.equal(augmented.properties.links.full, - 'http://example.com/?api_key=' + key + '#hash'); - assert.equal(augmented.properties.links['square_thumbnail'], - 'http://example.com/?foo=bar&api_key=' + key); - assert.equal(augmented.properties.links.thumbnail, - 'http://example.com/thumb?api_key=' + key); - assert.equal(augmented.properties.data.products.foo.bar, - 'http://example.com/foo/bar?api_key=' + key); - }); - - }); - - describe('augmentQuadLinks()', function() { - var quad; - - beforeEach(function() { - quad = util.assign({}, { - geometry: { - type: 'Polygon', - coordinates: [ - [ - [-78.925781239, 39.0959629318], - [-78.925781239, 38.9594087879], - [-78.749999989, 38.9594087879], - [-78.749999989, 39.0959629318], - [-78.925781239, 39.0959629318] - ] - ] - }, - type: 'Feature', - id: 'L15-0575E-1265N', - properties: { - updated: '2015-07-20T13:39:49.550576+00:00', - 'num_input_scenes': 28, - links: { - self: 'https://example.com/mosaics/one/quads/two', - full: 'https://example.com/mosaics/one/quads/two/full', - thumbnail: 'https://example.com/mosaics/one/quads/two/thumb', - mosaic: 'https://example.com/mosaics/one', - scenes: 'https://example.com/mosaics/one/quads/two/scenes/' - }, - 'percent_covered': 100 - } - }); - }); - - afterEach(function() { - authStore.clear(); - }); - - it('adds a API key from stored token to data URLs', function() { - // {api_key: 'my-api-key'} - var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcGlfa2V5Ijoib' + - 'XktYXBpLWtleSJ9.sYcuJzdUThIsvJGNymbobOh-nY6ZKFEqXTqwZS-4QvE'; - authStore.setToken(token); - var key = authStore.getKey(); - - var augmented = util.augmentQuadLinks(quad); - assert.equal(augmented.properties.links.full, - 'https://example.com/mosaics/one/quads/two/full?api_key=' + key); - assert.equal(augmented.properties.links.thumbnail, - 'https://example.com/mosaics/one/quads/two/thumb?api_key=' + key); - }); - - it('adds a stored API key to data URLs', function() { - var key = 'my-key'; - authStore.setKey(key); - - var augmented = util.augmentQuadLinks(quad); - assert.equal(augmented.properties.links.full, - 'https://example.com/mosaics/one/quads/two/full?api_key=' + key); - assert.equal(augmented.properties.links.thumbnail, - 'https://example.com/mosaics/one/quads/two/thumb?api_key=' + key); - }); - - }); - - describe('augmentMosaicLinks()', function() { - var mosaic; - - beforeEach(function() { - mosaic = util.assign({}, { - name: 'one', - links: { - quads: 'https://example.com/mosaics/one/quads/', - self: 'https://example.com/mosaics/one', - tiles: 'https://s{0-3}.example.com/v0/mosaics/one/{z}/{x}/{y}.png', - quadmap: 'https://example.com/mosaics/one/quad-map.png' - }, - 'first_acquired': '2014-03-20T15:57:11+00:00', - datatype: 'byte', - 'quad_size': 4096, - title: 'A Mosaic', - 'coordinate_system': 'EPSG:3857', - geometry: { - type: 'Polygon', - coordinates: [ - [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]] - ] - }, - 'last_acquired': '2015-07-20T02:11:31.947579+00:00', - 'scene_type': 'ortho', - 'quad_pattern': 'L{glevel:d}-{tilex:04d}E-{tiley:04d}N', - level: 15, - resolution: 4.77731426716 - }); - }); - - afterEach(function() { - authStore.clear(); - }); - - it('adds a API key from stored token to data URLs', function() { - // {api_key: 'my-api-key'} - var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcGlfa2V5Ijoib' + - 'XktYXBpLWtleSJ9.sYcuJzdUThIsvJGNymbobOh-nY6ZKFEqXTqwZS-4QvE'; - authStore.setToken(token); - var key = authStore.getKey(); - - var augmented = util.augmentMosaicLinks(mosaic); - assert.equal(augmented.links.tiles, - 'https://s{0-3}.example.com/v0/mosaics/one/{z}/{x}/{y}.png?api_key=' + - key); - assert.equal(augmented.links.quadmap, - 'https://example.com/mosaics/one/quad-map.png?api_key=' + key); - }); - - it('adds a stored API key to data URLs', function() { - var key = 'my-key'; - authStore.setKey(key); - - var augmented = util.augmentMosaicLinks(mosaic); - assert.equal(augmented.links.tiles, - 'https://s{0-3}.example.com/v0/mosaics/one/{z}/{x}/{y}.png?api_key=' + - key); - assert.equal(augmented.links.quadmap, - 'https://example.com/mosaics/one/quad-map.png?api_key=' + key); - }); - - }); - describe('assign()', function() { it('assigns source properties to target object', function() {