caching lase used baseUrl and key in local storage
This commit is contained in:
@@ -46,6 +46,8 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
// make some models public
|
// make some models public
|
||||||
this.ApiResource = function() {return ApiResource;};
|
this.ApiResource = function() {return ApiResource;};
|
||||||
|
|
||||||
|
this.apiHost = function() {return apiHost;};
|
||||||
|
|
||||||
// Model: ApiResource
|
// Model: ApiResource
|
||||||
var ApiResource = Spine.Model.setup("ApiResource", ["name", "baseUrl", "path", "path_json", "path_xml", "description", "apiLists", "modelList"]);
|
var ApiResource = Spine.Model.setup("ApiResource", ["name", "baseUrl", "path", "path_json", "path_xml", "description", "apiLists", "modelList"]);
|
||||||
ApiResource.include({
|
ApiResource.include({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
jQuery(function($) {
|
jQuery(function($) {
|
||||||
|
|
||||||
this.baseUrl = "http://swagr.api.wordnik.com/v4/list.json";
|
// this.baseUrl = "http://swagr.api.wordnik.com/v4/list.json";
|
||||||
// this.apiKey = "my-api-key";
|
// this.apiKey = "my-api-key";
|
||||||
|
|
||||||
var ApiSelectionController = Spine.Controller.create({
|
var ApiSelectionController = Spine.Controller.create({
|
||||||
@@ -10,23 +10,31 @@ jQuery(function($) {
|
|||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
if (this.supportsLocalStorage()) {
|
if (this.supportsLocalStorage()) {
|
||||||
var baseUrls = localStorage.getItem("com.wordnik.swagger.ui.baseUrls");
|
var baseUrl = localStorage.getItem("com.wordnik.swagger.ui.baseUrl");
|
||||||
if (baseUrls && jQuery.trim(baseUrls).length > 0) {
|
var apiKey = localStorage.getItem("com.wordnik.swagger.ui.apiKey");
|
||||||
this.baseUrlList = baseUrls.split(",");
|
|
||||||
}
|
if(baseUrl && baseUrl.length > 0)
|
||||||
|
$("#input_baseUrl").val(baseUrl);
|
||||||
|
|
||||||
|
if(apiKey && apiKey.length > 0)
|
||||||
|
$("#input_apiKey").val(apiKey);
|
||||||
|
|
||||||
|
|
||||||
|
// if (baseUrls && jQuery.trim(baseUrls).length > 0) {
|
||||||
|
// this.baseUrlList = baseUrls.split(",");
|
||||||
|
// }
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log("local storage not supported, user will need to specifiy the api url")
|
log("local storage not supported, user will need to specifiy the api url")
|
||||||
}
|
}
|
||||||
|
|
||||||
this.render();
|
|
||||||
|
|
||||||
$("#button_explore").click(this.showApi);
|
$("#button_explore").click(this.showApi);
|
||||||
},
|
},
|
||||||
|
|
||||||
slapOn: function() {
|
slapOn: function() {
|
||||||
messageController.showMessage("Please enter a base url for the api that you wish to explore.");
|
messageController.showMessage("Please enter a base url for the api that you wish to explore.");
|
||||||
$("#resources_container").hide();
|
$("#resources_container").hide();
|
||||||
|
this.showApi();
|
||||||
},
|
},
|
||||||
|
|
||||||
supportsLocalStorage: function() {
|
supportsLocalStorage: function() {
|
||||||
@@ -37,10 +45,6 @@ jQuery(function($) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
|
||||||
// $("#baseUrlSelector").chosen();
|
|
||||||
},
|
|
||||||
|
|
||||||
showApi: function() {
|
showApi: function() {
|
||||||
var baseUrl = jQuery.trim($("#input_baseUrl").val());
|
var baseUrl = jQuery.trim($("#input_baseUrl").val());
|
||||||
var apiKey = jQuery.trim($("#input_apiKey").val());
|
var apiKey = jQuery.trim($("#input_apiKey").val());
|
||||||
@@ -48,6 +52,11 @@ jQuery(function($) {
|
|||||||
$("#input_baseUrl").wiggle();
|
$("#input_baseUrl").wiggle();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
if(this.supportsLocalStorage()) {
|
||||||
|
localStorage.setItem("com.wordnik.swagger.ui.apiKey", apiKey);
|
||||||
|
localStorage.setItem("com.wordnik.swagger.ui.baseUrl", baseUrl);
|
||||||
|
|
||||||
|
}
|
||||||
var resourceListController = ResourceListController.init({baseUrl: baseUrl, apiKey: apiKey})
|
var resourceListController = ResourceListController.init({baseUrl: baseUrl, apiKey: apiKey})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,13 +101,13 @@ jQuery(function($) {
|
|||||||
$("#resources").html("");
|
$("#resources").html("");
|
||||||
|
|
||||||
// create and initialize SwaggerService
|
// create and initialize SwaggerService
|
||||||
$("#api_host_url").html(this.baseUrl);
|
|
||||||
var swaggerService = new SwaggerService(this.baseUrl, this.apiKey, function(msg) {
|
var swaggerService = new SwaggerService(this.baseUrl, this.apiKey, function(msg) {
|
||||||
if (msg)
|
if (msg)
|
||||||
messageController.showMessage(msg);
|
messageController.showMessage(msg);
|
||||||
else
|
else
|
||||||
messageController.showMessage("Rendering page...");
|
messageController.showMessage("Rendering page...");
|
||||||
});
|
});
|
||||||
|
$("#api_host_url").html(swaggerService.apiHost());
|
||||||
swaggerService.init();
|
swaggerService.init();
|
||||||
|
|
||||||
// Create convenience references to Spine models
|
// Create convenience references to Spine models
|
||||||
|
|||||||
Reference in New Issue
Block a user