Skip to content

Commit

Permalink
Music REST API available !
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Nov 11, 2016
1 parent 4b217be commit 277b84b
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 5 deletions.
94 changes: 94 additions & 0 deletions api/controllers/MusicController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

module.exports = {

flushQueue: function(req, res, next){
gladys.music.flushQueue(req.body)
.then((result) => res.json(result))
.catch(next);
},

getCurrentTrack: function(req, res, next){
gladys.music.getCurrentTrack(req.query)
.then((result) => res.json(result))
.catch(next);
},

getQueue: function(req, res, next){
gladys.music.getQueue(req.query)
.then((result) => res.json(result))
.catch(next);
},

getMuted: function(req, res, next){
gladys.music.getMuted(req.query)
.then((result) => res.json(result))
.catch(next);
},

getPlaylists: function(req, res, next){
gladys.music.getPlaylists(req.query)
.then((result) => res.json(result))
.catch(next);
},

getVolume: function(req, res, next){
gladys.music.getVolume(req.query)
.then((result) => res.json(result))
.catch(next);
},

next: function(req, res, next){
gladys.music.next(req.body)
.then((result) => res.json(result))
.catch(next);
},

pause: function(req, res, next){
gladys.music.pause(req.body)
.then((result) => res.json(result))
.catch(next);
},

play: function(req, res, next){
gladys.music.play(req.body)
.then((result) => res.json(result))
.catch(next);
},

playPlaylist: function(req, res, next){
gladys.music.playPlaylist(req.body)
.then((result) => res.json(result))
.catch(next);
},

previous: function(req, res, next){
gladys.music.previous(req.body)
.then((result) => res.json(result))
.catch(next);
},

queue: function(req, res, next){
gladys.music.queue(req.body)
.then((result) => res.json(result))
.catch(next);
},

setMuted: function(req, res, next){
gladys.music.setMuted(req.body)
.then((result) => res.json(result))
.catch(next);
},

setVolume: function(req, res, next){
gladys.music.setVolume(req.body)
.then((result) => res.json(result))
.catch(next);
},

stop: function(req, res, next){
gladys.music.stop(req.body)
.then((result) => res.json(result))
.catch(next);
},
};

17 changes: 17 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ module.exports.routes = {
'post /module/install': 'ModuleController.install',
'post /module/:slug/config': 'ModuleController.config',
'delete /module/:id': 'ModuleController.uninstall',

// Music
'post /music/flushqueue': 'MusicController.flushQueue',
'get /music/currenttrack': 'MusicController.getCurrentTrack',
'get /music/queue': 'MusicController.getQueue',
'get /music/muted': 'MusicController.getMuted',
'get /music/playlist': 'MusicController.getPlaylists',
'get /music/volume': 'MusicController.getVolume',
'post /music/next': 'MusicController.next',
'post /music/pause': 'MusicController.pause',
'post /music/play': 'MusicController.play',
'post /music/playplaylist': 'MusicController.playPlaylist',
'post /music/previous': 'MusicController.previous',
'post /music/queue': 'MusicController.queue',
'post /music/muted': 'MusicController.setMuted',
'post /music/volume': 'MusicController.setVolume',
'post /music/stop': 'MusicController.stop',

// Notification
'get /notification': 'NotificationController.index',
Expand Down
10 changes: 5 additions & 5 deletions test/bootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ function addTestModuleGladys(gladys){
},
music: {
flushQueue: function() {return Promise.resolve()},
getCurrentTrack: function() {return Promise.resolve()},
getQueue: function() {return Promise.resolve()},
getMuted: function() {return Promise.resolve()},
getPlaylists: function() {return Promise.resolve()},
getVolume: function() {return Promise.resolve()},
getCurrentTrack: function() {return Promise.resolve({title: 'test', artist:'test'})},
getQueue: function() {return Promise.resolve([{title: 'test', artist:'test'}])},
getMuted: function() {return Promise.resolve({muted: true})},
getPlaylists: function() {return Promise.resolve([{title: 'test'}])},
getVolume: function() {return Promise.resolve({volume: 1})},
next: function() {return Promise.resolve()},
pause: function() {return Promise.resolve()},
play: function() {return Promise.resolve()},
Expand Down
Loading

0 comments on commit 277b84b

Please sign in to comment.