No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

749 líneas
26 KiB

  1. // Generated by CoffeeScript 1.4.0
  2. (function() {
  3. var SwaggerApi, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
  4. __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  5. SwaggerApi = (function() {
  6. SwaggerApi.prototype.discoveryUrl = "http://api.wordnik.com/v4/resources.json";
  7. SwaggerApi.prototype.debug = false;
  8. SwaggerApi.prototype.api_key = null;
  9. SwaggerApi.prototype.basePath = null;
  10. function SwaggerApi(options) {
  11. if (options == null) {
  12. options = {};
  13. }
  14. if (options.discoveryUrl != null) {
  15. this.discoveryUrl = options.discoveryUrl;
  16. }
  17. if (options.debug != null) {
  18. this.debug = options.debug;
  19. }
  20. this.apiKeyName = options.apiKeyName != null ? options.apiKeyName : 'api_key';
  21. if (options.apiKey != null) {
  22. this.api_key = options.apiKey;
  23. }
  24. if (options.api_key != null) {
  25. this.api_key = options.api_key;
  26. }
  27. if (options.verbose != null) {
  28. this.verbose = options.verbose;
  29. }
  30. this.supportHeaderParams = options.supportHeaderParams != null ? options.supportHeaderParams : false;
  31. this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
  32. if (options.success != null) {
  33. this.success = options.success;
  34. }
  35. this.failure = options.failure != null ? options.failure : function() {};
  36. this.progress = options.progress != null ? options.progress : function() {};
  37. this.headers = options.headers != null ? options.headers : {};
  38. this.booleanValues = options.booleanValues != null ? options.booleanValues : new Array('true', 'false');
  39. this.discoveryUrl = this.suffixApiKey(this.discoveryUrl);
  40. if (options.success != null) {
  41. this.build();
  42. }
  43. }
  44. SwaggerApi.prototype.build = function() {
  45. var _this = this;
  46. this.progress('fetching resource list: ' + this.discoveryUrl);
  47. return jQuery.getJSON(this.discoveryUrl, function(response) {
  48. var res, resource, _i, _j, _len, _len1, _ref, _ref1;
  49. if (response.apiVersion != null) {
  50. _this.apiVersion = response.apiVersion;
  51. }
  52. if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
  53. _this.basePath = response.basePath;
  54. if (_this.basePath.match(/^HTTP/i) == null) {
  55. _this.fail("discoveryUrl basePath must be a URL.");
  56. }
  57. _this.basePath = _this.basePath.replace(/\/$/, '');
  58. } else {
  59. _this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('/'));
  60. log('derived basepath from discoveryUrl as ' + _this.basePath);
  61. }
  62. _this.resources = {};
  63. _this.resourcesArray = [];
  64. if (response.resourcePath != null) {
  65. _this.resourcePath = response.resourcePath;
  66. res = null;
  67. _ref = response.apis;
  68. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  69. resource = _ref[_i];
  70. if (res === null) {
  71. res = new SwaggerResource(resource, _this);
  72. } else {
  73. res.addOperations(resource.path, resource.operations);
  74. }
  75. }
  76. if (res != null) {
  77. _this.resources[res.name] = res;
  78. _this.resourcesArray.push(res);
  79. res.ready = true;
  80. _this.selfReflect();
  81. }
  82. } else {
  83. _ref1 = response.apis;
  84. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  85. resource = _ref1[_j];
  86. res = new SwaggerResource(resource, _this);
  87. _this.resources[res.name] = res;
  88. _this.resourcesArray.push(res);
  89. }
  90. }
  91. return _this;
  92. }).error(function(error) {
  93. return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
  94. });
  95. };
  96. SwaggerApi.prototype.selfReflect = function() {
  97. var resource, resource_name, _ref;
  98. if (this.resources == null) {
  99. return false;
  100. }
  101. _ref = this.resources;
  102. for (resource_name in _ref) {
  103. resource = _ref[resource_name];
  104. if (resource.ready == null) {
  105. return false;
  106. }
  107. }
  108. this.setConsolidatedModels();
  109. this.ready = true;
  110. if (this.success != null) {
  111. return this.success();
  112. }
  113. };
  114. SwaggerApi.prototype.fail = function(message) {
  115. this.failure(message);
  116. throw message;
  117. };
  118. SwaggerApi.prototype.setConsolidatedModels = function() {
  119. var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
  120. this.modelsArray = [];
  121. this.models = {};
  122. _ref = this.resources;
  123. for (resource_name in _ref) {
  124. resource = _ref[resource_name];
  125. for (modelName in resource.models) {
  126. if (!(this.models[modelName] != null)) {
  127. this.models[modelName] = resource.models[modelName];
  128. this.modelsArray.push(resource.models[modelName]);
  129. }
  130. }
  131. }
  132. _ref1 = this.modelsArray;
  133. _results = [];
  134. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  135. model = _ref1[_i];
  136. _results.push(model.setReferencedModels(this.models));
  137. }
  138. return _results;
  139. };
  140. SwaggerApi.prototype.suffixApiKey = function(url) {
  141. var sep;
  142. if ((this.api_key != null) && jQuery.trim(this.api_key).length > 0 && (url != null)) {
  143. sep = url.indexOf('?') > 0 ? '&' : '?';
  144. return url + sep + this.apiKeyName + '=' + this.api_key;
  145. } else {
  146. return url;
  147. }
  148. };
  149. SwaggerApi.prototype.help = function() {
  150. var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
  151. _ref = this.resources;
  152. for (resource_name in _ref) {
  153. resource = _ref[resource_name];
  154. console.log(resource_name);
  155. _ref1 = resource.operations;
  156. for (operation_name in _ref1) {
  157. operation = _ref1[operation_name];
  158. console.log(" " + operation.nickname);
  159. _ref2 = operation.parameters;
  160. for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
  161. parameter = _ref2[_i];
  162. console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  163. }
  164. }
  165. }
  166. return this;
  167. };
  168. return SwaggerApi;
  169. })();
  170. SwaggerResource = (function() {
  171. function SwaggerResource(resourceObj, api) {
  172. var parts,
  173. _this = this;
  174. this.api = api;
  175. this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
  176. this.description = resourceObj.description;
  177. parts = this.path.split("/");
  178. this.name = parts[parts.length - 1].replace('.{format}', '');
  179. this.basePath = this.api.basePath;
  180. this.operations = {};
  181. this.operationsArray = [];
  182. this.modelsArray = [];
  183. this.models = {};
  184. if ((resourceObj.operations != null) && (this.api.resourcePath != null)) {
  185. this.api.progress('reading resource ' + this.name + ' models and operations');
  186. this.addModels(resourceObj.models);
  187. this.addOperations(resourceObj.path, resourceObj.operations);
  188. this.api[this.name] = this;
  189. } else {
  190. if (this.path == null) {
  191. this.api.fail("SwaggerResources must have a path.");
  192. }
  193. this.url = this.api.suffixApiKey(this.api.basePath + this.path.replace('{format}', 'json'));
  194. this.api.progress('fetching resource ' + this.name + ': ' + this.url);
  195. jQuery.getJSON(this.url, function(response) {
  196. var endpoint, _i, _len, _ref;
  197. if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
  198. _this.basePath = response.basePath;
  199. _this.basePath = _this.basePath.replace(/\/$/, '');
  200. }
  201. _this.addModels(response.models);
  202. if (response.apis) {
  203. _ref = response.apis;
  204. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  205. endpoint = _ref[_i];
  206. _this.addOperations(endpoint.path, endpoint.operations);
  207. }
  208. }
  209. _this.api[_this.name] = _this;
  210. _this.ready = true;
  211. return _this.api.selfReflect();
  212. }).error(function(error) {
  213. return _this.api.fail(error.status + ' : ' + error.statusText + ' ' + _this.url);
  214. });
  215. }
  216. }
  217. SwaggerResource.prototype.addModels = function(models) {
  218. var model, modelName, swaggerModel, _i, _len, _ref, _results;
  219. if (models != null) {
  220. for (modelName in models) {
  221. if (!(this.models[modelName] != null)) {
  222. swaggerModel = new SwaggerModel(modelName, models[modelName]);
  223. this.modelsArray.push(swaggerModel);
  224. this.models[modelName] = swaggerModel;
  225. }
  226. }
  227. _ref = this.modelsArray;
  228. _results = [];
  229. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  230. model = _ref[_i];
  231. _results.push(model.setReferencedModels(this.models));
  232. }
  233. return _results;
  234. }
  235. };
  236. SwaggerResource.prototype.addOperations = function(resource_path, ops) {
  237. var o, op, _i, _len, _results;
  238. if (ops) {
  239. _results = [];
  240. for (_i = 0, _len = ops.length; _i < _len; _i++) {
  241. o = ops[_i];
  242. op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, o.errorResponses, this, o.supportedContentTypes);
  243. this.operations[op.nickname] = op;
  244. _results.push(this.operationsArray.push(op));
  245. }
  246. return _results;
  247. }
  248. };
  249. SwaggerResource.prototype.help = function() {
  250. var operation, operation_name, parameter, _i, _len, _ref, _ref1;
  251. _ref = this.operations;
  252. for (operation_name in _ref) {
  253. operation = _ref[operation_name];
  254. console.log(" " + operation.nickname);
  255. _ref1 = operation.parameters;
  256. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  257. parameter = _ref1[_i];
  258. console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  259. }
  260. }
  261. return this;
  262. };
  263. return SwaggerResource;
  264. })();
  265. SwaggerModel = (function() {
  266. function SwaggerModel(modelName, obj) {
  267. var propertyName;
  268. this.name = obj.id != null ? obj.id : modelName;
  269. this.properties = [];
  270. for (propertyName in obj.properties) {
  271. this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName]));
  272. }
  273. }
  274. SwaggerModel.prototype.setReferencedModels = function(allModels) {
  275. var prop, _i, _len, _ref, _results;
  276. _ref = this.properties;
  277. _results = [];
  278. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  279. prop = _ref[_i];
  280. if (allModels[prop.dataType] != null) {
  281. _results.push(prop.refModel = allModels[prop.dataType]);
  282. } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
  283. _results.push(prop.refModel = allModels[prop.refDataType]);
  284. } else {
  285. _results.push(void 0);
  286. }
  287. }
  288. return _results;
  289. };
  290. SwaggerModel.prototype.getMockSignature = function(prefix, modelToIgnore) {
  291. var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1;
  292. propertiesStr = [];
  293. _ref = this.properties;
  294. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  295. prop = _ref[_i];
  296. propertiesStr.push(prop.toString());
  297. }
  298. strong = '<span style="font-weight: bold; color: #000; font-size: 1.0em">';
  299. stronger = '<span style="font-weight: bold; color: #000; font-size: 1.1em">';
  300. strongClose = '</span>';
  301. classOpen = strong + 'class ' + this.name + '(' + strongClose;
  302. classClose = strong + ')' + strongClose;
  303. returnVal = classOpen + '<span>' + propertiesStr.join('</span>, <span>') + '</span>' + classClose;
  304. if (prefix != null) {
  305. returnVal = stronger + prefix + strongClose + '<br/>' + returnVal;
  306. }
  307. _ref1 = this.properties;
  308. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  309. prop = _ref1[_j];
  310. if ((prop.refModel != null) && (!(prop.refModel === modelToIgnore))) {
  311. returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(void 0, this));
  312. }
  313. }
  314. return returnVal;
  315. };
  316. SwaggerModel.prototype.createJSONSample = function(modelToIgnore) {
  317. var prop, result, _i, _len, _ref;
  318. result = {};
  319. _ref = this.properties;
  320. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  321. prop = _ref[_i];
  322. result[prop.name] = prop.getSampleValue(modelToIgnore);
  323. }
  324. return result;
  325. };
  326. return SwaggerModel;
  327. })();
  328. SwaggerModelProperty = (function() {
  329. function SwaggerModelProperty(name, obj) {
  330. this.name = name;
  331. this.dataType = obj.type;
  332. this.isArray = this.dataType.toLowerCase() === 'array';
  333. this.descr = obj.description;
  334. if (obj.items != null) {
  335. if (obj.items.type != null) {
  336. this.refDataType = obj.items.type;
  337. }
  338. if (obj.items.$ref != null) {
  339. this.refDataType = obj.items.$ref;
  340. }
  341. }
  342. this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType;
  343. if (obj.allowableValues != null) {
  344. this.valueType = obj.allowableValues.valueType;
  345. this.values = obj.allowableValues.values;
  346. if (this.values != null) {
  347. this.valuesString = "'" + this.values.join("' or '") + "'";
  348. }
  349. }
  350. }
  351. SwaggerModelProperty.prototype.getSampleValue = function(modelToIgnore) {
  352. var result;
  353. if ((this.refModel != null) && (!(this.refModel === modelToIgnore))) {
  354. result = this.refModel.createJSONSample(this.refModel);
  355. } else {
  356. if (this.isArray) {
  357. result = this.refDataType;
  358. } else {
  359. result = this.dataType;
  360. }
  361. }
  362. if (this.isArray) {
  363. return [result];
  364. } else {
  365. return result;
  366. }
  367. };
  368. SwaggerModelProperty.prototype.toString = function() {
  369. var str;
  370. str = this.name + ': ' + this.dataTypeWithRef;
  371. if (this.values != null) {
  372. str += " = ['" + this.values.join("' or '") + "']";
  373. }
  374. if (this.descr != null) {
  375. str += ' {' + this.descr + '}';
  376. }
  377. return str;
  378. };
  379. return SwaggerModelProperty;
  380. })();
  381. SwaggerOperation = (function() {
  382. function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource, supportedContentTypes) {
  383. var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2,
  384. _this = this;
  385. this.nickname = nickname;
  386. this.path = path;
  387. this.httpMethod = httpMethod;
  388. this.parameters = parameters != null ? parameters : [];
  389. this.summary = summary;
  390. this.notes = notes;
  391. this.responseClass = responseClass;
  392. this.errorResponses = errorResponses;
  393. this.resource = resource;
  394. this.supportedContentTypes = supportedContentTypes;
  395. this["do"] = __bind(this["do"], this);
  396. if (this.nickname == null) {
  397. this.resource.api.fail("SwaggerOperations must have a nickname.");
  398. }
  399. if (this.path == null) {
  400. this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
  401. }
  402. if (this.httpMethod == null) {
  403. this.resource.api.fail("SwaggerOperation " + nickname + " is missing httpMethod.");
  404. }
  405. this.path = this.path.replace('{format}', 'json');
  406. this.httpMethod = this.httpMethod.toLowerCase();
  407. this.isGetMethod = this.httpMethod === "get";
  408. this.resourceName = this.resource.name;
  409. if (((_ref = this.responseClass) != null ? _ref.toLowerCase() : void 0) === 'void') {
  410. this.responseClass = void 0;
  411. }
  412. if (this.responseClass != null) {
  413. this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
  414. this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
  415. }
  416. this.errorResponses = this.errorResponses || [];
  417. _ref1 = this.parameters;
  418. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  419. parameter = _ref1[_i];
  420. parameter.name = parameter.name || parameter.dataType;
  421. if (parameter.dataType.toLowerCase() === 'boolean') {
  422. parameter.allowableValues = {};
  423. parameter.allowableValues.values = this.resource.api.booleanValues;
  424. }
  425. parameter.signature = this.getSignature(parameter.dataType, this.resource.models);
  426. parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models);
  427. if (parameter.allowableValues != null) {
  428. if (parameter.allowableValues.valueType === "RANGE") {
  429. parameter.isRange = true;
  430. } else {
  431. parameter.isList = true;
  432. }
  433. if (parameter.allowableValues.values != null) {
  434. parameter.allowableValues.descriptiveValues = [];
  435. _ref2 = parameter.allowableValues.values;
  436. for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
  437. v = _ref2[_j];
  438. if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
  439. parameter.allowableValues.descriptiveValues.push({
  440. value: v,
  441. isDefault: true
  442. });
  443. } else {
  444. parameter.allowableValues.descriptiveValues.push({
  445. value: v,
  446. isDefault: false
  447. });
  448. }
  449. }
  450. }
  451. }
  452. }
  453. this.resource[this.nickname] = function(args, callback, error) {
  454. return _this["do"](args, callback, error);
  455. };
  456. }
  457. SwaggerOperation.prototype.isListType = function(dataType) {
  458. if (dataType.indexOf('[') >= 0) {
  459. return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']'));
  460. } else {
  461. return void 0;
  462. }
  463. };
  464. SwaggerOperation.prototype.getSignature = function(dataType, models) {
  465. var isPrimitive, listType;
  466. listType = this.isListType(dataType);
  467. isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
  468. if (isPrimitive) {
  469. return dataType;
  470. } else {
  471. if (listType != null) {
  472. return models[listType].getMockSignature(dataType);
  473. } else {
  474. return models[dataType].getMockSignature(dataType);
  475. }
  476. }
  477. };
  478. SwaggerOperation.prototype.getSampleJSON = function(dataType, models) {
  479. var isPrimitive, listType, val;
  480. listType = this.isListType(dataType);
  481. isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
  482. val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample());
  483. if (val) {
  484. val = listType ? [val] : val;
  485. return JSON.stringify(val, null, 2);
  486. }
  487. };
  488. SwaggerOperation.prototype["do"] = function(args, callback, error) {
  489. var body, headers;
  490. if (args == null) {
  491. args = {};
  492. }
  493. if ((typeof args) === "function") {
  494. error = callback;
  495. callback = args;
  496. args = {};
  497. }
  498. if (error == null) {
  499. error = function(xhr, textStatus, error) {
  500. return console.log(xhr, textStatus, error);
  501. };
  502. }
  503. if (callback == null) {
  504. callback = function(data) {
  505. return console.log(data);
  506. };
  507. }
  508. if (args.headers != null) {
  509. headers = args.headers;
  510. delete args.headers;
  511. }
  512. if (args.body != null) {
  513. body = args.body;
  514. delete args.body;
  515. }
  516. return new SwaggerRequest(this.httpMethod, this.urlify(args), headers, body, callback, error, this);
  517. };
  518. SwaggerOperation.prototype.pathJson = function() {
  519. return this.path.replace("{format}", "json");
  520. };
  521. SwaggerOperation.prototype.pathXml = function() {
  522. return this.path.replace("{format}", "xml");
  523. };
  524. SwaggerOperation.prototype.urlify = function(args, includeApiKey) {
  525. var param, queryParams, reg, url, _i, _len, _ref;
  526. if (includeApiKey == null) {
  527. includeApiKey = true;
  528. }
  529. url = this.resource.basePath + this.pathJson();
  530. _ref = this.parameters;
  531. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  532. param = _ref[_i];
  533. if (param.paramType === 'path') {
  534. if (args[param.name]) {
  535. reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
  536. url = url.replace(reg, encodeURIComponent(args[param.name]));
  537. delete args[param.name];
  538. } else {
  539. throw "" + param.name + " is a required path param.";
  540. }
  541. }
  542. }
  543. if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
  544. args[this.apiKeyName] = this.resource.api.api_key;
  545. }
  546. if (this.supportHeaderParams()) {
  547. queryParams = jQuery.param(this.getQueryParams(args, includeApiKey));
  548. } else {
  549. queryParams = jQuery.param(this.getQueryAndHeaderParams(args, includeApiKey));
  550. }
  551. if ((queryParams != null) && queryParams.length > 0) {
  552. url += "?" + queryParams;
  553. }
  554. return url;
  555. };
  556. SwaggerOperation.prototype.supportHeaderParams = function() {
  557. return this.resource.api.supportHeaderParams;
  558. };
  559. SwaggerOperation.prototype.supportedSubmitMethods = function() {
  560. return this.resource.api.supportedSubmitMethods;
  561. };
  562. SwaggerOperation.prototype.getQueryAndHeaderParams = function(args, includeApiKey) {
  563. if (includeApiKey == null) {
  564. includeApiKey = true;
  565. }
  566. return this.getMatchingParams(['query', 'header'], args, includeApiKey);
  567. };
  568. SwaggerOperation.prototype.getQueryParams = function(args, includeApiKey) {
  569. if (includeApiKey == null) {
  570. includeApiKey = true;
  571. }
  572. return this.getMatchingParams(['query'], args, includeApiKey);
  573. };
  574. SwaggerOperation.prototype.getHeaderParams = function(args, includeApiKey) {
  575. if (includeApiKey == null) {
  576. includeApiKey = true;
  577. }
  578. return this.getMatchingParams(['header'], args, includeApiKey);
  579. };
  580. SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args, includeApiKey) {
  581. var matchingParams, name, param, value, _i, _len, _ref, _ref1;
  582. matchingParams = {};
  583. _ref = this.parameters;
  584. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  585. param = _ref[_i];
  586. if ((jQuery.inArray(param.paramType, paramTypes) >= 0) && args[param.name]) {
  587. matchingParams[param.name] = args[param.name];
  588. }
  589. }
  590. if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
  591. matchingParams[this.resource.api.apiKeyName] = this.resource.api.api_key;
  592. }
  593. if (jQuery.inArray('header', paramTypes) >= 0) {
  594. _ref1 = this.resource.api.headers;
  595. for (name in _ref1) {
  596. value = _ref1[name];
  597. matchingParams[name] = value;
  598. }
  599. }
  600. return matchingParams;
  601. };
  602. SwaggerOperation.prototype.help = function() {
  603. var parameter, _i, _len, _ref;
  604. _ref = this.parameters;
  605. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  606. parameter = _ref[_i];
  607. console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  608. }
  609. return this;
  610. };
  611. return SwaggerOperation;
  612. })();
  613. SwaggerRequest = (function() {
  614. function SwaggerRequest(type, url, headers, body, successCallback, errorCallback, operation) {
  615. var obj,
  616. _this = this;
  617. this.type = type;
  618. this.url = url;
  619. this.headers = headers;
  620. this.body = body;
  621. this.successCallback = successCallback;
  622. this.errorCallback = errorCallback;
  623. this.operation = operation;
  624. if (this.type == null) {
  625. throw "SwaggerRequest type is required (get/post/put/delete).";
  626. }
  627. if (this.url == null) {
  628. throw "SwaggerRequest url is required.";
  629. }
  630. if (this.successCallback == null) {
  631. throw "SwaggerRequest successCallback is required.";
  632. }
  633. if (this.errorCallback == null) {
  634. throw "SwaggerRequest error callback is required.";
  635. }
  636. if (this.operation == null) {
  637. throw "SwaggerRequest operation is required.";
  638. }
  639. if (this.operation.resource.api.verbose) {
  640. console.log(this.asCurl());
  641. }
  642. this.headers || (this.headers = {});
  643. if (this.operation.resource.api.api_key != null) {
  644. this.headers[this.apiKeyName] = this.operation.resource.api.api_key;
  645. }
  646. if (this.headers.mock == null) {
  647. obj = {
  648. type: this.type,
  649. url: this.url,
  650. data: JSON.stringify(this.body),
  651. dataType: 'json',
  652. error: function(xhr, textStatus, error) {
  653. return _this.errorCallback(xhr, textStatus, error);
  654. },
  655. success: function(data) {
  656. return _this.successCallback(data);
  657. }
  658. };
  659. if (obj.type.toLowerCase() === "post" || obj.type.toLowerCase() === "put") {
  660. obj.contentType = "application/json";
  661. }
  662. jQuery.ajax(obj);
  663. }
  664. }
  665. SwaggerRequest.prototype.asCurl = function() {
  666. var header_args, k, v;
  667. header_args = (function() {
  668. var _ref, _results;
  669. _ref = this.headers;
  670. _results = [];
  671. for (k in _ref) {
  672. v = _ref[k];
  673. _results.push("--header \"" + k + ": " + v + "\"");
  674. }
  675. return _results;
  676. }).call(this);
  677. return "curl " + (header_args.join(" ")) + " " + this.url;
  678. };
  679. return SwaggerRequest;
  680. })();
  681. window.SwaggerApi = SwaggerApi;
  682. window.SwaggerResource = SwaggerResource;
  683. window.SwaggerOperation = SwaggerOperation;
  684. window.SwaggerRequest = SwaggerRequest;
  685. }).call(this);