parameterized root resources api name and host url. also removed list resource from model

This commit is contained in:
Ayush Gupta
2011-07-27 12:31:35 -07:00
parent 9443819afd
commit 9e874d65ab
3 changed files with 12 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
jQuery(function($) { jQuery(function($) {
// create and initialize SwaggerService // create and initialize SwaggerService
var swaggerService = new SwaggerService(); var swaggerService = new SwaggerService("http://swagr.api.wordnik.com/v4");
swaggerService.init(); swaggerService.init();
// Create convenience references to Spine models // Create convenience references to Spine models

View File

@@ -1,7 +1,11 @@
function SwaggerService(hostUrl) { function SwaggerService(hostUrl, rootResourcesApi) {
if(!hostUrl)
throw new Error("hostUrl must be passed while creating SwaggerService");
// constants // constants
var apiHost = hostUrl || "http://swagr.api.wordnik.com/v4"; var apiHost = hostUrl;
var rootResourcesApiName = rootResourcesApi || "list";
// utility functions // utility functions
function log(m) { function log(m) {
@@ -253,9 +257,12 @@ function SwaggerService(hostUrl) {
fetchEndpoints: function() { fetchEndpoints: function() {
var controller = this; var controller = this;
$.getJSON(apiHost + "/list.json", function(response) { $.getJSON(apiHost + "/" + rootResourcesApiName + ".json", function(response) {
//log(response); //log(response);
ApiResource.createAll(response.apis); ApiResource.createAll(response.apis);
ApiResource.findByAttribute("name", rootResourcesApiName).destroy();
controller.fetchResources(); controller.fetchResources();
}); });
}, },

View File

@@ -1,6 +1,6 @@
jQuery(function($) { jQuery(function($) {
// create and initialize SwaggerService // create and initialize SwaggerService
var swaggerService = new SwaggerService(); var swaggerService = new SwaggerService("http://swagr.api.wordnik.com/v4");
swaggerService.init(); swaggerService.init();
// Create convenience references to Spine models // Create convenience references to Spine models