private SCPlaylistObject playListObject, plTestObject;
public string TrackList;
private List<SCTrackObjects> TListTest;
/// <summary>
/// Deserializes JSON data into object from string
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonString"></param>
/// <returns>json object</returns>
public static T Deserialize<T>(string jsonString)
{
DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(T));
MemoryStream MemStream = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));
T result = (T)deserializer.ReadObject(MemStream);
return result;
}
public async Task<string> GetUserTracks() // Async Call to get user id
{
try
{
responseText = await GetjsonStream();
SCUserID = userObject.id;
TrackList = await GetTracks();
TList = Deserialize<List<SCTrackObjects>>(TrackList);
return TrackList;
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.Message);
return ex.Message;
}
public async Task<string> GetTracks() //Function to read from given url
{
HttpClient client = new HttpClient();
string url = SCLink + SCAPIUsers + SCUserID + "/tracks?client_id=" + soundcloudAPI;
HttpResponseMessage response = await client.GetAsync(url);
HttpResponseMessage v = new HttpResponseMessage();
return await response.Content.ReadAsStringAsync();
}
}
public async Task<string> GetjsonStream() //Function to read from given url
{
HttpClient client = new HttpClient();
string url = SCLink + SCAPIUsers + SCNameField + ".json?client_id=" + soundcloudAPI;
HttpResponseMessage response = await client.GetAsync(url);
HttpResponseMessage v = new HttpResponseMessage();
return await response.Content.ReadAsStringAsync();
}