-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpotifyApiManager.cs
37 lines (33 loc) · 1.08 KB
/
SpotifyApiManager.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
using System.Net.Http;
using Newtonsoft.Json;
using System.Threading.Tasks;
using System.Diagnostics;
using System;
namespace SpotifySongTracker {
public class TrackInfo {
public string song;
public string artist;
public string album;
public string albumArtUrl;
}
public static class SpotifyApiManager {
private static readonly HttpClient client = new HttpClient();
[Conditional("DEBUG")]
private static void IsDebugCheck(ref bool isDebug) {
isDebug = true;
}
public static async Task<TrackInfo> GetTrackInfo(string query) {
try {
bool isDebug = false;
IsDebugCheck(ref isDebug);
string apiUrl = isDebug ? "http://localhost:8080/api" : "http://outis-spotify-rest.us-east-1.elasticbeanstalk.com/api";
var response = await client.GetStringAsync(string.Format("{0}/track?title={1}", apiUrl, query));
TrackInfo track = JsonConvert.DeserializeObject<TrackInfo>(response);
return track;
} catch (Exception error) {
ErrorLogger.LogToFile(error);
return null;
}
}
}
}