online_notifications_controller.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class OnlineNotificationsController < ApplicationController
  3. before_filter :authentication_check
  4. =begin
  5. Format:
  6. JSON
  7. Example:
  8. {
  9. "id":1,
  10. "name":"some template",
  11. "user_id": null,
  12. "options":{"a":1,"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/templates.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/online_notifications.json -v -u #{login}:#{password}
  37. =end
  38. def index
  39. if params[:full]
  40. render :json => OnlineNotification.list_full(current_user, 50)
  41. return
  42. end
  43. notifications = OnlineNotification.list(current_user, 50)
  44. model_index_render_result(notifications)
  45. end
  46. =begin
  47. Resource:
  48. PUT /api/v1/online_notifications/{id}
  49. Payload:
  50. {
  51. "name": "some name",
  52. "options":{"a":1,"b":2},
  53. }
  54. Response:
  55. {
  56. "id": 1,
  57. "name": "some_name",
  58. ...
  59. }
  60. Test:
  61. curl http://localhost/api/v1/online_notifications -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  62. =end
  63. def update
  64. notification = OnlineNotification.find(params[:id])
  65. if notification.user_id != current_user.id
  66. response_access_deny
  67. return
  68. end
  69. model_update_render(OnlineNotification, params)
  70. end
  71. end