Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features and Bug Fixes #68

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/AlbumEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using SpotNetCore.Models;

namespace SpotNetCore.Endpoints
{
public class AlbumEndpoint
{
private readonly HttpClient _httpClient;

internal AlbumEndpoint(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async Task<IEnumerable<SpotifyTrack>> GetAlbumTracks(String albumId)
{
return await _httpClient.GetFromSpotifyJsonAsync<IEnumerable<SpotifyTrack>>($"/v1/albums/{albumId}/tracks");
}

public async Task<IEnumerable<SpotifyTrack>> GetAlbumTracks(SpotifyAlbum album)
{
return await GetAlbumTracks(album.Id);
}
}
}
27 changes: 27 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/ArtistEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using SpotNetCore.Models;

namespace SpotNetCore.Endpoints
{
public class ArtistEndpoint
{
private readonly HttpClient _httpClient;

public ArtistEndpoint(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async Task<IEnumerable<SpotifyTrack>> GetArtistTopTracks(string artistId)
{
return await _httpClient.GetFromSpotifyJsonAsync<IEnumerable<SpotifyTrack>>($"/v1/artists/{artistId}/top-tracks");
}

public async Task<IEnumerable<SpotifyAlbum>> GetArtistAlbums(string artistId)
{
return await _httpClient.GetFromSpotifyJsonAsync<IEnumerable<SpotifyAlbum>>($"/v1/artists/{artistId}/albums?include_groups=album");
}
}
}
63 changes: 63 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/PlayerEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Net.Http;
using System.Threading.Tasks;
using SpotNetCore.Models;

namespace SpotNetCore.Endpoints
{
public class PlayerEndpoint
{
private readonly HttpClient _httpClient;

internal PlayerEndpoint(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async Task<HttpResponseMessage> Play()
{
var response = await _httpClient.PutAsync("/v1/me/player/play", null);
return response;
}

public async Task<HttpResponseMessage> Pause()
{
var response = await _httpClient.PutAsync("/v1/me/player/pause", null);
return response;
}

public async Task<HttpResponseMessage> Next()
{
var response = await _httpClient.PostAsync("/v1/me/player/next", null);
return response;
}

public async Task<HttpResponseMessage> Previous()
{
var response = await _httpClient.PostAsync("/v1/me/player/previous", null);
return response;
}

public async Task<HttpResponseMessage> Seek(int milliseconds)
{
var response = await _httpClient.PutAsync($"/v1/me/player/seek?position_ms={milliseconds}", null);
return response;
}

public async Task<HttpResponseMessage> Shuffle(bool state)
{
var response = await _httpClient.PutAsync($"/v1/me/player/shuffle?state={state}", null);
return response;
}

public async Task<HttpResponseMessage> Queue(string trackUri)
{
var response = await _httpClient.PostAsync($"/v1/me/player/queue?uri={trackUri}", null);
return response;
}

public async Task<SpotifyPlayerContext> Player()
{
return await _httpClient.GetFromSpotifyJsonAsync<SpotifyPlayerContext>("/v1/me/player");
}
}
}
22 changes: 22 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/PlaylistEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using SpotNetCore.Models;

namespace SpotNetCore.Endpoints
{
public class PlaylistEndpoint
{
private readonly HttpClient _httpClient;

public PlaylistEndpoint(HttpClient httpClient)
{
_httpClient = httpClient;
}

public Task<IEnumerable<SpotifyPlaylistTrack>> GetPlaylistTracks(string playlistId)
{
return _httpClient.GetFromSpotifyJsonAsync<IEnumerable<SpotifyPlaylistTrack>>($"/v1/playlists/{playlistId}/tracks");
}
}
}
46 changes: 46 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/SearchEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using SpotNetCore.Models;

namespace SpotNetCore.Endpoints
{
public class SearchEndpoint
{
private readonly HttpClient _httpClient;

public SearchEndpoint(HttpClient httpClient)
{
_httpClient = httpClient;
}

private async Task<SpotifySearchResult> Search(string query, string type, int limit = 10, int offset = 0)
{
return await _httpClient.GetFromSpotifyJsonAsync<SpotifySearchResult>($"/v1/search?q={query}&type={type}&limit={limit}&offset={offset}");
}

public async Task<IEnumerable<SpotifyTrack>> SearchTracks(string query, int limit = 10, int offset = 0)
{
var data = await Search(query, "track", limit, offset);
return data.Tracks.Items;
}

public async Task<IEnumerable<SpotifyAlbum>> SearchAlbums(string query, int limit = 10, int offset = 0)
{
var data = await Search(query, "album", limit, offset);
return data.Albums.Items;
}

public async Task<IEnumerable<SpotifyPlaylist>> SearchPlaylists(string query, int limit = 10, int offset = 0)
{
var data = await Search(query, "playlist", limit, offset);
return data.Playlists.Items;
}

public async Task<IEnumerable<SpotifyArtist>> SearchArtists(string query, int limit = 10, int offset = 0)
{
var data = await Search(query, "artist", limit, offset);
return data.Artists.Items;
}
}
}
36 changes: 36 additions & 0 deletions SpotNetCore/SpotNetCore/Implementation/AppConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace SpotNetCore.Implementation
{
public class AppConstants
{
public static readonly string Prompt = "Spotify> ";
public static readonly string SuccessHtml = @"
<html style='font-family: sans-serif;'>
<head><title>SpotNetCore - Spotify | Authentication Succeed</title></head>
<body style='text-align: center;'>
<header>
<h1>SpotNetCore</h1>
</header>
<main style='border: 1px solid lightgrey; margin: auto; width: 600px; padding-bottom: 15px;'>
<h2 style='color: limegreen;'>Authentication complete</h2>
<div>You can return to the application. Feel free to close this browser tab.</div>
</main>
</body>
</html>";

public static readonly string ErrorHtml = @"
<html style='font-family: sans-serif;'>
<head><title>SpotNetCore - Spotify | Authentication Failed</title></head>
<body style='text-align: center;'>
<header>
<h1>SpotNetCore</h1>
</header>
<main style='border: 1px solid lightgrey; margin: auto; width: 600px; padding-bottom: 15px;'>
<h2 style='color: salmon;'>Authentication failed</h2>
<div><b>Error details:</b> error {0} error_description: {1}</div>
<br>
<div>You can return to the application. Feel free to close this browser tab.</div>
</main>
</body>
</html>";
}
}
Loading