Beispiel #1
0
        /* Excludes:
         * images : (image object)[]
         * followers : followers object
         * external_url : external URL object
         */

        /// <summary>
        /// Get the authenticated PublicUser from Spotify
        /// </summary>
        public static async Task <PublicUser> GetCurrentAsync()
        {
            if (!SpotifyApi.IsAuthenticated)
            {
                return(null);
            }
            string profile = await SpotifyApi.ApiGetAsync("/me");

            return(JsonConvert.DeserializeObject <PublicUser>(profile));
        }
Beispiel #2
0
        /// <summary>
        /// Retrieve a list of up to 20 related artists.
        /// </summary>
        public static async Task <SimpleArtist[]> GetRelatedAsync(string id)
        {
            if (!SpotifyApi.IsAuthenticated)
            {
                return(null);
            }
            string endpoint = string.Format("/artists/{0}/related-artists", id);
            string artists  = await SpotifyApi.ApiGetAsync(endpoint);

            return(JObject.Parse(artists)["artists"].ToObject <SimpleArtist[]>());
        }
Beispiel #3
0
        /// <summary>
        /// Retrieve up to 10 of the most popular tracks from an artist.
        /// </summary>
        public static async Task <Track[]> GetTopTracksAsync(string id, string country = "US")
        {
            if (!SpotifyApi.IsAuthenticated)
            {
                return(null);
            }
            string endpoint = string.Format("/artists/{0}/top-tracks?country={1}", id, country);
            string tracks   = await SpotifyApi.ApiGetAsync(endpoint);

            return(JObject.Parse(tracks)["tracks"].ToObject <Track[]>());
        }
Beispiel #4
0
        /// <summary>
        /// Get profile of a user from Spotify
        /// </summary>
        public static async Task <PublicUser> GetAsync(string id)
        {
            if (!SpotifyApi.IsAuthenticated)
            {
                return(null);
            }
            string profile = await SpotifyApi.ApiGetAsync(String.Format("users/{0}", id)).
                             ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <PublicUser>(profile));
        }
Beispiel #5
0
        private static async Task <bool[]> _CheckSavedAsync(string[] ids, string type)
        {
            if (!SpotifyApi.IsAuthenticated)
            {
                return(null);
            }
            string endpoint = string.Format(
                "/me/{0}/contains?ids={1}", type, string.Join(",", ids));
            string data = await SpotifyApi.ApiGetAsync(endpoint);

            return(JsonConvert.DeserializeObject <bool[]>(data));
        }
Beispiel #6
0
        /// <summary>
        /// Retrieve current user's saved tracks.
        /// </summary>
        public static async Task <Page <Track> > GetSavedTracksAsync(
            int offset = 0, int limit = 20)
        {
            if (!SpotifyApi.IsAuthenticated)
            {
                return(null);
            }
            string endpoint = string.Format("/me/tracks?offset={0}&limit={1}", offset, limit);
            string tracks   = await SpotifyApi.ApiGetAsync(endpoint);

            return(JsonConvert.DeserializeObject <Page <Track> >(tracks));
        }
Beispiel #7
0
        /// <summary>
        /// Retrieve the previous page from Spotify API.
        /// Updates the Page object.
        /// </summary>
        public async Task PreviousPage()
        {
            if (Next == null)
            {
                return;
            }
            string prevPageStr = await SpotifyApi.ApiGetAsync(Next, fullUrl : true);

            //Probably not the best way to do this.
            string   key      = (typeof(T) + "s").ToLower().Split('.')[1];
            Page <T> prevPage = JObject.Parse(prevPageStr)[key].ToObject <Page <T> >();

            CopyPage(prevPage);
        }
Beispiel #8
0
        /// <summary>
        /// Retrieve the playlist tracks.
        /// </summary>
        public static async Task <Page <PlaylistTrack> > GetTracksAsync(
            string id, int offset = 0, int limit = 20, string country = "US")
        {
            if (!SpotifyApi.IsAuthenticated)
            {
                return(null);
            }
            string endpoint = string.Format(
                "/playlists/{0}/tracks?offset={1}&limit={2}&country={3}",
                id, offset, limit, country);
            string data = await SpotifyApi.ApiGetAsync(endpoint);

            return(JsonConvert.DeserializeObject <Page <PlaylistTrack> >(data));
        }
Beispiel #9
0
        /// <summary>
        /// Retrieve the albums by the artist of id.
        /// </summary>
        public static async Task <Page <Album> > GetAlbumsAsync(
            string id, int offset = 0, int limit = 20, string[] groups = null)
        {
            if (!SpotifyApi.IsAuthenticated)
            {
                return(null);
            }
            //Build a default groups string[] if needed
            string[] include_groups = groups ?? (new string[] { "album" });
            //Build the endpoint string using passed params
            string endpoint = string.Format(
                "/artists/{0}/albums?offset={1}&limit={2}&include_groups={3}",
                id, offset, limit, string.Join(",", include_groups));

            string albums = await SpotifyApi.ApiGetAsync(endpoint);

            return(JsonConvert.DeserializeObject <Page <Album> >(albums));
        }