Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-32: bit.ly support complete

Mike McGann5abd81fb481c
diff --git a/Gruntfile.js b/Gruntfile.js
index 02eed4f37..59e66dd81 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -415,7 +415,7 @@ module.exports = function(grunt) {
version: "<%= pkg.version %>",
url: "https://earthdata.nasa.gov/worldview",
options: {
- paths: ["src/wv"],
+ paths: ["src/js"],
outdir: "build/doc"
}
}
@@ -429,6 +429,10 @@ module.exports = function(grunt) {
]
},
+ buster: {
+ all: {}
+ },
+
remove: {
build: ["build"],
dist: ["dist"],
@@ -524,6 +528,7 @@ module.exports = function(grunt) {
grunt.registerTask("doc", ["yuidoc"]);
grunt.registerTask("lint", ["jshint"]);
+ grunt.registerTask("test", ["buster"]);
grunt.registerTask("rpm", ["build", "rpm_only"]);
grunt.registerTask("clean", "remove:build");
grunt.registerTask("distclean", ["remove:build", "remove:dist"]);
diff --git a/buster.js b/buster.js
index 3bc299fb0..89a634375 100644
--- a/buster.js
+++ b/buster.js
@@ -15,13 +15,12 @@ config["wv"] = {
rootPath: "./",
environment: "browser",
libs: [
- "src/wv/ext/lodash/*.js",
- "src/wv/ext/jquery/*.js",
- "src/wv/ext/jscache/*.js",
+ "src/ext/wv.main/lodash-2.4.1/lodash.js",
+ "src/ext/wv.main/jquery-1.6.4/jquery.js",
+ "src/ext/wv.main/jscache-gitba01cdc/cache.js",
],
src: [
- "src/wv/**/*.js",
- "!src/wv/**/ext/**/*.js"
+ "src/js/**/wv.*.js"
],
tests: [
"test/**/*.js"
diff --git a/src/js/link/wv.link.model.js b/src/js/link/wv.link.model.js
index f4d14cc17..5b9f9904c 100644
--- a/src/js/link/wv.link.model.js
+++ b/src/js/link/wv.link.model.js
@@ -26,15 +26,10 @@ wv.link = wv.link || {};
wv.link.model = wv.link.model || function(config) {
var self = {};
+ var DEBUG_SHORTEN_LINK = "https://earthdata.nasa.gov/worldview?a=1&b=2";
var shortenCache = new Cache(10);
var mock = "";
- /**
- * URLs for localhost cannot be shorted via bit.ly. If localhost is
- * being used, use the following URL instead of the actual permalink.
- */
- var DEBUG_SHORTEN_URL = "https://earthdata.nasa.gov/labs/worldview";
-
/**
* The "permalink" from the registry returns values from components
* that should not actually be in the permalink. Only accept the
@@ -58,19 +53,11 @@ wv.link.model = wv.link.model || function(config) {
var init = function() {
if ( config && config.parameters && config.parameters.shorten ) {
- mock = config.parameters.shorten + "-";
+ mock = "-" + config.parameters.shorten;
}
};
- /**
- * Returns a query string that is the concatenated value of all components.
- *
- * @method get
- * @static
- * @return {string} The query string to use as a permalink with special
- * characters escaped.
- */
- self.get = function() {
+ self.queryString = function() {
var comps = REGISTRY.getComponents();
var parameters = {};
for ( var i = 0; i < comps.length; i++ ) {
@@ -86,8 +73,19 @@ wv.link.model = wv.link.model || function(config) {
}
}
}
- var queryString = wv.util.toQueryString(parameters,
- ENCODING_EXCEPTIONS);
+ return wv.util.toQueryString(parameters, ENCODING_EXCEPTIONS);
+ };
+
+ /**
+ * Returns a query string that is the concatenated value of all components.
+ *
+ * @method get
+ * @static
+ * @return {string} The query string to use as a permalink with special
+ * characters escaped.
+ */
+ self.get = function() {
+ var queryString = self.queryString();
var url = window.location.href;
var prefix = url.split("?")[0];
prefix = (prefix !== null && prefix !== undefined) ? prefix: url;
@@ -107,18 +105,17 @@ wv.link.model = wv.link.model || function(config) {
if ( !link ) {
link = self.get();
}
- if ( shortenCache.link ) {
- return $.Deferred().resolve(shortenCache.link);
+ if ( shortenCache[link] ) {
+ return $.Deferred().resolve(shortenCache[link]);
}
if ( /localhost/.test(link) ) {
- console.warn("Cannot shorten localhost. Using " +
- DEBUG_SHORTEN_URL);
- link = DEBUG_SHORTEN_URL;
+ link = DEBUG_SHORTEN_LINK;
+ console.warn("Cannot shorten localhost, using", link);
}
- var promise = $.getJSON("service/wv.link/" + mock + "shorten.cgi" +
- "?url=" + link);
+ var promise = $.getJSON("service/wv.link/shorten.cgi" + mock +
+ "?url=" + encodeURIComponent(link));
promise.done(function(result) {
- shortenCache.link = result;
+ shortenCache[link] = result;
});
return promise;
};
diff --git a/src/service/wv.link/error-shorten.cgi b/src/service/wv.link/error-shorten.cgi
deleted file mode 100755
index 270a7760a..000000000
--- a/src/service/wv.link/error-shorten.cgi
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/python
-
-#
-# NASA Worldview
-#
-# This code was originally developed at NASA/Goddard Space Flight Center for
-# the Earth Science Data and Information System (ESDIS) project.
-#
-# Copyright (C) 2013 - 2014 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-#
-
-import json
-
-result = {
- "status_code": 500,
- "status_txt": "Limit exceeded"
-}
-
-print "Content-type: application/json"
-print ""
-print json.dumps(result)
-
-
diff --git a/src/service/wv.link/shorten.cgi b/src/service/wv.link/shorten.cgi
index 8884e55fd..c4c3d8be6 100755
--- a/src/service/wv.link/shorten.cgi
+++ b/src/service/wv.link/shorten.cgi
@@ -16,7 +16,7 @@ from optparse import OptionParser
import os
import shutil
import sys
-from urllib2 import Request, urlopen, HTTPError
+from urllib2 import Request, urlopen, HTTPError, quote
endpoint = "http://api.bit.ly/v3/shorten"
login = "mikemcgann"
@@ -115,7 +115,7 @@ def process_request(options):
"?login=" + login,
"&apiKey=" + api_key,
"&format=json",
- "&longUrl=" + fields["url"].value])
+ "&longUrl=" + quote(fields["url"].value)])
if options.url:
print url
diff --git a/src/service/wv.link/shorten.cgi-error b/src/service/wv.link/shorten.cgi-error
new file mode 100644
index 000000000..46637bd74
--- /dev/null
+++ b/src/service/wv.link/shorten.cgi-error
@@ -0,0 +1 @@
+{"status_code": 500, "status_txt": "Limit exceeded"}
diff --git a/test/link/wv.link.model-test.js b/test/link/wv.link.model-test.js
index a39493fbb..5911fa49f 100644
--- a/test/link/wv.link.model-test.js
+++ b/test/link/wv.link.model-test.js
@@ -21,7 +21,7 @@ buster.testCase("wv.link.model", {
}));
var promise = link.shorten("foo");
promise.done(function(result) {
- buster.assert.calledWith(call, "wv/link/shorten.cgi?url=foo");
+ buster.assert.calledWith(call, "service/wv.link/shorten.cgi?url=foo");
buster.assert.equals(result.data.url, "shorten");
done();
});