Exemple #1
0
        public Task <IEnumerable <ITrack> > GetTracks()
        {
            if (TracklistInternal != null)
            {
                return(Task.Run(() =>
                {
                    List <ITrack> tracks = new List <ITrack>();

                    foreach (Track t in TracklistInternal.Items)
                    {
                        t.Deserialize(Client);
                        tracks.Add(t);
                    }

                    return tracks as IEnumerable <ITrack>;
                }, Client.CancellationToken));
            }


            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", Id)
            };

            return(Client.Get <Track>("album/{id}/tracks", parms)
                   .ContinueWith <IEnumerable <ITrack> >(task => Client.Transform <Track, ITrack>(task.Result),
                                                         Client.CancellationToken,
                                                         TaskContinuationOptions.NotOnCanceled,
                                                         TaskScheduler.Default));
        }
        public void GetNewUrlSegmentParamter()
        {
            var actual = RequestParameter.GetNewUrlSegmentParamter("user", new { ID = 10 });

            Assert.IsNotNull(actual);
            Assert.AreEqual("user", actual.Id, "Id");
            Assert.AreEqual(new { ID = 10 }, actual.Value, "Value");
            Assert.AreEqual(ParameterType.UrlSegment, actual.Type, "Type");
        }
Exemple #3
0
        public Task <bool> SetSeen()
        {
            List <IRequestParameter> p = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", this.Id),
            };

            return(Client.Post("playlist/{id}/seen", p, DeezerPermissions.BasicAccess));
        }
Exemple #4
0
        public Task <bool> AddToPlaylist(uint playlistId, string songids)
        {
            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("playlist_id", playlistId),
                RequestParameter.GetNewQueryStringParameter("songs", songids)
            };

            return(Client.Post("playlist/{playlist_id}/tracks", parms, DeezerPermissions.ManageLibrary));
        }
Exemple #5
0
        public Task <bool> RemoveTracks(string aTrackIds)
        {
            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("playlist_id", Id),
                RequestParameter.GetNewQueryStringParameter("songs", aTrackIds)
            };

            return(Client.Delete("playlist/{playlist_id}/tracks", parms, DeezerPermissions.ManageLibrary | DeezerPermissions.DeleteLibrary));
        }
Exemple #6
0
        public Task <uint> CreatePlaylist(string title)
        {
            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", Id),
                RequestParameter.GetNewQueryStringParameter("title", title)
            };

            return(Client.PostForCreate("user/{id}/playlists", parms, DeezerPermissions.ManageLibrary).ContinueWith(t => t.Result.Id));
        }
Exemple #7
0
        public Task <IEnumerable <ITrack> > GetTracks(uint aStart, uint aCount)
        {
            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", Id)
            };

            return(Client.Get <Track>("playlist/{id}/tracks", parms, aStart, aCount).ContinueWith <IEnumerable <ITrack> >((aTask) =>
            {
                return Client.Transform <Track, ITrack>(aTask.Result);
            }, Client.CancellationToken, TaskContinuationOptions.NotOnCanceled, TaskScheduler.Default));
        }
Exemple #8
0
        //Internal wrapper around get for all artist methods :)
        private Task <IEnumerable <TDest> > Get <TSource, TDest>(string aMethod, uint aStart, uint aCount) where TSource : TDest, IDeserializable <IDeezerClient>
        {
            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", Id)
            };

            return(Client.Get <TSource>(aMethod, parms, aStart, aCount).ContinueWith <IEnumerable <TDest> >((aTask) =>
            {
                return Client.Transform <TSource, TDest>(aTask.Result);
            }, Client.CancellationToken, TaskContinuationOptions.NotOnCanceled, TaskScheduler.Default));
        }
        public void TestParamsFilledUrl()
        {
            string url = "test.com/charts/{id}";
            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", "something"),
            };

            string trueurl = executor.BuildUrl(url, parms);

            Assert.NotNull(trueurl);
            Assert.AreEqual("test.com/charts/something?output=json", trueurl);
        }
Exemple #10
0
        public Task <IEnumerable <IComment> > GetComments(uint aStart = 0, uint aCount = 10)
        {
            List <IRequestParameter> p = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", this.Id)
            };

            return(Client.Get <Comment>("playlist/{id}/comments", p, aStart, aCount)
                   .ContinueWith <IEnumerable <IComment> >(task => Client.Transform <Comment, IComment>(task.Result),
                                                           Client.CancellationToken,
                                                           TaskContinuationOptions.NotOnCanceled,
                                                           TaskScheduler.Default));
        }
