/// <summary> /// Set to your fans or Remove from your fans. /// </summary> /// <param name="ArtistId"></param> /// <param name="Artists"></param> /// <returns></returns> public static bool SetUserFan(string ArtistId, User_Authentication authUser) { try { //Set the Artist to Fans var RestClient = new RestClient(authUser.token.URL); var Request = new RestRequest("users/artists?relation='fan'"); Request.AddParameter("client_id", authUser.token.Client_ID); Request.AddParameter("access_token", authUser.token.Access_Token); Request.AddParameter("artist_id", ArtistId); var tRsponse = RestClient.Execute(Request); } catch { return(false); } //set to the Csv File string Path = System.Reflection.Assembly.GetExecutingAssembly().Location; int length = Path.IndexOf("Debug\\"); Path = Path.Substring(0, length); Path += "Debug\\UserArtists.csv"; Artists art = GetArtistFromCsv(ArtistId, Path); SetArtistCsv(art); SetUserFan(ArtistId, authUser); return(true); }
public static bool AddTrackToFavorites(User_Authentication auth, string trackid) { try { if (auth.token.Expiring_Date < DateTime.Now) { auth.RefreshAccessToken(); } var RestClient = new RestClient(auth.token.URL); var Request = new RestRequest("setuser/favorite", Method.POST); Request.AddParameter("client_id", auth.token.Client_ID); Request.AddParameter("access_token", auth.token.Access_Token); Request.AddParameter("track_id", trackid); var tResponse = RestClient.Execute(Request); SearchTracks tracks = JsonConvert.DeserializeObject <SearchTracks>(tResponse.Content); if (tracks.headears.status == "Ok") { return(true); } return(true); } catch { return(false); } }
/// <summary> /// Check if the artists saved in the csv file are identical to Http data or not. /// </summary> /// <param name="Csvlist"></param> /// <param name="userauth"></param> /// <returns>List Of Artists</returns> public static List <Artists> CheckSimilarty(List <Artists> Csvlist, User_Authentication userauth) { List <Artists> Rest = GetRestArtists(userauth); if (!Rest.Equals(Csvlist)) { UpdateCsvArtists(Rest); } return(Rest); }
/// <summary> /// Get The user using http request and then update CSV if not similar. /// </summary> /// <returns>User</returns> public static User GetUser(User_Authentication _userAuth) { User CSVuser = CsvUser(); User RestUser = RestRequest(_userAuth); if (!RestUser.Equals(CSVuser)) { UpdateCSV(RestUser); } return(RestUser); }
/// <summary> /// it is prefered to use GetCsvArtist() insted of this method to check first if there are a csv file of your artist /// </summary> /// <param name="authUser"></param> /// <returns>List of Artists</returns> public static List <Artists> GetRestArtists(User_Authentication authUser) { try { var RestClient = new RestClient(authUser.token.URL); var Request = new RestRequest("users/artists"); Request.AddParameter("client_id", authUser.token.Client_ID); Request.AddParameter("access_token", authUser.token.Access_Token); var tRsponse = RestClient.Execute(Request); UserArtists artists = JsonConvert.DeserializeObject <UserArtists>(tRsponse.Content); return(artists.Artists[0].Artists); } catch { return(null); } }
/// <summary> /// Search about tracks using the namesearch. /// </summary> /// <param name="auth"></param> /// <param name="value"></param> /// <returns></returns> public static List <Tracks> SearchTracks(User_Authentication auth, string value) { if (auth.token.Expiring_Date < DateTime.Now) { auth.RefreshAccessToken(); } var RestClient = new RestClient(auth.token.URL); var Request = new RestRequest("tracks"); Request.AddParameter("client_id", auth.token.Client_ID); Request.AddParameter("namesearch", value); Request.AddParameter("limit", "200"); var tResponse = RestClient.Execute(Request); SearchTracks tracks = JsonConvert.DeserializeObject <SearchTracks>(tResponse.Content); return(tracks.Tracks); }
/// <summary> /// Get the Tracks either single or album tracks as a List of Tracks using the AccessToken in User Authentication object /// </summary> /// <param name="auth"></param> /// <returns></returns> public static List <Tracks> GetRestUserTracks(User_Authentication auth) { if (auth.token.Expiring_Date < DateTime.Now) { auth.RefreshAccessToken(); } var RestClient = new RestClient(auth.token.URL); var Request = new RestRequest("users/tracks"); Request.AddParameter("client_id", auth.token.Client_ID); Request.AddParameter("access_token", auth.token.Access_Token); Request.AddParameter("track_type", "single albumtrack"); var tRsponse = RestClient.Execute(Request); UserTracks tracks = JsonConvert.DeserializeObject <UserTracks>(tRsponse.Content); return(tracks.results[0].tracks); }
/// <summary> /// It is For Getting Artists form the web service, and these artists are public not fans /// </summary> /// <param name="userauth"></param> /// <param name="limit"></param> /// <returns></returns> public static List <JsonPublicArtist> GetPublicArtist(User_Authentication userauth, int limit) { try { PublicArtist PubArtists = new PublicArtist(); RestClient client = new RestClient(userauth.token.URL); var Request = new RestRequest("artists"); Request.AddParameter("client_id", userauth.token.Client_ID); Request.AddParameter("access_token", userauth.token.Access_Token); Request.AddParameter("limit", limit.ToString()); var tRsponse = client.Execute(Request); PubArtists = JsonConvert.DeserializeObject <PublicArtist>(tRsponse.Content); return(PubArtists.results); } catch { return(null); } }
//Private Methods private static User RestRequest(User_Authentication auth) { try { if (auth.token.Expiring_Date < DateTime.Now) { auth.RefreshAccessToken(); } var RestClient = new RestClient(auth.token.URL); var Request = new RestRequest("users"); Request.AddParameter("client_id", auth.token.Client_ID); Request.AddParameter("access_token", auth.token.Access_Token); var tRsponse = RestClient.Execute(Request); JsonUser usr = JsonConvert.DeserializeObject <JsonUser>(tRsponse.Content); return(usr.Users.First()); } catch { return(null); } }
/// <summary> /// This is a way to access the User Fans or liked Artists using GetCsvArtist /// <para>Return a list of artists from csv file if existed and from Http method if csv file not existed</para> /// </summary> /// <param name="authuser"></param> /// <returns>List of Artists</Artist></returns> public static List <Artists> GetCsvArtist(User_Authentication authUser) { List <Artists> Artists = new List <Artists>(); string Path = System.Reflection.Assembly.GetExecutingAssembly().Location; int length = Path.IndexOf("Debug\\"); Path = Path.Substring(0, length); Path += "Debug\\UserArtists.csv"; if (File.Exists(Path)) { Artists = File.ReadAllLines(Path). Skip(1). Select(v => CsvToArtist(v)).ToList(); return(Artists); } else { Artists = GetRestArtists(authUser); UpdateCsvArtists(Artists); return(Artists); } }