This repository has been archived by the owner on Aug 10, 2020. It is now read-only.
/
Library.cs
71 lines (63 loc) · 2.35 KB
/
Library.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Spotify's Library API contains no objects, but rather returns objects from
* the current user's library. As such, this API implementation is placed into
* appropriate classes.
* Note: Library requires a specific scope permission to access.
*
* More info here:
* https://developer.spotify.com/console/library/
*/
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SpotifyDotNet {
public partial class PublicUser : SpotifyBaseObject {
#region GET
/// <summary>
/// Retrieve current user's saved albums.
/// </summary>
public static async Task<Page<Album>> GetSavedAlbumsAsync(
int offset = 0, int limit = 20) {
if (!SpotifyApi.IsAuthenticated) return null;
string endpoint = string.Format("/me/albums?offset={0}&limit={1}", offset, limit);
string albums = await SpotifyApi.ApiGetAsync(endpoint);
return JsonConvert.DeserializeObject<Page<Album>>(albums);
}
/// <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);
}
///<summary>
/// Check for a list of albums within current users saved albums.
/// </summary>
public static async Task<bool[]> CheckSavedAlbumsAsync(string[] ids) {
return await _CheckSavedAsync(ids, "albums");
}
///<summary>
/// Check for a list of albums within current users saved albums.
/// </summary>
public static async Task<bool[]> CheckSavedTracksAsync(string[] ids) {
return await _CheckSavedAsync(ids, "tracks");
}
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);
}
#endregion
#region DELETE
#endregion
#region PUT
#endregion
}
}