Skip to content
Snippets Groups Projects
Commit d6dde397 authored by Sing Li's avatar Sing Li
Browse files

initial implementation of REST-full API closes #349

parent ba7eb3ac
No related merge requests found
......@@ -58,7 +58,8 @@ It is a great solution for communities and companies wanting to privately host t
- Media Embeds
- Link Previews
- LDAP Authentication - [LDAP Authentication on Rocket.Chat Wiki](https://github.com/RocketChat/Rocket.Chat/wiki/LDAP-Authentication)
- Face to Face Video Conferencing aka WebRTC (Alpha) - [How to go video](https://github.com/RocketChat/Rocket.Chat/wiki/Using-Face-to-face-video-conference-%28aka-webrtc%29)
- Face to Face Video Conferencing aka WebRTC (Alpha) - [How to video chat](https://github.com/RocketChat/Rocket.Chat/wiki/Using-Face-to-face-video-conference-%28aka-webrtc%29)
- REST-full APIs - [Ready for testing ...](https://github.com/RocketChat/Rocket.Chat/wiki/REST-full-APIs)
### Roadmap for v1.0
......@@ -71,7 +72,6 @@ It is a great solution for communities and companies wanting to privately host t
- Native Android Application [Issue #271 - HELP WANTED](https://github.com/RocketChat/Rocket.Chat/issues/271)
- Native iOS Application [Issue #270 - HELP WANTED](https://github.com/RocketChat/Rocket.Chat/issues/270)
- Full text search
- REST-full APIs
- Kerberos Authentication
- XMPP Multi-user chat (MUC)
......
Api = new Restivus
useDefaultAuth: true
prettyJson: true
Api.addCollection ChatMessage
Api.addCollection ChatRoom
Api.addRoute 'version', authRequired: false,
get: ->
version = {api: '0.1', rocketchat: '0.5'}
status: 'success', versions: version
Api.addRoute 'publicRooms', authRequired: true,
get: ->
rooms = ChatRoom.find({ t: 'c' }, { sort: { msgs:-1 } }).fetch()
if rooms
status: 'success', rooms: rooms
else
statusCode: 404
body: status: 'fail', message: 'Rooms not found'
# join a room
Api.addRoute 'rooms/:id/join', authRequired: true,
post: ->
Meteor.runAsUser this.userId, () =>
Meteor.call('joinRoom', @urlParams.id)
status: 'success' # need to handle error
# leave a room
Api.addRoute 'rooms/:id/leave', authRequired: true,
post: ->
Meteor.runAsUser this.userId, () =>
Meteor.call('leaveRoom', @urlParams.id)
status: 'success' # need to handle error
# get messages in a room
Api.addRoute 'rooms/:id/messages', authRequired: true,
post: ->
msgs = ChatMessage.find({rid: @urlParams.id, _deleted: {$ne: true}}, {sort: {ts: -1}}, {limit: 50}).fetch()
if msgs
status: 'success', messages: msgs
else
statusCode: 404
body: status: 'fail', message: 'Messages not found'
# send a message in a room - POST body should be { "msg" : "this is my message"}
Api.addRoute 'rooms/:id/send', authRequired: true,
post: ->
Meteor.runAsUser this.userId, () =>
console.log @bodyParams.msg
Meteor.call('sendMessage', {msg: this.bodyParams.msg, rid: @urlParams.id} )
status: 'success' #need to handle error
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment