channels_controller.rb 3.2 KB

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