diff --git a/.vscode/csharp.code-snippets b/.vscode/csharp.code-snippets index 8eae99f8..6d618ddd 100644 --- a/.vscode/csharp.code-snippets +++ b/.vscode/csharp.code-snippets @@ -7,7 +7,7 @@ "{", " public class $1", " {", - " public ${2:string} ${3:Name} { get; set; }", + " public ${2:string} ${3:Name} { get; private set; }", "", " $4", " }", diff --git a/SpotifyAPI.Web/Clients/Interfaces/ITracksClient.cs b/SpotifyAPI.Web/Clients/Interfaces/ITracksClient.cs index 8388b99f..e4d87934 100644 --- a/SpotifyAPI.Web/Clients/Interfaces/ITracksClient.cs +++ b/SpotifyAPI.Web/Clients/Interfaces/ITracksClient.cs @@ -1,6 +1,20 @@ +using System.Threading.Tasks; + namespace SpotifyAPI.Web { public interface ITracksClient { + Task GetSeveral(TracksRequest request); + + Task GetAudioAnalysis(string trackId); + Task GetAudioFeatures(string trackId); + + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")] + Task Get(string trackId); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")] + Task Get(string trackId, TrackRequest request); + + Task GetSeveralAudioFeatures(TracksAudioFeaturesRequest request); } } diff --git a/SpotifyAPI.Web/Clients/TracksClient.cs b/SpotifyAPI.Web/Clients/TracksClient.cs index 7e973da0..4e515111 100644 --- a/SpotifyAPI.Web/Clients/TracksClient.cs +++ b/SpotifyAPI.Web/Clients/TracksClient.cs @@ -1,9 +1,54 @@ +using System.Threading.Tasks; using SpotifyAPI.Web.Http; +using URLs = SpotifyAPI.Web.SpotifyUrls; namespace SpotifyAPI.Web { public class TracksClient : APIClient, ITracksClient { public TracksClient(IAPIConnector apiConnector) : base(apiConnector) { } + + public Task Get(string trackId) + { + Ensure.ArgumentNotNullOrEmptyString(trackId, nameof(trackId)); + + return API.Get(URLs.Track(trackId)); + } + + public Task Get(string trackId, TrackRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(trackId, nameof(trackId)); + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get(URLs.Track(trackId), request.BuildQueryParams()); + } + + public Task GetAudioAnalysis(string trackId) + { + Ensure.ArgumentNotNullOrEmptyString(trackId, nameof(trackId)); + + return API.Get(URLs.AudioAnalysis(trackId)); + } + + public Task GetAudioFeatures(string trackId) + { + Ensure.ArgumentNotNullOrEmptyString(trackId, nameof(trackId)); + + return API.Get(URLs.AudioFeatures(trackId)); + } + + public Task GetSeveral(TracksRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get(URLs.Tracks(), request.BuildQueryParams()); + } + + public Task GetSeveralAudioFeatures(TracksAudioFeaturesRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get(URLs.AudioFeatures(), request.BuildQueryParams()); + } } } diff --git a/SpotifyAPI.Web/Models/Request/RequestParams.cs b/SpotifyAPI.Web/Models/Request/RequestParams.cs index a5fa2a2a..feb5505b 100644 --- a/SpotifyAPI.Web/Models/Request/RequestParams.cs +++ b/SpotifyAPI.Web/Models/Request/RequestParams.cs @@ -11,7 +11,7 @@ namespace SpotifyAPI.Web { public JObject BuildBodyParams() { - // Make sure everything is okay before building query params + // Make sure everything is okay before building body params CustomEnsure(); var bodyProps = GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public) diff --git a/SpotifyAPI.Web/Models/Request/TrackRequest.cs b/SpotifyAPI.Web/Models/Request/TrackRequest.cs new file mode 100644 index 00000000..423e5046 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/TrackRequest.cs @@ -0,0 +1,8 @@ +namespace SpotifyAPI.Web +{ + public class TrackRequest : RequestParams + { + [QueryParam("market")] + public string Market { get; set; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/TracksAudioFeaturesRequest.cs b/SpotifyAPI.Web/Models/Request/TracksAudioFeaturesRequest.cs new file mode 100644 index 00000000..38449896 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/TracksAudioFeaturesRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class TracksAudioFeaturesRequest : RequestParams + { + public TracksAudioFeaturesRequest(IList ids) + { + Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids)); + + Ids = ids; + } + + [QueryParam("ids")] + public IList Ids { get; private set; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/TracksRequest.cs b/SpotifyAPI.Web/Models/Request/TracksRequest.cs new file mode 100644 index 00000000..965e6938 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/TracksRequest.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class TracksRequest : RequestParams + { + public TracksRequest(IList ids) + { + Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids)); + + Ids = ids; + } + + [QueryParam("ids")] + public IList Ids { get; } + + [QueryParam("market")] + public string Market { get; set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/Section.cs b/SpotifyAPI.Web/Models/Response/Section.cs new file mode 100644 index 00000000..f22ff14a --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/Section.cs @@ -0,0 +1,18 @@ +namespace SpotifyAPI.Web +{ + public class Section + { + public float Start { get; private set; } + public float Duration { get; private set; } + public float Confidence { get; private set; } + public float Loudness { get; private set; } + public float Tempo { get; private set; } + public float TempoConfidence { get; private set; } + public int Key { get; private set; } + public float KeyConfidence { get; private set; } + public int Mode { get; private set; } + public float ModeConfidence { get; private set; } + public int TimeSignature { get; private set; } + public float TimeSignatureConfidence { get; private set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/Segment.cs b/SpotifyAPI.Web/Models/Response/Segment.cs new file mode 100644 index 00000000..b8efae9a --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/Segment.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class Segment + { + public float Start { get; private set; } + public float Duration { get; private set; } + public float Confidence { get; private set; } + public float LoudnessStart { get; private set; } + public float LoudnessMax { get; private set; } + public float LoudnessMaxTime { get; private set; } + public float LoudnessEnd { get; private set; } + public List Pitches { get; private set; } + public List Timbre { get; private set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/TimeInterval.cs b/SpotifyAPI.Web/Models/Response/TimeInterval.cs new file mode 100644 index 00000000..d83f1a85 --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/TimeInterval.cs @@ -0,0 +1,9 @@ +namespace SpotifyAPI.Web +{ + public class TimeInterval + { + public float Start { get; private set; } + public float Duration { get; private set; } + public float Confidence { get; private set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/TrackAudioAnalysis.cs b/SpotifyAPI.Web/Models/Response/TrackAudioAnalysis.cs new file mode 100644 index 00000000..ceb79167 --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/TrackAudioAnalysis.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class TrackAudioAnalysis + { + public List Bars { get; private set; } + public List Beats { get; private set; } + public List
Sections { get; private set; } + public List Segments { get; private set; } + public List Tatums { get; private set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/TrackAudioFeatures.cs b/SpotifyAPI.Web/Models/Response/TrackAudioFeatures.cs new file mode 100644 index 00000000..0676a9cd --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/TrackAudioFeatures.cs @@ -0,0 +1,24 @@ +namespace SpotifyAPI.Web +{ + public class TrackAudioFeatures + { + public float Acousticness { get; private set; } + public string AnalysisUrl { get; private set; } + public float Danceability { get; private set; } + public int DurationMs { get; private set; } + public float Energy { get; private set; } + public string Id { get; private set; } + public float Instrumentalness { get; private set; } + public int Key { get; private set; } + public float Liveness { get; private set; } + public float Loudness { get; private set; } + public int Mode { get; private set; } + public float Speechiness { get; private set; } + public float Tempo { get; private set; } + public int TimeSignature { get; private set; } + public string TrackHref { get; private set; } + public string Type { get; private set; } + public string Uri { get; private set; } + public float Valence { get; private set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/TracksAudioFeaturesResponse.cs b/SpotifyAPI.Web/Models/Response/TracksAudioFeaturesResponse.cs new file mode 100644 index 00000000..4641b074 --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/TracksAudioFeaturesResponse.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class TracksAudioFeaturesResponse + { + public List AudioFeatures { get; private set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/TracksResponse.cs b/SpotifyAPI.Web/Models/Response/TracksResponse.cs new file mode 100644 index 00000000..a3aa9bc4 --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/TracksResponse.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class TracksResponse + { + public List Tracks { get; private set; } + } +} diff --git a/SpotifyAPI.Web/SpotifyUrls.cs b/SpotifyAPI.Web/SpotifyUrls.cs index f38a0589..2e8fd218 100644 --- a/SpotifyAPI.Web/SpotifyUrls.cs +++ b/SpotifyAPI.Web/SpotifyUrls.cs @@ -51,6 +51,16 @@ namespace SpotifyAPI.Web public static Uri PlaylistFollowers(string playlistId) => EUri($"playlists/{playlistId}/followers"); + public static Uri Tracks() => EUri($"tracks"); + + public static Uri Track(string trackId) => EUri($"tracks/{trackId}"); + + public static Uri AudioAnalysis(string trackId) => EUri($"audio-analysis/{trackId}"); + + public static Uri AudioFeatures(string trackId) => EUri($"audio-features/{trackId}"); + + public static Uri AudioFeatures() => EUri($"audio-features"); + private static Uri EUri(FormattableString path) => new Uri(path.ToString(_provider), UriKind.Relative); } }