Exemple #1
0
        private APIResponse PutPlaylist(APIRequest request)
        {
            var cname    = APIUtils.DecodeUrlDataString(request.Segment);
            var playlist = JsonConvert.DeserializeObject <Playlist>(request.Body);

            //TODO return different status codes: 201 for a new playlist, 204 for an update (?)

            MediaDatabase.SetPlaylist(cname, playlist);

            return(new APIResponse(string.Empty, (int)HttpStatusCode.Created));
        }
Exemple #2
0
        private APIResponse GetPlaylist(APIRequest request)
        {
            var cname    = APIUtils.DecodeUrlDataString(request.Segment);
            var playlist = MediaDatabase.GetPlaylist(cname);

            if (MediaDatabase.GetPlaylist(cname) == null)
            {
                throw new ResourceNotFoundException();
            }

            return(new APIResponse(JsonConvert.SerializeObject(new { data = playlist })));
        }
Exemple #3
0
        private APIResponse DeletePlaylist(APIRequest request)
        {
            var cname = APIUtils.DecodeUrlDataString(request.Segment);

            if (MediaDatabase.GetPlaylist(cname) == null)
            {
                throw new ResourceNotFoundException();
            }

            MediaDatabase.DeletePlaylist(cname);

            return(new APIResponse(string.Empty, (int)HttpStatusCode.NoContent));
        }
Exemple #4
0
        private APIResponse GetFolder(APIRequest request)
        {
            string folderPath = APIUtils.DecodeUrlDataString(request.Segment);
            Dictionary <string, object> responseData = null;

            if (MediaDatabase.GetFolderExists(folderPath))
            {
                responseData = new Dictionary <string, object>();
                responseData.Add("path", folderPath);
                responseData.Add("folders", MediaDatabase.GetFoldersInFolder(folderPath));
                responseData.Add("songs", MediaDatabase.GetSongsInFolder(folderPath));
            }
            else
            {
                throw new ResourceNotFoundException();
            }

            return(new APIResponse(JsonConvert.SerializeObject(new { data = responseData })));
        }