PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/public/javascript/rexster/ajax.js

http://github.com/tinkerpop/rexster
JavaScript | 213 lines | 165 code | 15 blank | 33 comment | 0 complexity | e9affe08062ad9d496cb65ba102ec39d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. define(
  2. [
  3. "rexster/server"
  4. ],
  5. function (server) {
  6. var rexsterMimeType = "application/vnd.rexster-v1+json";
  7. var baseUri = "";
  8. // currently only one of these
  9. baseUri = server.getBaseUri(0);
  10. // public methods
  11. return {
  12. /**
  13. * Get a list of graphs.
  14. *
  15. * @param onSuccess {Function} The action that occurs on a successful REST call.
  16. * @param onFail {Function} The action that occurs on a failed REST call.
  17. */
  18. getGraphs : function(onSuccess, onFail){
  19. $.ajax({
  20. url: baseUri,
  21. accepts:{
  22. json: rexsterMimeType
  23. },
  24. type: "GET",
  25. dataType:"json",
  26. success: onSuccess,
  27. error: onFail
  28. });
  29. },
  30. /**
  31. * Get a specific graph.
  32. *
  33. * @param graphName {String} The name of the graph.
  34. * @param onSuccess {Function} The action that occurs on a successful REST call.
  35. * @param onFail {Function} The action that occurs on a failed REST call.
  36. */
  37. getGraph : function(graphName, onSuccess, onFail){
  38. $.ajax({
  39. url: baseUri + graphName,
  40. accepts:{
  41. json: rexsterMimeType
  42. },
  43. type: "GET",
  44. dataType:"json",
  45. success: onSuccess,
  46. error: onFail
  47. });
  48. },
  49. /**
  50. * Get a list of vertices for a specific graph.
  51. *
  52. * @param graphName {String} the name of the graph.
  53. * @param start {int} The first vertex to return in the set.
  54. * @param end {int} The last vertex to return in the set.
  55. * @param onSuccess {Function} The action that occurs on a successful REST call.
  56. * @param onFail {Function} The action that occurs on a failed REST call.
  57. */
  58. getVertices : function(graphName, start, end, onSuccess, onFail){
  59. $.ajax({
  60. url: baseUri + graphName + "/vertices?rexster.offset.start=" + start + "&rexster.offset.end=" + end,
  61. accepts:{
  62. json: rexsterMimeType
  63. },
  64. type: "GET",
  65. dataType:"json",
  66. success: onSuccess,
  67. async:false,
  68. error: onFail
  69. });
  70. },
  71. /**
  72. * Get a list of edges for a specific graph.
  73. *
  74. * @param graphName {String} the name of the graph.
  75. * @param start {int} The first edge to return in the set.
  76. * @param end {int} The last edge to return in the set.
  77. * @param onSuccess {Function} The action that occurs on a successful REST call.
  78. * @param onFail {Function} The action that occurs on a failed REST call.
  79. */
  80. getEdges : function(graphName, start, end, onSuccess, onFail){
  81. $.ajax({
  82. url: baseUri + graphName + "/edges?rexster.offset.start=" + start + "&rexster.offset.end=" + end,
  83. accepts:{
  84. json: rexsterMimeType
  85. },
  86. type: "GET",
  87. dataType:"json",
  88. success: onSuccess,
  89. async:false,
  90. error: onFail
  91. });
  92. },
  93. getVertexEdges : function(graphName, vertex, onSuccess, onFail, asynchronous) {
  94. $.ajax({
  95. url: baseUri + graphName + "/vertices/" + encodeURIComponent(vertex) + "/bothE",
  96. accepts:{
  97. json: rexsterMimeType
  98. },
  99. type: "GET",
  100. dataType:"json",
  101. success: onSuccess,
  102. async:asynchronous,
  103. error: onFail
  104. });
  105. },
  106. getVertexInEdges : function(graphName, vertex, onSuccess, onFail, asynchronous) {
  107. $.ajax({
  108. url: baseUri + graphName + "/vertices/" + encodeURIComponent(vertex) + "/inE",
  109. accepts:{
  110. json: rexsterMimeType
  111. },
  112. type: "GET",
  113. dataType:"json",
  114. success: onSuccess,
  115. async:asynchronous,
  116. error: onFail
  117. });
  118. },
  119. getVertexOutEdges : function(graphName, vertex, onSuccess, onFail, asynchronous) {
  120. $.ajax({
  121. url: baseUri + graphName + "/vertices/" + encodeURIComponent(vertex) + "/outE",
  122. accepts:{
  123. json: rexsterMimeType
  124. },
  125. type: "GET",
  126. dataType:"json",
  127. success: onSuccess,
  128. async:asynchronous,
  129. error: onFail
  130. });
  131. },
  132. getVertexElement : function(graphName, vertex, onSuccess, onFail, asynchronous) {
  133. $.ajax({
  134. url: baseUri + graphName + "/vertices/" + encodeURIComponent(vertex),
  135. accepts:{
  136. json: rexsterMimeType
  137. },
  138. type: "GET",
  139. dataType:"json",
  140. success: onSuccess,
  141. async:asynchronous,
  142. error: onFail
  143. });
  144. },
  145. getEdgeElement : function(graphName, edge, onSuccess, onFail, asynchronous) {
  146. $.ajax({
  147. url: baseUri + graphName + "/edges/" + encodeURIComponent(edge),
  148. accepts:{
  149. json: rexsterMimeType
  150. },
  151. type: "GET",
  152. dataType:"json",
  153. success: onSuccess,
  154. async:asynchronous,
  155. error: onFail
  156. });
  157. },
  158. getVertexBoth : function(graphName, vertex, onSuccess, onFail, asynchronous) {
  159. $.ajax({
  160. url: baseUri + graphName + "/vertices/" + encodeURIComponent(vertex) + "/both",
  161. accepts:{
  162. json: rexsterMimeType
  163. },
  164. type: "GET",
  165. dataType:"json",
  166. success: onSuccess,
  167. async:asynchronous,
  168. error: onFail
  169. });
  170. },
  171. getIndices : function(graphName, onSuccess, onFail, asynchronous) {
  172. $.ajax({
  173. url: baseUri + graphName + "/indices",
  174. accepts:{
  175. json: rexsterMimeType
  176. },
  177. type: "GET",
  178. dataType:"json",
  179. success: onSuccess,
  180. async:asynchronous,
  181. error: onFail
  182. });
  183. },
  184. getByIndex : function(graphName, start, end, indexName, indexKey, indexValue, onSuccess, onFail){
  185. $.ajax({
  186. url: baseUri + graphName + "/indices/" + encodeURIComponent(indexName) + "?rexster.offset.start=" + start + "&rexster.offset.end=" + end + "&key=" + encodeURIComponent(indexKey) + "&value=" + encodeURIComponent(indexValue),
  187. accepts:{
  188. json: rexsterMimeType
  189. },
  190. type: "GET",
  191. dataType:"json",
  192. success: onSuccess,
  193. async:false,
  194. error: onFail
  195. });
  196. }
  197. };
  198. });