Merge pull request #9 from zeke/master
Better detection of resource discovery URL components.
This commit is contained in:
@@ -159,7 +159,7 @@
|
|||||||
</script>
|
</script>
|
||||||
<div id='content_message'>
|
<div id='content_message'>
|
||||||
Enter the base URL of the API that you wish to explore, or try
|
Enter the base URL of the API that you wish to explore, or try
|
||||||
<a onclick="$('#input_baseUrl').val('http://petstore.swagger.wordnik.com/api'); apiSelectionController.showApi(); return false;" href="#">petstore.swagger.wordnik.com/api</a>
|
<a onclick="$('#input_baseUrl').val('http://petstore.swagger.wordnik.com/api/resources.json'); apiSelectionController.showApi(); return false;" href="#">petstore.swagger.wordnik.com/api/resources.json</a>
|
||||||
</div>
|
</div>
|
||||||
<p id='colophon' style='display:none'>
|
<p id='colophon' style='display:none'>
|
||||||
Sexy API documentation from
|
Sexy API documentation from
|
||||||
|
|||||||
@@ -2529,11 +2529,7 @@ arguments),this._chain)}});j.prototype.chain=function(){this._chain=!0;return th
|
|||||||
|
|
||||||
// adeed by ayush
|
// adeed by ayush
|
||||||
createAll: function(values){
|
createAll: function(values){
|
||||||
// debugger;
|
|
||||||
values = this.fromJSON(values);
|
values = this.fromJSON(values);
|
||||||
|
|
||||||
// debugger;
|
|
||||||
|
|
||||||
for (var i=0, il = values.length; i < il; i++) {
|
for (var i=0, il = values.length; i < il; i++) {
|
||||||
var record = values[i];
|
var record = values[i];
|
||||||
record.newRecord = false;
|
record.newRecord = false;
|
||||||
|
|||||||
@@ -233,11 +233,7 @@
|
|||||||
|
|
||||||
// adeed by ayush
|
// adeed by ayush
|
||||||
createAll: function(values){
|
createAll: function(values){
|
||||||
// debugger;
|
|
||||||
values = this.fromJSON(values);
|
values = this.fromJSON(values);
|
||||||
|
|
||||||
// debugger;
|
|
||||||
|
|
||||||
for (var i=0, il = values.length; i < il; i++) {
|
for (var i=0, il = values.length; i < il; i++) {
|
||||||
var record = values[i];
|
var record = values[i];
|
||||||
record.newRecord = false;
|
record.newRecord = false;
|
||||||
|
|||||||
@@ -11,17 +11,9 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
baseUrl = ("http://" + baseUrl);
|
baseUrl = ("http://" + baseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// baseUrl = baseUrl + "/resources.json";
|
|
||||||
|
|
||||||
// log("using base url " + baseUrl);
|
|
||||||
var apiHost = baseUrl.substr(0, baseUrl.lastIndexOf("/"));
|
var apiHost = baseUrl.substr(0, baseUrl.lastIndexOf("/"));
|
||||||
// debugger
|
var discoParts = baseUrl.split("/");
|
||||||
// var rootResourcesApiName = baseUrl.substr(baseUrl.lastIndexOf("/") + 1, (baseUrl.lastIndexOf(".") - baseUrl.lastIndexOf("/") - 1));
|
var rootResourcesApiName = discoParts[discoParts.length-1];
|
||||||
|
|
||||||
// assuming root swagger is resources
|
|
||||||
var rootResourcesApiName = "resources";
|
|
||||||
if (baseUrl.indexOf(".json") > -1) rootResourcesApiName += ".json";
|
|
||||||
|
|
||||||
var formatString = ".{format}";
|
var formatString = ".{format}";
|
||||||
var statusListener = statusCallback;
|
var statusListener = statusCallback;
|
||||||
var apiKey = _apiKey;
|
var apiKey = _apiKey;
|
||||||
@@ -79,7 +71,7 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
addApis: function(apiObjects) {
|
addApis: function(apiObjects) {
|
||||||
log("apiObjects: %o", apiObjects);
|
// log("apiObjects: %o", apiObjects);
|
||||||
this.apiList.createAll(apiObjects);
|
this.apiList.createAll(apiObjects);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -402,10 +394,9 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
var controller = this;
|
var controller = this;
|
||||||
updateStatus("Fetching " + apiResource.name + "...");
|
updateStatus("Fetching " + apiResource.name + "...");
|
||||||
var resourceUrl = apiHost + apiResource.path_json + apiKeySuffix;
|
var resourceUrl = apiHost + apiResource.path_json + apiKeySuffix;
|
||||||
log("resourceUrl: %o", resourceUrl);
|
// log("resourceUrl: %o", resourceUrl);
|
||||||
$.getJSON(resourceUrl,
|
$.getJSON(resourceUrl,
|
||||||
function(response) {
|
function(response) {
|
||||||
log(response);
|
|
||||||
controller.loadResources(response, apiResource);
|
controller.loadResources(response, apiResource);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -432,7 +423,7 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
updateStatus();
|
updateStatus();
|
||||||
} finally {
|
} finally {
|
||||||
if (this.countLoaded == ApiResource.count()) {
|
if (this.countLoaded == ApiResource.count()) {
|
||||||
log("all models/api loaded");
|
// log("all models/api loaded");
|
||||||
ApiResource.trigger("refresh");
|
ApiResource.trigger("refresh");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
jQuery(function($) {
|
jQuery(function($) {
|
||||||
|
|
||||||
// this.baseUrl = "http://swagr.api.wordnik.com/v4";
|
// this.baseUrl = "http://petstore.swagger.wordnik.com/api/resources.json";
|
||||||
|
|
||||||
// this.baseUrl = "http://petstore.swagger.wordnik.com/api";
|
|
||||||
// this.apiKey = "special-key";
|
// this.apiKey = "special-key";
|
||||||
|
|
||||||
var ApiSelectionController = Spine.Controller.create({
|
var ApiSelectionController = Spine.Controller.create({
|
||||||
@@ -37,15 +35,17 @@ jQuery(function($) {
|
|||||||
|
|
||||||
handleEnter: function(){
|
handleEnter: function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
var submit = function() { self.showApi() }
|
var submit = function() {
|
||||||
|
self.showApi();
|
||||||
|
};
|
||||||
$('#input_baseUrl').keydown(function(e) {
|
$('#input_baseUrl').keydown(function(e) {
|
||||||
if(e.which != 13) return;
|
if(e.which != 13) return;
|
||||||
submit();
|
submit();
|
||||||
})
|
});
|
||||||
$('#input_apiKey').keydown(function(e) {
|
$('#input_apiKey').keydown(function(e) {
|
||||||
if(e.which != 13) return;
|
if(e.which != 13) return;
|
||||||
submit();
|
submit();
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
adaptToScale: function() {
|
adaptToScale: function() {
|
||||||
@@ -145,7 +145,6 @@ jQuery(function($) {
|
|||||||
// Create convenience references to Spine models
|
// Create convenience references to Spine models
|
||||||
this.ApiResource = swaggerService.ApiResource();
|
this.ApiResource = swaggerService.ApiResource();
|
||||||
|
|
||||||
debugger;
|
|
||||||
this.ApiResource.bind("refresh", this.addAll);
|
this.ApiResource.bind("refresh", this.addAll);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -233,11 +233,7 @@
|
|||||||
|
|
||||||
// adeed by ayush
|
// adeed by ayush
|
||||||
createAll: function(values){
|
createAll: function(values){
|
||||||
// debugger;
|
|
||||||
values = this.fromJSON(values);
|
values = this.fromJSON(values);
|
||||||
|
|
||||||
// debugger;
|
|
||||||
|
|
||||||
for (var i=0, il = values.length; i < il; i++) {
|
for (var i=0, il = values.length; i < il; i++) {
|
||||||
var record = values[i];
|
var record = values[i];
|
||||||
record.newRecord = false;
|
record.newRecord = false;
|
||||||
|
|||||||
@@ -11,17 +11,9 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
baseUrl = ("http://" + baseUrl);
|
baseUrl = ("http://" + baseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// baseUrl = baseUrl + "/resources.json";
|
|
||||||
|
|
||||||
// log("using base url " + baseUrl);
|
|
||||||
var apiHost = baseUrl.substr(0, baseUrl.lastIndexOf("/"));
|
var apiHost = baseUrl.substr(0, baseUrl.lastIndexOf("/"));
|
||||||
// debugger
|
var discoParts = baseUrl.split("/");
|
||||||
// var rootResourcesApiName = baseUrl.substr(baseUrl.lastIndexOf("/") + 1, (baseUrl.lastIndexOf(".") - baseUrl.lastIndexOf("/") - 1));
|
var rootResourcesApiName = discoParts[discoParts.length-1];
|
||||||
|
|
||||||
// assuming root swagger is resources
|
|
||||||
var rootResourcesApiName = "resources";
|
|
||||||
if (baseUrl.indexOf(".json") > -1) rootResourcesApiName += ".json";
|
|
||||||
|
|
||||||
var formatString = ".{format}";
|
var formatString = ".{format}";
|
||||||
var statusListener = statusCallback;
|
var statusListener = statusCallback;
|
||||||
var apiKey = _apiKey;
|
var apiKey = _apiKey;
|
||||||
@@ -79,7 +71,7 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
addApis: function(apiObjects) {
|
addApis: function(apiObjects) {
|
||||||
log("apiObjects: %o", apiObjects);
|
// log("apiObjects: %o", apiObjects);
|
||||||
this.apiList.createAll(apiObjects);
|
this.apiList.createAll(apiObjects);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -402,10 +394,9 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
var controller = this;
|
var controller = this;
|
||||||
updateStatus("Fetching " + apiResource.name + "...");
|
updateStatus("Fetching " + apiResource.name + "...");
|
||||||
var resourceUrl = apiHost + apiResource.path_json + apiKeySuffix;
|
var resourceUrl = apiHost + apiResource.path_json + apiKeySuffix;
|
||||||
log("resourceUrl: %o", resourceUrl);
|
// log("resourceUrl: %o", resourceUrl);
|
||||||
$.getJSON(resourceUrl,
|
$.getJSON(resourceUrl,
|
||||||
function(response) {
|
function(response) {
|
||||||
log(response);
|
|
||||||
controller.loadResources(response, apiResource);
|
controller.loadResources(response, apiResource);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -432,7 +423,7 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
|
|||||||
updateStatus();
|
updateStatus();
|
||||||
} finally {
|
} finally {
|
||||||
if (this.countLoaded == ApiResource.count()) {
|
if (this.countLoaded == ApiResource.count()) {
|
||||||
log("all models/api loaded");
|
// log("all models/api loaded");
|
||||||
ApiResource.trigger("refresh");
|
ApiResource.trigger("refresh");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
jQuery(function($) {
|
jQuery(function($) {
|
||||||
|
|
||||||
// this.baseUrl = "http://swagr.api.wordnik.com/v4";
|
// this.baseUrl = "http://petstore.swagger.wordnik.com/api/resources.json";
|
||||||
|
|
||||||
// this.baseUrl = "http://petstore.swagger.wordnik.com/api";
|
|
||||||
// this.apiKey = "special-key";
|
// this.apiKey = "special-key";
|
||||||
|
|
||||||
var ApiSelectionController = Spine.Controller.create({
|
var ApiSelectionController = Spine.Controller.create({
|
||||||
@@ -37,15 +35,17 @@ jQuery(function($) {
|
|||||||
|
|
||||||
handleEnter: function(){
|
handleEnter: function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
var submit = function() { self.showApi() }
|
var submit = function() {
|
||||||
|
self.showApi();
|
||||||
|
};
|
||||||
$('#input_baseUrl').keydown(function(e) {
|
$('#input_baseUrl').keydown(function(e) {
|
||||||
if(e.which != 13) return;
|
if(e.which != 13) return;
|
||||||
submit();
|
submit();
|
||||||
})
|
});
|
||||||
$('#input_apiKey').keydown(function(e) {
|
$('#input_apiKey').keydown(function(e) {
|
||||||
if(e.which != 13) return;
|
if(e.which != 13) return;
|
||||||
submit();
|
submit();
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
adaptToScale: function() {
|
adaptToScale: function() {
|
||||||
@@ -145,7 +145,6 @@ jQuery(function($) {
|
|||||||
// Create convenience references to Spine models
|
// Create convenience references to Spine models
|
||||||
this.ApiResource = swaggerService.ApiResource();
|
this.ApiResource = swaggerService.ApiResource();
|
||||||
|
|
||||||
debugger;
|
|
||||||
this.ApiResource.bind("refresh", this.addAll);
|
this.ApiResource.bind("refresh", this.addAll);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#content_message
|
#content_message
|
||||||
Enter the base URL of the API that you wish to explore, or try
|
Enter the base URL of the API that you wish to explore, or try
|
||||||
= link_to("petstore.swagger.wordnik.com/api", "#", :onclick => "$('#input_baseUrl').val('http://petstore.swagger.wordnik.com/api'); apiSelectionController.showApi(); return false;")
|
= link_to("petstore.swagger.wordnik.com/api/resources.json", "#", :onclick => "$('#input_baseUrl').val('http://petstore.swagger.wordnik.com/api/resources.json'); apiSelectionController.showApi(); return false;")
|
||||||
|
|
||||||
%p#colophon{:style => 'display:none'}
|
%p#colophon{:style => 'display:none'}
|
||||||
Sexy API documentation from
|
Sexy API documentation from
|
||||||
|
|||||||
Reference in New Issue
Block a user