Skip to content

Commit

Permalink
Merge branch 'aevansme-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielLarsenNZ committed Nov 13, 2018
2 parents 01b0ee9 + cccf88e commit 1f57c9f
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ obj
.vscode/launch.json
appsettings.*.json
_*
node_modules
node_modules
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Lightweight .NET Core wrapper for the Spotify Web API.

### Build status

[![Build Status](https://dev.azure.com/daniellarsennz/SpotifyApi.NetCore/_apis/build/status/SpotifyApi.NetCore-Build)](https://dev.azure.com/daniellarsennz/SpotifyApi.NetCore/_build/latest?definitionId=9)

## Features

* Targets .NET Standard 2.0
Expand Down Expand Up @@ -52,10 +56,6 @@ See tests and samples for more usage examples.
| `src/SpotifyApi.NetCore.Tests` | Tests |
| `src/samples/SpotifyVue` | Sample project using ASP.NET Core + Vue.js. [Try the demo](https://spotifyaspnetcore.z5.web.core.windows.net/). |

## Build status

[![Build Status](https://dev.azure.com/daniellarsennz/SpotifyApi.NetCore/_apis/build/status/SpotifyApi.NetCore-Build)](https://dev.azure.com/daniellarsennz/SpotifyApi.NetCore/_build/latest?definitionId=9)

## Spotify Web API Coverage

| Spotify API | Endpoints | Implemented | % | |
Expand All @@ -74,3 +74,9 @@ See tests and samples for more usage examples.
| **Total** | **63** | **14** | **22%** |

Feature requests welcomed! (log an issue)

## Contributors

Thanks to @aevansme for his contributions!

Contributions welcomed. Read [CONTRIB.md](./CONTRIB.md)
24 changes: 24 additions & 0 deletions src/SpotifyApi.NetCore.Tests/PlaylistsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,29 @@ public async Task SearchPlaylists_PlaylistName_AnyItems()
// assert
Assert.IsTrue(response.Items.Any());
}

[TestCategory("Integration")]
[TestMethod]
public async Task GetTracks_ReturnsValidPlaylistTracks()
{
// Arrange
const string username = "spotify";
const string playlistId = "37i9dQZF1DX3WvGXE8FqYX";

var http = new HttpClient();
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());

var api = new PlaylistsApi(http, accounts);

// Act
var response = await api.GetTracks(username, playlistId);

// Assert
Assert.IsNotNull(response.Items);
Assert.IsTrue(response.Items.Length > 0);
Assert.IsTrue(response.Items[0].Track.Name.Length > 0);
Assert.IsTrue(response.Items[0].Track.Album.Name.Length > 0);
Assert.IsTrue(response.Items[0].Track.Artists.Length > 0);
}
}
}
6 changes: 6 additions & 0 deletions src/SpotifyApi.NetCore.Tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Basic usage

- Add "appsettings.local.json" to this directory.
- Add "SpotifyClientId" and "SpotifyClientSecret" inside appsettings.local.json
- run 'dotnet test'

31 changes: 31 additions & 0 deletions src/SpotifyApi.NetCore.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2047
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpotifyApi.NetCore", "SpotifyApi.NetCore\SpotifyApi.NetCore.csproj", "{D835F618-4B23-4DAD-842D-57D308499BA8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpotifyApi.NetCore.Tests", "SpotifyApi.NetCore.Tests\SpotifyApi.NetCore.Tests.csproj", "{86644469-0957-4363-A185-32E6ADEB0C3E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D835F618-4B23-4DAD-842D-57D308499BA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D835F618-4B23-4DAD-842D-57D308499BA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D835F618-4B23-4DAD-842D-57D308499BA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D835F618-4B23-4DAD-842D-57D308499BA8}.Release|Any CPU.Build.0 = Release|Any CPU
{86644469-0957-4363-A185-32E6ADEB0C3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86644469-0957-4363-A185-32E6ADEB0C3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86644469-0957-4363-A185-32E6ADEB0C3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86644469-0957-4363-A185-32E6ADEB0C3E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {45AA36B6-8CC8-463C-9277-2D504217A6D6}
EndGlobalSection
EndGlobal
23 changes: 21 additions & 2 deletions src/SpotifyApi.NetCore/IPlaylistsApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;

namespace SpotifyApi.NetCore
{
Expand All @@ -7,23 +8,41 @@ namespace SpotifyApi.NetCore
/// </summary>
public interface IPlaylistsApi
{
#region GetPlaylists

/// <summary>
/// Get a list of a user's playlists.
/// </summary>
/// <returns>The JSON result deserialized to object (as dynamic).</returns>
Task<PlaylistsSearchResult> GetPlaylists(string username);
Task<T> GetPlaylists<T>(string username);

#endregion

#region GetPlaylist

/// <summary>
/// Get a list of a user's playlists.
/// </summary>
/// <returns>The JSON result deserialized to dynamic.</returns>
[Obsolete("This endpoint has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
Task<Playlist> GetPlaylist(string username, string playlistId);

[Obsolete("This endpoint has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
Task<T> GetPlaylist<T>(string username, string playlistId);

Task<TracksSearchResult> GetTracks(string username, string playlistId);
#endregion

#region GetTracks

[Obsolete("This endpoint has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
Task<PlaylistTracksSearchResult> GetTracks(string username, string playlistId);

[Obsolete("This endpoint has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
Task<T> GetTracks<T>(string username, string playlistId);

#endregion

#region SearchPlaylists

/// <summary>
Expand Down
25 changes: 25 additions & 0 deletions src/SpotifyApi.NetCore/Models/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,29 @@ public partial class PlaylistsSearchResult
[JsonProperty("total")]
public long Total { get; set; }
}

[Obsolete("This endpoint that uses this model has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
public partial class PlaylistTracksSearchResult
{
[JsonProperty("href")]
public Uri Href { get; set; }

[JsonProperty("items")]
public PlaylistTrack[] Items { get; set; }

[JsonProperty("limit")]
public long Limit { get; set; }

[JsonProperty("next")]
public Uri Next { get; set; }

[JsonProperty("offset")]
public long Offset { get; set; }

[JsonProperty("previous")]
public object Previous { get; set; }

[JsonProperty("total")]
public long Total { get; set; }
}
}
20 changes: 18 additions & 2 deletions src/SpotifyApi.NetCore/PlaylistsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public PlaylistsApi(HttpClient httpClient, IAccountsService accountsService) : b
SearchApi = new SearchApi(httpClient, accountsService);
}

#region GetPlaylists

/// <summary>
/// Get a list of a user's playlists.
/// </summary>
Expand All @@ -33,23 +35,34 @@ public async Task<T> GetPlaylists<T>(string username)
public async Task<PlaylistsSearchResult> GetPlaylists(string username)
=> await GetPlaylists<PlaylistsSearchResult>(username);

#endregion

#region GetPlaylist

[Obsolete("This endpoint has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
public async Task<Playlist> GetPlaylist(string username, string playlistId)
=> await GetPlaylist<Playlist>(username, playlistId);

[Obsolete("This endpoint has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
public Task<T> GetPlaylist<T>(string username, string playlistId)
{
throw new NotImplementedException();
}

#endregion

#region GetTracks

/// <summary>
/// Get full details of the tracks of a playlist owned by a Spotify user.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="username">The user's Spotify user ID.</param>
/// <param name="playlistId">The Spotify ID for the playlist.</param>
/// <returns></returns>
public async Task<TracksSearchResult> GetTracks(string username, string playlistId)
=> await GetTracks<TracksSearchResult>(username, playlistId);
[Obsolete("This endpoint has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
public async Task<PlaylistTracksSearchResult> GetTracks(string username, string playlistId)
=> await GetTracks<PlaylistTracksSearchResult>(username, playlistId);

/// <summary>
/// Get full details of the tracks of a playlist owned by a Spotify user.
Expand All @@ -59,6 +72,7 @@ public async Task<TracksSearchResult> GetTracks(string username, string playlist
/// <param name="playlistId">The Spotify ID for the playlist.</param>
/// <returns></returns>

[Obsolete("This endpoint has been deprecated by Spotify and will be removed in the next major release. See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/")]
public async Task<T> GetTracks<T>(string username, string playlistId)
{
if (string.IsNullOrEmpty(username)) throw new ArgumentNullException("username");
Expand All @@ -67,6 +81,8 @@ public async Task<T> GetTracks<T>(string username, string playlistId)
return await GetModel<T>($"{BaseUrl}/users/{Uri.EscapeDataString(username)}/playlists/{Uri.EscapeDataString(playlistId)}/tracks");
}

#endregion

#region SearchPlaylists

/// <summary>
Expand Down

0 comments on commit 1f57c9f

Please sign in to comment.