channels_controller.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
  2. class ChannelsController < ApplicationController
  3. before_filter :authentication_check
  4. =begin
  5. Format:
  6. JSON
  7. Example:
  8. {
  9. "id":1,
  10. "area":"Email::Inbound",
  11. "adapter":"IMAP",
  12. "group_id:": 1,
  13. "options":{
  14. "host":"mail.example.com",
  15. "user":"some_user",
  16. "password":"some_password",
  17. "ssl":true
  18. },
  19. "active":true,
  20. "updated_at":"2012-09-14T17:51:53Z",
  21. "created_at":"2012-09-14T17:51:53Z",
  22. "updated_by_id":2.
  23. "created_by_id":2,
  24. }
  25. {
  26. "id":1,
  27. "area":"Twitter::Inbound",
  28. "adapter":"Twitter2",
  29. "group_id:": 1,
  30. "options":{
  31. "consumer_key":"PJ4c3dYYRtSZZZdOKo8ow",
  32. "consumer_secret":"ggAdnJE2Al1Vv0cwwvX5bdvKOieFs0vjCIh5M8Dxk",
  33. "oauth_token":"293437546-xxRa9g74CercnU5AvY1uQwLLGIYrV1ezYtpX8oKW",
  34. "oauth_token_secret":"ju0E4l9OdY2Lh1iTKMymAu6XVfOaU2oGxmcbIMRZQK4",
  35. "search":[
  36. {
  37. "item":"#otrs",
  38. "group_id":1,
  39. },
  40. {
  41. "item":"#zombie42",
  42. "group_id":1,
  43. },
  44. {
  45. "item":"#otterhub",
  46. "group_id":1,
  47. }
  48. ],
  49. "mentions" {
  50. "group_id":1,
  51. },
  52. "direct_messages": {
  53. "group_id":1,
  54. }
  55. },
  56. "active":true,
  57. "updated_at":"2012-09-14T17:51:53Z",
  58. "created_at":"2012-09-14T17:51:53Z",
  59. "updated_by_id":2.
  60. "created_by_id":2,
  61. }
  62. =end
  63. =begin
  64. Resource:
  65. GET /api/v1/channels.json
  66. Response:
  67. [
  68. {
  69. "id": 1,
  70. "area":"Email::Inbound",
  71. "adapter":"IMAP",
  72. ...
  73. },
  74. {
  75. "id": 2,
  76. "area":"Email::Inbound",
  77. "adapter":"IMAP",
  78. ...
  79. }
  80. ]
  81. Test:
  82. curl http://localhost/api/v1/channels.json -v -u #{login}:#{password}
  83. =end
  84. def index
  85. return if deny_if_not_role('Admin')
  86. model_index_render(Channel, params)
  87. end
  88. =begin
  89. Resource:
  90. GET /api/v1/channels/#{id}.json
  91. Response:
  92. {
  93. "id": 1,
  94. "area":"Email::Inbound",
  95. "adapter":"IMAP",
  96. ...
  97. }
  98. Test:
  99. curl http://localhost/api/v1/channels/#{id}.json -v -u #{login}:#{password}
  100. =end
  101. def show
  102. return if deny_if_not_role('Admin')
  103. model_show_render(Channel, params)
  104. end
  105. =begin
  106. Resource:
  107. POST /api/v1/channels.json
  108. Payload:
  109. {
  110. "area":"Email::Inbound",
  111. "adapter":"IMAP",
  112. "group_id:": 1,
  113. "options":{
  114. "host":"mail.example.com",
  115. "user":"some_user",
  116. "password":"some_password",
  117. "ssl":true
  118. },
  119. "active":true,
  120. }
  121. Response:
  122. {
  123. "area":"Email::Inbound",
  124. "adapter":"IMAP",
  125. ...
  126. }
  127. Test:
  128. curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"name": "some_name","active": true, "note": "some note"}'
  129. =end
  130. def create
  131. return if deny_if_not_role('Admin')
  132. model_create_render(Channel, params)
  133. end
  134. =begin
  135. Resource:
  136. PUT /api/v1/channels/{id}.json
  137. Payload:
  138. {
  139. "id":1,
  140. "area":"Email::Inbound",
  141. "adapter":"IMAP",
  142. "group_id:": 1,
  143. "options":{
  144. "host":"mail.example.com",
  145. "user":"some_user",
  146. "password":"some_password",
  147. "ssl":true
  148. },
  149. "active":true,
  150. }
  151. Response:
  152. {
  153. "id": 1,
  154. "name": "some_name",
  155. ...
  156. }
  157. Test:
  158. curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  159. =end
  160. def update
  161. return if deny_if_not_role('Admin')
  162. model_update_render(Channel, params)
  163. end
  164. =begin
  165. Resource:
  166. DELETE /api/v1/channels/{id}.json
  167. Response:
  168. {}
  169. Test:
  170. curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
  171. =end
  172. def destroy
  173. return if deny_if_not_role('Admin')
  174. model_destory_render(Channel, params)
  175. end
  176. end