/// <summary> /// Saves this playlist data. If it does not exist, it will be created; otherwise, /// it will be updated. /// </summary> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> public void Save(Action <Playlist> onSuccess, Action <NetworkResponse> onFailure, Action onError) { var playlistData = new { playlist_id = PlaylistId, account_id = AccountId, name = Name }; if (PlaylistId == 0) { RestSharpTools.PostAsync <Playlist>("/playlist", playlistData, JSON_EQUIVALENTS, (response) => { onSuccess(response.Model); }, onFailure, () => { Console.WriteLine("Exception@Playlist->Save()"); onError?.Invoke(); }); } else { RestSharpTools.PutAsync <Playlist>("/playlist/" + PlaylistId, playlistData, JSON_EQUIVALENTS, (response) => { onSuccess(response.Model); }, onFailure, () => { Console.WriteLine("Exception@Playlist->Save()"); onError?.Invoke(); }); } }
/// <summary> /// Gets a new subscription. /// </summary> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> public void Subscribe(Action <Subscription> onSuccess, Action <NetworkResponse> onFailure, Action onError) { RestSharpTools.PostAsync <Subscription>("/subscription", null, Subscription.JSON_EQUIVALENTS, (response) => { Subscription = response.Model; onSuccess(response.Model); }, onFailure, () => { Console.WriteLine("Exception@Account->Subscribe()"); onError?.Invoke(); }); }
/// <summary> /// Adds a song to this playlist. /// </summary> /// <param name="song">Song to add</param> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> public void AddSong(Song song, Action onSuccess, Action <NetworkResponse> onFailure, Action onError) { var data = new { song_id = song.SongId }; RestSharpTools.PostAsync("/playlist/" + PlaylistId + "/song", data, (response) => { onSuccess(); }, onFailure, () => { Console.WriteLine("Exception@Playlist->AddSong()"); onError?.Invoke(); }); }
/// <summary> /// Dislikes a song. /// </summary> /// <param name="song">Song to dislike</param> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> public void DislikeSong(Song song, Action onSuccess, Action <NetworkResponse> onFailure, Action onError) { var data = new { account_id = AccountId }; RestSharpTools.PostAsync("/song/" + song.SongId + "/songdislike", data, (response) => { onSuccess(); }, onFailure, () => { Console.WriteLine("Exception@Account->DislikeSong()"); onError?.Invoke(); }); }
/// <summary> /// Registers this new account. /// </summary> /// <param name="isArtist">Register as an artist too</param> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> /// <param name="artisticName">Artistic name if should be registered as an artist too</param> public void Register(bool isArtist, Action onSuccess, Action <NetworkResponse> onFailure, Action onError, string artisticName = null) { var accountData = new { email = Email, password = Password, name = Name, last_name = LastName, is_artist = isArtist, artistic_name = artisticName }; RestSharpTools.PostAsync("/auth/register", accountData, (response) => { onSuccess(); }, onFailure, () => { Console.WriteLine("Exception@Account->Register()"); onError?.Invoke(); }); }
/// <summary> /// Attempts to log in with given credentials. /// </summary> /// <param name="email">Email</param> /// <param name="password">Hashed password</param> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> public static void Login( string email, string password, Action <Account> onSuccess, Action <NetworkResponse> onFailure, Action onError ) { var accountData = new { email, password }; RestSharpTools.PostAsync <Account>("/auth/login", accountData, JSON_EQUIVALENTS, (response) => { Session.AccessToken = response.Json["access_token"]; Session.Account = response.Model; onSuccess(response.Model); }, onFailure, () => { Console.WriteLine("Exception@Account->Login()"); onError?.Invoke(); }); }
/// <summary> /// Creates this album with its songs. /// </summary> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> public void Save(Action onSuccess, Action <NetworkResponse> onFailure, Action onError) { string[] filesRoutes = new string[Songs.Count]; for (int i = 0; i < Songs.Count; i++) { filesRoutes[i] = Songs.ElementAt(i).SongLocation; } RestSharpTools.PostMultimediaAsync <Song>("album/songs", null, filesRoutes, Song.JSON_MIN_EQUIVALENTS, (responseSongs) => { filesRoutes = new string[] { ImageLocation }; RestSharpTools.PostMultimediaAsync <Album>("album/image", null, filesRoutes, JSON_IMAGE_EQUIVALENT, (responseImage) => { List <object> artistsId = new List <object>(); foreach (Artist artist in Artists) { artistsId.Add(new { artist_id = artist.ArtistId }); } List <object> newSongs = new List <object>(); int i = 0; foreach (Song song in Songs) { List <object> songArtistsId = new List <object>(); foreach (Artist artist in song.Artists) { songArtistsId.Add(new { artist_id = artist.ArtistId }); } newSongs.Add(new { genre_id = song.GenreId, title = song.Title, duration = responseSongs.Model.ElementAt(i).Duration, song_location = responseSongs.Model.ElementAt(i).SongLocation, artists_id = songArtistsId }); i++; } var albumData = new { type = Type, name = Name, launch_year = LaunchYear, discography = Discography, image_location = responseImage.Model.ElementAt(0).ImageLocation, artists_id = artistsId, new_songs = newSongs }; RestSharpTools.PostAsync("/album", albumData, (responseAlbum) => { onSuccess(); }, onFailure, () => { Console.WriteLine("Exception@Album->Save()"); onError?.Invoke(); }); }, onFailure, () => { Console.WriteLine("Exception@Album->Save()"); onError?.Invoke(); }); }, onFailure, () => { Console.WriteLine("Exception@Album->Save()"); onError?.Invoke(); }); }