slas_controller.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class SlasController < ApplicationController
  3. before_filter :authentication_check
  4. =begin
  5. Format:
  6. JSON
  7. Example:
  8. {
  9. "id":1,
  10. "name":"some sla",
  11. "condition":{"c_a":1,"c_b":2},
  12. "data":{"o_a":1,"o_b":2},
  13. "updated_at":"2012-09-14T17:51:53Z",
  14. "created_at":"2012-09-14T17:51:53Z",
  15. "updated_by_id":2.
  16. "created_by_id":2,
  17. }
  18. =end
  19. =begin
  20. Resource:
  21. GET /api/v1/slas.json
  22. Response:
  23. [
  24. {
  25. "id": 1,
  26. "name": "some_name1",
  27. ...
  28. },
  29. {
  30. "id": 2,
  31. "name": "some_name2",
  32. ...
  33. }
  34. ]
  35. Test:
  36. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password}
  37. =end
  38. def index
  39. return if deny_if_not_role('Admin')
  40. model_index_render(Sla, params)
  41. end
  42. =begin
  43. Resource:
  44. GET /api/v1/slas/#{id}.json
  45. Response:
  46. {
  47. "id": 1,
  48. "name": "name_1",
  49. ...
  50. }
  51. Test:
  52. curl http://localhost/api/v1/slas/#{id}.json -v -u #{login}:#{password}
  53. =end
  54. def show
  55. return if deny_if_not_role('Admin')
  56. model_show_render(Sla, params)
  57. end
  58. =begin
  59. Resource:
  60. POST /api/v1/slas.json
  61. Payload:
  62. {
  63. "name":"some sla",
  64. "condition":{"c_a":1,"c_b":2},
  65. "data":{"o_a":1,"o_b":2},
  66. }
  67. Response:
  68. {
  69. "id": 1,
  70. "name": "some_name",
  71. ...
  72. }
  73. Test:
  74. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"name": "some_name","active": true, "note": "some note"}'
  75. =end
  76. def create
  77. return if deny_if_not_role('Admin')
  78. model_create_render(Sla, params)
  79. end
  80. =begin
  81. Resource:
  82. PUT /api/v1/slas/{id}.json
  83. Payload:
  84. {
  85. "name":"some sla",
  86. "condition":{"c_a":1,"c_b":2},
  87. "data":{"o_a":1,"o_b":2},
  88. }
  89. Response:
  90. {
  91. "id": 1,
  92. "name": "some_name",
  93. ...
  94. }
  95. Test:
  96. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  97. =end
  98. def update
  99. return if deny_if_not_role('Admin')
  100. model_update_render(Sla, params)
  101. end
  102. =begin
  103. Resource:
  104. DELETE /api/v1/slas/{id}.json
  105. Response:
  106. {}
  107. Test:
  108. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
  109. =end
  110. def destroy
  111. return if deny_if_not_role('Admin')
  112. model_destory_render(Sla, params)
  113. end
  114. end