Exemple #11
0
        public Task <IEnumerable <ITrack> > GetFlow(uint aStart = 0, uint aCount = 100)
        {
            List <IRequestParameter> p = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", this.Id),
            };

            return(Client.Get <Track>("user/{id}/flow", p, aStart, aCount)
                   .ContinueWith <IEnumerable <ITrack> >(task => Client.Transform <Track, ITrack>(task.Result),
                                                         Client.CancellationToken,
                                                         TaskContinuationOptions.NotOnCanceled,
                                                         TaskScheduler.Default));
        }
Exemple #12
0
        public Task <IEnumerable <IUserProfile> > GetFans(uint aStart = 0, uint aCount = 25)
        {
            List <IRequestParameter> p = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", this.Id),
            };

            return(Client.Get <UserProfile>("album/{id}/fans", p, aStart, aCount)
                   .ContinueWith <IEnumerable <IUserProfile> >(task => Client.Transform <UserProfile, IUserProfile>(task.Result),
                                                               Client.CancellationToken,
                                                               TaskContinuationOptions.NotOnCanceled,
                                                               TaskScheduler.Default));
        }
Exemple #13
0
        public Task <bool> DeleteComment()
        {
            if (!this.IsUserComment)
            {
                throw new InvalidOperationException("Attempting to delete a comment which the user did not create. Please check 'IsUserComment' property before calling this method.");
            }

            List <IRequestParameter> p = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", this.Id)
            };

            return(Client.Delete("comment/{id}", p, DeezerPermissions.BasicAccess));
        }
Exemple #14
0
        public Task <bool> Rate(int aRating)
        {
            if (aRating < 1 || aRating > 5)
            {
                throw new ArgumentOutOfRangeException("aRating", "Rating value should be between 1 and 5 (inclusive)");
            }

            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", Id),
                RequestParameter.GetNewQueryStringParameter("note", aRating)
            };

            return(Client.Post("playlist/{id}", parms, DeezerPermissions.BasicAccess));
        }
Exemple #15
0
        public Task <bool> AddComment(string commentText)
        {
            if (string.IsNullOrEmpty(commentText))
            {
                throw new ArgumentException("A comment is required.");
            }

            List <IRequestParameter> p = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", this.Id),
                RequestParameter.GetNewQueryStringParameter("comment", commentText),
            };

            return(Client.Post("artist/{id}/comments", p, DeezerPermissions.BasicAccess));
        }
Exemple #16
0
        public async Task <IArtist> GetArtistById(uint artistId)
        {
            var p = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", artistId),
            };

            // Will throw if Deezer error
            var response = await iClient.GetDeezerObject <ArtistObjectResponse>("artist/{id}", p)
                           .ConfigureAwait(false);

            response.Object.Deserialize(iClient);

            return(response.Object);
        }
Exemple #17
0
        public async Task <IUserProfile> GetUserById(uint UserId)
        {
            var p = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", UserId),
            };

            // Will throw if Deezer error
            var response = await iClient.GetDeezerObject <UserProfileObjectResponse>("user/{id}", p)
                           .ConfigureAwait(false);

            response.Object.Deserialize(iClient);

            return(response.Object);
        }
Exemple #18
0
        public Task <IEnumerable <ITrack> > GetFirst40Tracks()
        {
            if (!Client.HasPermission(DeezerPermissions.BasicAccess))
            {
                throw new DeezerPermissionsException(DeezerPermissions.BasicAccess);
            }

            IList <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", Id)
            };

            return(Client.Get <Track>("radio/{id}/tracks", parms).ContinueWith <IEnumerable <ITrack> >((aTask) =>
            {
                return Client.Transform <Track, ITrack>(aTask.Result);
            }, Client.CancellationToken, TaskContinuationOptions.NotOnCanceled, TaskScheduler.Default));
        }
Exemple #19
0
        //Internal wrapper around get for all ChartEndpoint methods :)
        private Task <IEnumerable <TDest> > Get <TSource, TDest>(string aMethod, uint aId, uint aStart, uint aCount) where TSource : TDest, IDeserializable <DeezerClient>
        {
            List <IRequestParameter> parms = new List <IRequestParameter>()
            {
                RequestParameter.GetNewUrlSegmentParamter("id", aId)
            };

            return(iClient.Get <TSource>(aMethod, parms, aStart, aCount).ContinueWith <IEnumerable <TDest> >((aTask) =>
            {
                List <TDest> items = new List <TDest>();

                foreach (var item in aTask.Result.Items)
                {
                    item.Deserialize(iClient);
                    items.Add(item);
                }
                return items;
            }, iClient.CancellationToken, TaskContinuationOptions.NotOnCanceled, TaskScheduler.Default));
        }