예제 #1
0
        /// <inheritdoc />
        public async Task <IList <SimpleAlbum> > GetArtistAlbums(SpotifyUri artistUri, AlbumType albumTypes, string market, int limit, int offset)
        {
            // TODO: Move this to Model.Enum or something.
            var albumTypeString = "album_type=";

            if (albumTypes.HasFlag(AlbumType.Album))
            {
                albumTypeString += "album,";
            }
            if (albumTypes.HasFlag(AlbumType.AppearsOn))
            {
                albumTypeString += "appears_on,";
            }
            if (albumTypes.HasFlag(AlbumType.Compilation))
            {
                albumTypeString += "compilation,";
            }
            if (albumTypes.HasFlag(AlbumType.Single))
            {
                albumTypeString += "compilation,";
            }
            albumTypeString = albumTypeString.Remove(albumTypeString.Length - 1);

            var r = await ApiClient.GetAsync <Paging <SimpleAlbum> >(
                MakeUri($"artists/{artistUri.Id}/albums?{albumTypeString}&limit={limit}&offset={offset}{AddMarketCode("&", market)}"),
                this.Token);

            if (r.Response is Paging <SimpleAlbum> res)
            {
                return(await HelperExtensions.LoadToList(res, this.Token));
            }
            return(new List <SimpleAlbum>());
        }
        public SpotifyArtistAlbumsRequest Types(AlbumType type)
        {
            var types =
                Enum.GetValues(typeof(AlbumType))
                .Cast <AlbumType>()
                .Where(v => type.HasFlag(v))
                .Select(p => p.ToString().ToLower())
                .ToList();

            return(this.QParam("album_type", string.Join(",", types)));
        }
예제 #3
0
        public static string GetAlbumValue(this AlbumType en, String separator)
        {
            IEnumerable <StringAttribute> attributes =
                Enum.GetValues(typeof(AlbumType))
                .Cast <AlbumType>()
                .Where(v => en.HasFlag(v))
                .Select(v => typeof(AlbumType).GetRuntimeField(v.ToString()))
                .Select(f => f.GetCustomAttributes(typeof(StringAttribute), false).FirstOrDefault())
                .Cast <StringAttribute>();

            var list = attributes.Select(x => x.Text).ToList();

            return(string.Join(separator, list));
        }
예제 #4
0
        /// <inheritdoc />
        public async Task <IList <SimpleAlbum> > GetArtistAlbums(SpotifyUri artistUri, AlbumType albumTypes, string market, int maxResults, int offset)
        {
            var albumTypeString = string.Empty;

            if (albumTypes.HasFlag(AlbumType.Album))
            {
                albumTypeString += "album,";
            }
            if (albumTypes.HasFlag(AlbumType.AppearsOn))
            {
                albumTypeString += "appears_on,";
            }
            if (albumTypes.HasFlag(AlbumType.Compilation))
            {
                albumTypeString += "compilation,";
            }
            if (albumTypes.HasFlag(AlbumType.Single))
            {
                albumTypeString += "compilation,";
            }
            albumTypeString = albumTypeString.Remove(albumTypeString.Length - 1);

            var r = await ApiClient.GetAsync <Paging <SimpleAlbum> >(
                MakeUri(
                    $"artists/{artistUri.Id}/albums?{albumTypeString}",
                    ("album_type", albumTypeString),
                    ("limit", "50"),
                    ("offset", offset.ToString()),
                    ("market", market)),
                this.Token);

            if (r.Response is Paging <SimpleAlbum> res)
            {
                return(await res.LoadToList(this.Token));
            }
            return(new List <SimpleAlbum>());
        }
예제 #5
0
        public static string GetAlbumValue(this AlbumType en, String separator)
        {
            IEnumerable <StringAttribute> attributes =
                Enum.GetValues(typeof(AlbumType))
                .Cast <AlbumType>()
                .Where(v => en.HasFlag(v))
                .Select(v => typeof(AlbumType).GetField(v.ToString()))
                .Select(f => f.GetCustomAttributes(typeof(StringAttribute), false)[0])
                .Cast <StringAttribute>();

            List <String> list = new List <String>();

            attributes.ToList().ForEach((element) => list.Add(element.Text));
            return(string.Join(" ", list));
        }