Ejemplo n.º 1
0
        /// <summary>
        /// <see cref="IRdioManager.GetTopCharts"/>
        /// </summary>
        public IEnumerable <IRdioObject> GetTopCharts(RdioType type, int start    = 0, int count = 0,
                                                      IEnumerable <string> extras = null)
        {
            var postData = new NameValueCollection
            {
                { "method", "getTopCharts" },
                { "type", type.ToString() }
            };

            if (start > 0)
            {
                postData.Add("start", start.ToString());
            }
            if (count > 0)
            {
                postData.Add("count", count.ToString());
            }
            if (extras != null && extras.Count() > 0)
            {
                postData.Add("extras", string.Join(",", extras));
            }

            var result = MakeWebRequest(postData);

            switch (type)
            {
            case RdioType.Album:
                var albums = Deserialize(result, typeof(RdioResult <IList <RdioAlbum> >));
                return(((RdioResult <IList <RdioAlbum> >)albums).Result);

            case RdioType.Artist:
                var artists = Deserialize(result, typeof(RdioResult <IList <RdioArtist> >));
                return(((RdioResult <IList <RdioArtist> >)artists).Result);

            case RdioType.Track:
                var tracks = Deserialize(result, typeof(RdioResult <IList <RdioTrack> >));
                return(((RdioResult <IList <RdioTrack> >)tracks).Result);

            case RdioType.Playlist:
                var playlists = Deserialize(result, typeof(RdioResult <IList <RdioPlaylist> >));
                return(((RdioResult <IList <RdioPlaylist> >)playlists).Result);

            default:
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <see cref="IRdioManager.GetHeavyRotation"/>
        /// </summary>
        public IEnumerable <IRdioObject> GetHeavyRotation(string user  = null, RdioType type = RdioType.Album,
                                                          bool friends = false, int limit    = 0)
        {
            var postData = new NameValueCollection
            {
                { "method", "getHeavyRotation" },
                { "type", type.ToString() }
            };

            if (!string.IsNullOrEmpty(user))
            {
                postData.Add("user", user);
            }
            if (friends)
            {
                postData.Add("friends", friends.ToString());
            }
            if (limit > 0)
            {
                postData.Add("limit", limit.ToString());
            }

            var result = MakeWebRequest(postData);

            switch (type)
            {
            case RdioType.Artist:
                var artists = Deserialize(result, typeof(RdioResult <IList <RdioArtist> >));
                return(((RdioResult <IList <RdioArtist> >)artists).Result);

            case RdioType.Album:
                var albums = Deserialize(result, typeof(RdioResult <IList <RdioAlbum> >));
                return(((RdioResult <IList <RdioAlbum> >)albums).Result);

            default:
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <see cref="IRdioManager.GetTopCharts"/>
        /// </summary>
        public IEnumerable<IRdioObject> GetTopCharts(RdioType type, int start = 0, int count = 0,
            IEnumerable<string> extras = null)
        {
            var postData = new NameValueCollection
                               {
                                   {"method", "getTopCharts"},
                                   {"type", type.ToString()}
                               };
            if (start > 0) postData.Add("start", start.ToString());
            if (count > 0) postData.Add("count", count.ToString());
            if (extras != null && extras.Count() > 0) postData.Add("extras", string.Join(",", extras));

            var result = MakeWebRequest(postData);
            switch (type)
            {
                case RdioType.Album:
                    var albums = Deserialize(result, typeof(RdioResult<IList<RdioAlbum>>));
                    return ((RdioResult<IList<RdioAlbum>>)albums).Result;
                case RdioType.Artist:
                    var artists = Deserialize(result, typeof(RdioResult<IList<RdioArtist>>));
                    return ((RdioResult<IList<RdioArtist>>)artists).Result;
                case RdioType.Track:
                    var tracks = Deserialize(result, typeof(RdioResult<IList<RdioTrack>>));
                    return ((RdioResult<IList<RdioTrack>>)tracks).Result;
                case RdioType.Playlist:
                    var playlists = Deserialize(result, typeof(RdioResult<IList<RdioPlaylist>>));
                    return ((RdioResult<IList<RdioPlaylist>>)playlists).Result;
                default:
                    return null;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// <see cref="IRdioManager.GetHeavyRotation"/>
        /// </summary>
        public IEnumerable<IRdioObject> GetHeavyRotation(string user = null, RdioType type = RdioType.Album,
            bool friends = false, int limit = 0)
        {
            var postData = new NameValueCollection
                               {
                                   {"method", "getHeavyRotation"},
                                   {"type", type.ToString()}
                               };
            if (!string.IsNullOrEmpty(user)) postData.Add("user", user);
            if (friends) postData.Add("friends", friends.ToString());
            if (limit > 0) postData.Add("limit", limit.ToString());

            var result = MakeWebRequest(postData);
            switch (type)
            {
                case RdioType.Artist:
                    var artists = Deserialize(result, typeof(RdioResult<IList<RdioArtist>>));
                    return ((RdioResult<IList<RdioArtist>>)artists).Result;
                case RdioType.Album:
                    var albums = Deserialize(result, typeof(RdioResult<IList<RdioAlbum>>));
                    return ((RdioResult<IList<RdioAlbum>>)albums).Result;
                default:
                    return null;
            }
        }
Ejemplo n.º 5
0
        public static IRdioObject ConvertDictionaryToRdioObject(IDictionary <string, object> d,
                                                                RdioType type = RdioType.Unknown)
        {
            IRdioObject rdioObject = null;

            if (type == RdioType.Unknown)
            {
                type = ParseRdioType((string)d["type"]);
            }
            switch (type)
            {
            case RdioType.CollectionAlbum:
            case RdioType.Album:
                var album = new RdioAlbum
                {
                    Artist      = (string)d["artist"],
                    ArtistKey   = (string)d["artistKey"],
                    ArtistUrl   = (string)d["artistUrl"],
                    BaseIcon    = (string)d["baseIcon"],
                    CanSample   = (bool)d["canSample"],
                    CanStream   = (bool)d["canStream"],
                    CanTether   = (bool)d["canTether"],
                    Duration    = (int)d["duration"],
                    EmbedUrl    = (string)d["embedUrl"],
                    Icon        = (string)d["icon"],
                    IsClean     = (bool)d["isClean"],
                    IsExplicit  = (bool)d["isExplicit"],
                    Key         = (string)d["key"],
                    Length      = (int)d["length"],
                    Name        = (string)d["name"],
                    Price       = (string)d["price"],
                    ReleaseDate = DateTime.Parse((string)d["releaseDate"]),
                    ShortUrl    = (string)d["shortUrl"],
                    Type        = (string)d["type"],
                    Url         = (string)d["url"]
                };
                object keys;
                if (d.TryGetValue("trackKeys", out keys))
                {
                    album.TrackKeys = new List <object>((object[])keys).Cast <string>().ToList();
                }
                rdioObject = album;
                break;

            case RdioType.CollectionArtist:
            case RdioType.Artist:
                var artist = new RdioArtist
                {
                    BaseIcon = (string)d["baseIcon"],
                    HasRadio = (bool)d["hasRadio"],
                    Icon     = (string)d["icon"],
                    Key      = (string)d["key"],
                    Name     = (string)d["name"],
                    ShortUrl = (string)d["shortUrl"],
                    Length   = (int)d["length"],
                    Type     = (string)d["type"],
                    Url      = (string)d["url"]
                };
                object albumCount;
                if (d.TryGetValue("albumCount", out albumCount))
                {
                    artist.AlbumCount = (int)albumCount;
                }
                rdioObject = artist;
                break;

            case RdioType.Playlist:
                var playlist = new RdioPlaylist
                {
                    BaseIcon    = (string)d["baseIcon"],
                    EmbedUrl    = (string)d["embedUrl"],
                    Icon        = (string)d["icon"],
                    Key         = (string)d["key"],
                    LastUpdated = (decimal)d["lastUpdated"],
                    Length      = (int)d["length"],
                    Name        = (string)d["name"],
                    Owner       = (string)d["owner"],
                    OwnerIcon   = (string)d["ownerIcon"],
                    OwnerKey    = (string)d["ownerKey"],
                    OwnerUrl    = (string)d["ownerUrl"],
                    ShortUrl    = (string)d["shortUrl"],
                    Type        = (string)d["type"],
                    Url         = (string)d["url"]
                };
                rdioObject = playlist;
                break;

            case RdioType.Track:
                var track = new RdioTrack
                {
                    Album                = (string)d["album"],
                    AlbumArtistKey       = (string)d["albumArtistKey"],
                    AlbumArtistName      = (string)d["albumArtist"],
                    AlbumKey             = (string)d["albumKey"],
                    AlbumUrl             = (string)d["albumUrl"],
                    Artist               = (string)d["artist"],
                    ArtistKey            = (string)d["artistKey"],
                    ArtistUrl            = (string)d["artistUrl"],
                    BaseIcon             = (string)d["baseIcon"],
                    CanDownload          = (bool)d["canDownload"],
                    CanDownloadAlbumOnly = (bool)d["canDownloadAlbumOnly"],
                    CanSample            = (bool)d["canSample"],
                    CanStream            = (bool)d["canStream"],
                    CanTether            = (bool)d["canTether"],
                    Duration             = (int)d["duration"],
                    EmbedUrl             = (string)d["embedUrl"],
                    Icon       = (string)d["icon"],
                    IsClean    = (bool)d["isClean"],
                    IsExplicit = (bool)d["isExplicit"],
                    Key        = (string)d["key"],
                    Name       = (string)d["name"],
                    Price      = (string)d["price"],
                    ShortUrl   = (string)d["shortUrl"],
                    Type       = (string)d["type"],
                    Url        = (string)d["url"]
                };
                object playCount;
                if (d.TryGetValue("playCount", out playCount))
                {
                    track.PlayCount = (int)playCount;
                }
                rdioObject = track;
                break;

            case RdioType.User:
                var user = new RdioUser
                {
                    BaseIcon       = (string)d["baseIcon"],
                    FirstName      = (string)d["firstName"],
                    Gender         = (string)d["gender"],
                    Icon           = (string)d["icon"],
                    Key            = (string)d["key"],
                    LastName       = (string)d["lastName"],
                    LibraryVersion = (int)d["libraryVersion"],
                    Type           = (string)d["type"],
                    Url            = (string)d["url"]
                };
                object displayName, lastSongPlayed, lastSongPlayTime, trackCount, username;
                if (d.TryGetValue("displayName", out displayName))
                {
                    user.DisplayName = (string)displayName;
                }
                if (d.TryGetValue("lastSongPlayed", out lastSongPlayed))
                {
                    user.LastSongPlayed = (string)lastSongPlayed;
                }
                if (d.TryGetValue("lastSongPlayTime", out lastSongPlayTime))
                {
                    user.LastSongPlayTime = (DateTime)lastSongPlayTime;
                }
                if (d.TryGetValue("trackCount", out trackCount))
                {
                    user.TrackCount = (int)trackCount;
                }
                if (d.TryGetValue("username", out username))
                {
                    user.Username = (string)username;
                }
                rdioObject = user;
                break;

            default:
                break;
            }
            return(rdioObject);
        }
Ejemplo n.º 6
0
 public static string Pluralize(this RdioType type)
 {
     return(type + "s");
 }
Ejemplo n.º 7
0
        public static IRdioObject ConvertDictionaryToRdioObject(IDictionary <string, object> d,
                                                                RdioType type = RdioType.Unknown)
        {
            IRdioObject rdioObject = null;

            if (type == RdioType.Unknown)
            {
                type = ParseRdioType((string)d["type"]);
            }
            switch (type)
            {
            case RdioType.CollectionAlbum:
            case RdioType.Album:
                var album = new RdioAlbum
                {
                    Artist        = (string)d["artist"],
                    ArtistKey     = (string)d["artistKey"],
                    ArtistUrl     = (string)d["artistUrl"],
                    BaseIcon      = (string)d["baseIcon"],
                    CanSample     = (bool)d["canSample"],
                    CanStream     = (bool)d["canStream"],
                    CanTether     = (bool)d["canTether"],
                    Duration      = (int)d["duration"],
                    EmbedUrl      = (string)d["embedUrl"],
                    Icon          = (string)d["icon"],
                    IsClean       = (bool)d["isClean"],
                    IsExplicit    = (bool)d["isExplicit"],
                    IsCompilation = d.GetOptionalKey <bool>("isCompilation"),
                    Key           = (string)d["key"],
                    Length        = (int)d["length"],
                    Name          = (string)d["name"],
                    Price         = (string)d["price"],
                    ReleaseDate   = DateTime.Parse((string)d["releaseDate"]),
                    ShortUrl      = (string)d["shortUrl"],
                    Type          = (string)d["type"],
                    Url           = (string)d["url"]
                };
                object keys;
                if (d.TryGetValue("trackKeys", out keys))
                {
                    album.TrackKeys = new List <object>((object[])keys).Cast <string>().ToList();
                }
                album.BigIcon = d.GetOptionalKey <string>("bigIcon");

                rdioObject = album;
                break;

            case RdioType.CollectionArtist:
            case RdioType.Artist:
                var artist = new RdioArtist
                {
                    BaseIcon   = (string)d["baseIcon"],
                    HasRadio   = (bool)d["hasRadio"],
                    Icon       = (string)d["icon"],
                    Key        = (string)d["key"],
                    Name       = (string)d["name"],
                    ShortUrl   = (string)d["shortUrl"],
                    Length     = (int)d["length"],
                    Type       = (string)d["type"],
                    Url        = (string)d["url"],
                    AlbumCount = d.GetOptionalKey <int>("albumCount")
                };

                rdioObject = artist;
                break;

            case RdioType.Playlist:
                var playlist = new RdioPlaylist
                {
                    BaseIcon    = (string)d["baseIcon"],
                    EmbedUrl    = (string)d["embedUrl"],
                    Icon        = (string)d["icon"],
                    Key         = (string)d["key"],
                    LastUpdated = (decimal)d["lastUpdated"],
                    Length      = (int)d["length"],
                    Name        = (string)d["name"],
                    Owner       = (string)d["owner"],
                    OwnerIcon   = (string)d["ownerIcon"],
                    OwnerKey    = (string)d["ownerKey"],
                    OwnerUrl    = (string)d["ownerUrl"],
                    ShortUrl    = (string)d["shortUrl"],
                    Type        = (string)d["type"],
                    Url         = (string)d["url"]
                };
                object playlistTrackKeys;
                if (d.TryGetValue("trackKeys", out playlistTrackKeys))
                {
                    playlist.TrackKeys = new List <object>((object[])playlistTrackKeys).Cast <string>().ToList();
                }
                playlist.BigIcon = d.GetOptionalKey <string>("bigIcon");

                rdioObject = playlist;
                break;

            case RdioType.Track:
                var track = new RdioTrack
                {
                    Album                = (string)d["album"],
                    AlbumArtistKey       = (string)d["albumArtistKey"],
                    AlbumArtistName      = (string)d["albumArtist"],
                    AlbumKey             = (string)d["albumKey"],
                    AlbumUrl             = (string)d["albumUrl"],
                    Artist               = (string)d["artist"],
                    ArtistKey            = (string)d["artistKey"],
                    ArtistUrl            = (string)d["artistUrl"],
                    BaseIcon             = (string)d["baseIcon"],
                    CanDownload          = (bool)d["canDownload"],
                    CanDownloadAlbumOnly = (bool)d["canDownloadAlbumOnly"],
                    CanSample            = (bool)d["canSample"],
                    CanStream            = (bool)d["canStream"],
                    CanTether            = (bool)d["canTether"],
                    Duration             = (int)d["duration"],
                    EmbedUrl             = (string)d["embedUrl"],
                    Icon            = (string)d["icon"],
                    IsClean         = (bool)d["isClean"],
                    IsExplicit      = (bool)d["isExplicit"],
                    IsOnCompilation = d.GetOptionalKey <bool>("isOnCompilation"),
                    Key             = (string)d["key"],
                    Name            = (string)d["name"],
                    Price           = (string)d["price"],
                    ShortUrl        = (string)d["shortUrl"],
                    Type            = (string)d["type"],
                    Url             = (string)d["url"]
                };
                track.PlayCount = d.GetOptionalKey <int>("playCount");
                track.BigIcon   = d.GetOptionalKey <string>("bigIcon");

                rdioObject = track;
                break;

            case RdioType.User:
                var user = new RdioUser
                {
                    BaseIcon         = (string)d["baseIcon"],
                    FirstName        = (string)d["firstName"],
                    Gender           = (string)d["gender"],
                    Icon             = (string)d["icon"],
                    Key              = (string)d["key"],
                    LastName         = (string)d["lastName"],
                    LibraryVersion   = (int)d["libraryVersion"],
                    Type             = (string)d["type"],
                    Url              = (string)d["url"],
                    DisplayName      = d.GetOptionalKey <string>("displayName"),
                    LastSongPlayed   = d.GetOptionalKey <string>("lastSongPlayed"),
                    LastSongPlayTime = d.GetOptionalKey <DateTime>("lastSongPlayTime"),
                    TrackCount       = d.GetOptionalKey <int>("trackCount"),
                    Username         = d.GetOptionalKey <string>("username")
                };

                user.IsSubscriber = d.GetOptionalKey <bool>("isSubscriber");
                user.IsUnlimited  = d.GetOptionalKey <bool>("isUnlimited");
                user.IsTrial      = d.GetOptionalKey <bool>("isTrial");

                rdioObject = user;
                break;

            default:
                break;
            }
            return(rdioObject);
        }
Ejemplo n.º 8
0
        public static IRdioObject ConvertDictionaryToRdioObject(IDictionary<string, object> d,
            RdioType type = RdioType.Unknown)
        {
            IRdioObject rdioObject = null;
            if (type == RdioType.Unknown) type = ParseRdioType((string) d["type"]);
            switch (type)
            {
                case RdioType.CollectionAlbum:
                case RdioType.Album:
                    var album = new RdioAlbum
                    {
                        Artist = (string)d["artist"],
                        ArtistKey = (string)d["artistKey"],
                        ArtistUrl = (string)d["artistUrl"],
                        BaseIcon = (string)d["baseIcon"],
                        CanSample = (bool)d["canSample"],
                        CanStream = (bool)d["canStream"],
                        CanTether = (bool)d["canTether"],
                        Duration = (int)d["duration"],
                        EmbedUrl = (string)d["embedUrl"],
                        Icon = (string)d["icon"],
                        IsClean = (bool)d["isClean"],
                        IsExplicit = (bool)d["isExplicit"],
                        IsCompilation = d.GetOptionalKey<bool>("isCompilation"),
                        Key = (string)d["key"],
                        Length = (int)d["length"],
                        Name = (string)d["name"],
                        Price = (string)d["price"],
                        ReleaseDate = DateTime.Parse((string)d["releaseDate"]),
                        ShortUrl = (string)d["shortUrl"],
                        Type = (string)d["type"],
                        Url = (string)d["url"]
                    };
                    object keys;
                    if (d.TryGetValue("trackKeys", out keys))
                        album.TrackKeys = new List<object>((object[])keys).Cast<string>().ToList();
                    album.BigIcon = d.GetOptionalKey<string>("bigIcon");

                    rdioObject = album;
                    break;
                case RdioType.CollectionArtist:
                case RdioType.Artist:
                    var artist = new RdioArtist
                    {
                        BaseIcon = (string)d["baseIcon"],
                        HasRadio = (bool)d["hasRadio"],
                        Icon = (string)d["icon"],
                        Key = (string)d["key"],
                        Name = (string)d["name"],
                        ShortUrl = (string)d["shortUrl"],
                        Length = (int)d["length"],
                        Type = (string)d["type"],
                        Url = (string)d["url"],
                        AlbumCount = d.GetOptionalKey<int>("albumCount")
                    };

                    rdioObject = artist;
                    break;
                case RdioType.Playlist:
                    var playlist = new RdioPlaylist
                    {
                        BaseIcon = (string)d["baseIcon"],
                        EmbedUrl = (string)d["embedUrl"],
                        Icon = (string)d["icon"],
                        Key = (string)d["key"],
                        LastUpdated = (decimal)d["lastUpdated"],
                        Length = (int)d["length"],
                        Name = (string)d["name"],
                        Owner = (string)d["owner"],
                        OwnerIcon = (string)d["ownerIcon"],
                        OwnerKey = (string)d["ownerKey"],
                        OwnerUrl = (string)d["ownerUrl"],
                        ShortUrl = (string)d["shortUrl"],
                        Type = (string)d["type"],
                        Url = (string)d["url"]
                    };
                    object playlistTrackKeys;
                    if (d.TryGetValue("trackKeys", out playlistTrackKeys))
                        playlist.TrackKeys = new List<object>((object[])playlistTrackKeys).Cast<string>().ToList();
                    playlist.BigIcon = d.GetOptionalKey<string>("bigIcon");

                    rdioObject = playlist;
                    break;
                case RdioType.Track:
                    var track = new RdioTrack
                    {
                        Album = (string)d["album"],
                        AlbumArtistKey = (string)d["albumArtistKey"],
                        AlbumArtistName = (string)d["albumArtist"],
                        AlbumKey = (string)d["albumKey"],
                        AlbumUrl = (string)d["albumUrl"],
                        Artist = (string)d["artist"],
                        ArtistKey = (string)d["artistKey"],
                        ArtistUrl = (string)d["artistUrl"],
                        BaseIcon = (string)d["baseIcon"],
                        CanDownload = (bool)d["canDownload"],
                        CanDownloadAlbumOnly = (bool)d["canDownloadAlbumOnly"],
                        CanSample = (bool)d["canSample"],
                        CanStream = (bool)d["canStream"],
                        CanTether = (bool)d["canTether"],
                        Duration = (int)d["duration"],
                        EmbedUrl = (string)d["embedUrl"],
                        Icon = (string)d["icon"],
                        IsClean = (bool)d["isClean"],
                        IsExplicit = (bool)d["isExplicit"],
                        IsOnCompilation = d.GetOptionalKey<bool>("isOnCompilation"),
                        Key = (string)d["key"],
                        Name = (string)d["name"],
                        Price = (string)d["price"],
                        ShortUrl = (string)d["shortUrl"],
                        Type = (string)d["type"],
                        Url = (string)d["url"]
                    };
                    track.PlayCount = d.GetOptionalKey<int>("playCount");
                    track.BigIcon = d.GetOptionalKey<string>("bigIcon");

                    rdioObject = track;
                    break;
                case RdioType.User:
                    var user = new RdioUser
                    {
                        BaseIcon = (string)d["baseIcon"],
                        FirstName = (string)d["firstName"],
                        Gender = (string)d["gender"],
                        Icon = (string)d["icon"],
                        Key = (string)d["key"],
                        LastName = (string)d["lastName"],
                        LibraryVersion = (int)d["libraryVersion"],
                        Type = (string)d["type"],
                        Url = (string)d["url"],
                        DisplayName = d.GetOptionalKey<string>("displayName"),
                        LastSongPlayed = d.GetOptionalKey<string>("lastSongPlayed"),
                        LastSongPlayTime = d.GetOptionalKey<DateTime>("lastSongPlayTime"),
                        TrackCount = d.GetOptionalKey<int>("trackCount"),
                        Username = d.GetOptionalKey<string>("username")
                    };

                    user.IsSubscriber = d.GetOptionalKey<bool>("isSubscriber");
                    user.IsUnlimited = d.GetOptionalKey<bool>("isUnlimited");
                    user.IsTrial = d.GetOptionalKey<bool>("isTrial");

                    rdioObject = user;
                    break;
                default:
                    break;
            }
            return rdioObject;
        }