JsonP.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * FeyaSoft EnterpriseSheet
  3. * Copyright(c) 2007-2013, FeyaSoft Inc. All right reserved.
  4. * info@feyasoft.com http://www.feyasoft.com
  5. */
  6. Ext.ns("feyaSoft.api");
  7. feyaSoft.api.JsonP = function(){
  8. // As documented ... parameters
  9. // c indicates the company id;
  10. // f indicates the filter (FIN, MUL, MKT, META);
  11. // v indicates the type of result (ABSV, PCHG, CAGR). Default is 'ABSV';
  12. // params is an array of other parameters are based on the requirements of the filter
  13. //
  14. // And this is output
  15. /**
  16. count indicates the number of records in the data set
  17. items is an array with the formula result
  18. formula is the formula string
  19. params is an array with the input parameters
  20. result is the computed value
  21. Examples
  22. GET https://api.securities.com/v2/metrics/isif/compute?f=META&c=4738&v=ABSV&params[0]=name
  23. http://emisweb03.securities.com/php/api/v2/formulae/isif/compute?c=3303906&f=INF&v=ABSV&params[0]=name
  24. {
  25. "status":200,
  26. "message":"OK",
  27. "apiVersion":"2.0",
  28. "data":{
  29. "count":1,
  30. "total_records":"1",
  31. "items":[
  32. {
  33. "formula":"=ISIF('4738', 'META', 'ABSV', 'name')",
  34. "params":[
  35. {
  36. "0":"4738",
  37. "1":"META",
  38. "2":"ABSV",
  39. "3":"name"
  40. }
  41. ],
  42. "result":"Hindustan Unilever Ltd.",
  43. }
  44. ]
  45. }
  46. }
  47. */
  48. var urls = {
  49. // example: =ISIF('3303906', 'INF', 'ABSV', 'name')
  50. 'ISIFFormulaUrl': 'http://emisweb03.securities.com/php/api/v2/formulae/isif/compute?',
  51. //'ISIFFormulaUrl': 'http://api-dev.securities.com/v2/formulae/isif/compute?'
  52. 'ISIFCompanyUrl': 'http://api-dev.securities.com/v2/companies?'
  53. };
  54. var callISIFormula = function(formula, params, callback, scope){
  55. var url = null;
  56. var readResponse = function(action, response){
  57. return response;
  58. };
  59. var reader = {
  60. readResponse: readResponse
  61. };
  62. // check whether this is for ISIF formula
  63. if (formula == "ISIF") {
  64. url = urls['ISIFFormulaUrl'];
  65. var ISFArgs = params.ISFArgs;
  66. var length = ISFArgs.length;
  67. if (length == 1) url = url + "c=" + ISFArgs[0];
  68. else if (length == 2) url = url + "c=" + ISFArgs[0] + "&f=" + ISFArgs[1];
  69. else if (length == 3) url = url + "c=" + ISFArgs[0] + "&f=" + ISFArgs[1] + "&v=" + ISFArgs[2];
  70. else if (length > 3) {
  71. url = url + "c=" + ISFArgs[0] + "&f=" + ISFArgs[1] + "&v=" + ISFArgs[2];
  72. for (var i=3; i<length; i++) {
  73. var startPoint = i - 3;
  74. url = url + "&params[" + startPoint + "]=" + ISFArgs[i];
  75. }
  76. }
  77. }
  78. if (url) {
  79. // This is EXTJS format ... jsonP call
  80. var proxy = new Ext.data.ScriptTagProxy({url: url});
  81. proxy.doRequest(undefined, [], [], reader, callback, scope);
  82. // This is JQuery format ... jsonP call
  83. /**
  84. $.ajax({
  85. url: url,
  86. type: "GET",
  87. dataType: "jsonP",
  88. success: function(response) {
  89. callback(scope, response);
  90. }
  91. });
  92. **/
  93. }
  94. };
  95. var searchCompanyName = function(keyword, callback, scope, limit){
  96. var url = urls['ISIFCompanyUrl'];
  97. limit = limit || 15;
  98. url += 'q=[name:'+keyword+'*]&max-results='+limit;
  99. var readResponse = function(action, response){
  100. return response;
  101. };
  102. var reader = {
  103. readResponse: readResponse
  104. };
  105. var proxy = new Ext.data.ScriptTagProxy({url: url});
  106. proxy.doRequest(undefined, [], [], reader, callback, scope);
  107. };
  108. return {
  109. callISIFormula: callISIFormula,
  110. searchCompanyName : searchCompanyName
  111. };
  112. }();