Exemplo n.º 1
0
        /// <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();
                });
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Fetches all songs whose name starts with the given title.
 /// </summary>
 /// <param name="title">Song title</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchByTitleCoincidences(
     string title, Action <List <Song> > onSuccess, Action <NetworkResponse> onFailure, Action onError
     )
 {
     RestSharpTools.GetAsyncMultiple <Song>("/song/search/" + title, null, JSON_EQUIVALENTS, (response) => {
         if (response.Model.Count == 0)
         {
             onSuccess(response.Model);
             return;
         }
         foreach (var song in response.Model)
         {
             Album.FetchById(song.AlbumId, (album) => {
                 song.Album = album;
                 Genre.FetchById(song.GenreId, (genre) => {
                     song.Genre = genre;
                     song.FetchArtists(() => {
                         onSuccess(response.Model);
                     }, null, null);
                 }, null, null);
             }, null, null);
         }
     }, onFailure, () => {
         Console.WriteLine("Exception@Song->FetchByTitleCoincidences()");
         onError?.Invoke();
     });
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deletes the song from this playlist.
 /// </summary>
 /// <param name="song">Song to delete</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public void DeleteSong(Song song, Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.DeleteAsync("/playlist/" + PlaylistId + "/songs/" + song.SongId, null, (response) => {
         onSuccess();
     }, onFailure, () => {
         Console.WriteLine("Exception@Playlist->DeleteSong()");
         onError?.Invoke();
     });
 }
Exemplo n.º 4
0
 /// <summary>
 /// Fetches all account playlists.
 /// </summary>
 /// <param name="accountId">Account ID</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchByAccountId(int accountId, Action <List <Playlist> > onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsyncMultiple <Playlist>("/account/" + accountId + "/playlists", null, JSON_EQUIVALENTS, (response) => {
         onSuccess(response.Model);
     }, onFailure, () => {
         Console.WriteLine("Exception@Playlist->FetchByAccountId()");
         onError?.Invoke();
     });
 }
Exemplo n.º 5
0
 /// <summary>
 /// Fetches all genres.
 /// </summary>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchAll(Action <List <Genre> > onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsyncMultiple <Genre>("/genres", null, JSON_EQUIVALENTS, (response) => {
         onSuccess(response.Model);
     }, onFailure, () => {
         onError?.Invoke();
         Console.WriteLine("Exception@Genre->FetchAll()");
     });
 }
Exemplo n.º 6
0
 /// <summary>
 /// Fetches this song artists.
 /// </summary>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public void FetchArtists(Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsyncMultiple <Artist>("/song/" + SongId + "/artists", null, Artist.JSON_EQUIVALENTS, (response) => {
         this.Artists = response.Model;
         onSuccess();
     }, onFailure, () => {
         Console.WriteLine("Exception@Album->FetchArtists()");
         onError?.Invoke();
     });
 }
Exemplo n.º 7
0
 /// <summary>
 /// Deletes an account song.
 /// </summary>
 /// <param name="accountSong">Account song to delete</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public void DeleteAccountSong(AccountSong accountSong, Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.DeleteAsync("/account/" + AccountId + "/accountsong/" + accountSong.AccountSongId, null, (response) => {
         AccountSongs.Remove(accountSong);
         onSuccess?.Invoke();
     }, onFailure, () => {
         Console.WriteLine("Exception@Account->DeleteAccountSong() -> ");
         onError?.Invoke();
     });
 }
Exemplo n.º 8
0
 /// <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();
     });
 }
Exemplo n.º 9
0
 /// <summary>
 /// Fetches an artist by its ID.
 /// </summary>
 /// <param name="artistId">Artist ID</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchById(int artistId, Action <Artist> onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsync <Artist>("/artist/" + artistId, null, JSON_EQUIVALENTS, (response) => {
         onSuccess(response.Model);
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
     }, () => {
         Console.WriteLine("Exception@Artist->FetchById()");
         onError?.Invoke();
     });
 }
Exemplo n.º 10
0
 /// <summary>
 /// Fetches an artist by its starting artistic name.
 /// </summary>
 /// <param name="artisticName">Artist artistic name</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchByArtisticNameCoincidences(
     string artisticName, Action <List <Artist> > onSuccess, Action <NetworkResponse> onFailure, Action onError
     )
 {
     RestSharpTools.GetAsyncMultiple <Artist>("/artist/search/" + artisticName, null, JSON_EQUIVALENTS, (response) => {
         onSuccess(response.Model);
     }, onFailure, () => {
         Console.WriteLine("Exception@Artist->FetchByArtisticNameCoincidences()");
         onError?.Invoke();
     });
 }
Exemplo n.º 11
0
 /// <summary>
 /// Fetches a genre by its ID.
 /// </summary>
 /// <param name="genreId">Genre ID</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchById(int genreId, Action <Genre> onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsync <Genre>("/genre/" + genreId, null, JSON_EQUIVALENTS, (response) => {
         onSuccess(response.Model);
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
     }, () => {
         Console.WriteLine("Exception@Genre->FetchById()");
         onError();
     });
 }
Exemplo n.º 12
0
        /// <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();
            });
        }
Exemplo n.º 13
0
        /// <summary>
        /// Undislikes a song.
        /// </summary>
        /// <param name="song">Song to undislike</param>
        /// <param name="onSuccess">On success</param>
        /// <param name="onFailure">On failure</param>
        /// <param name="onError">On error</param>
        public void UndislikeSong(Song song, Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
        {
            var data = new {
                account_id = AccountId
            };

            RestSharpTools.DeleteAsync("/song/" + song.SongId + "/songdislike", data, (response) => {
                onSuccess();
            }, onFailure, () => {
                Console.WriteLine("Exception@Account->DislikeSong()");
                onError?.Invoke();
            });
        }
Exemplo n.º 14
0
 /// <summary>
 /// Fetches an active subscription.
 /// </summary>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 /// <param name="onFinish">It's executed at the end of every case</param>
 public void FetchSubscription(Action <Subscription> onSuccess, Action <NetworkResponse> onFailure, Action onError, Action onFinish = null)
 {
     RestSharpTools.GetAsync <Subscription>("/subscription", null, Subscription.JSON_EQUIVALENTS, (response) => {
         onSuccess(response.Model);
         onFinish?.Invoke();
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
         onFinish?.Invoke();
     }, () => {
         Console.WriteLine("Exception@Account->FetchSubscription()");
         onError?.Invoke();
         onFinish?.Invoke();
     });
 }
Exemplo n.º 15
0
 /// <summary>
 /// Adds new account songs.
 /// </summary>
 /// <param name="fileRoutes">Files to add</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public void AddAccountSongs(string[] fileRoutes, Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.PostMultimediaAsync <AccountSong>(
         "/account/" + AccountId + "/accountsongs", null, fileRoutes,
         AccountSong.JSON_EQUIVALENTS,
         (response) => {
         this.AccountSongs = this.AccountSongs.Union(response.Model).ToList();
         onSuccess?.Invoke();
     }, onFailure, () => {
         Console.WriteLine("Exception@Account->AddAccountSongs()");
         onError?.Invoke();
     }
         );
 }
Exemplo n.º 16
0
 /// <summary>
 /// Fetches artist data attached to this account.
 /// </summary>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 /// <param name="onFinish">It's executed at the end of every case</param>
 public void FetchArtist(Action onSuccess, Action <NetworkResponse> onFailure, Action onError, Action onFinish = null)
 {
     RestSharpTools.GetAsync <Artist>("/account/" + AccountId + "/artist", null, Artist.JSON_EQUIVALENTS, (response) => {
         this.Artist = response.Model;
         onSuccess();
         onFinish?.Invoke();
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
         onFinish?.Invoke();
     }, () => {
         Console.WriteLine("Exception@Account->FetchArtist()");
         onError();
         onFinish?.Invoke();
     });
 }
Exemplo n.º 17
0
 /// <summary>
 /// Checks if the song is in this playlist.
 /// </summary>
 /// <param name="song">Song to check</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public void ContainsSong(Song song, Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsync <Song>(
         "/playlist/" + PlaylistId + "/songs/" + song.SongId,
         null, Song.JSON_EQUIVALENTS,
         (response) => {
         onSuccess();
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
     }, () => {
         Console.WriteLine("Exception@Playlist->ContainsSong()");
         onError();
     }
         );
 }
Exemplo n.º 18
0
        /// <summary>
        /// Checks if the song was liked before.
        /// </summary>
        /// <param name="song">Song</param>
        /// <param name="onSuccess">On success</param>
        /// <param name="onFailure">On failure</param>
        /// <param name="onError">On error</param>
        public void HasLikedSong(Song song, Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
        {
            var data = new {
                account_id = AccountId
            };

            RestSharpTools.GetAsync("/song/" + song.SongId + "/songlike", data, (response) => {
                onSuccess();
            }, (errorResponse) => {
                onFailure?.Invoke(errorResponse);
            }, () => {
                Console.WriteLine("Exception@Account->HasLikedSong()");
                onError?.Invoke();
            });
        }
Exemplo n.º 19
0
 /// <summary>
 /// Fetches a account song by its ID.
 /// </summary>
 /// <param name="SongId">Song ID</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchById(int accountSongId, Action <AccountSong> onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsync <AccountSong>(
         "/account/" + Session.Account.AccountId + "/accountsong/" + accountSongId,
         null, JSON_EQUIVALENTS,
         (response) => {
         onSuccess(response.Model);
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
     }, () => {
         Console.WriteLine("Exception@Song->FetchById()");
         onError?.Invoke();
     }
         );
 }
Exemplo n.º 20
0
 /// <summary>
 /// Fetches all account songs of this account.
 /// </summary>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public void FetchAccountSongs(Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsyncMultiple <AccountSong>(
         "/account/" + AccountId + "/accountsongs", null,
         AccountSong.JSON_EQUIVALENTS,
         (response) => {
         this.AccountSongs = response.Model;
         onSuccess?.Invoke();
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
     }, () => {
         Console.WriteLine("Exception@Account->FetchAccountSongs()");
         onError?.Invoke();
     }
         );
 }
Exemplo n.º 21
0
        /// <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();
            });
        }
Exemplo n.º 22
0
 /// <summary>
 /// Fetches a song by its ID.
 /// </summary>
 /// <param name="SongId">Song ID</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchById(int songId, Action <Song> onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsync <Song>("/song/" + songId, null, JSON_EQUIVALENTS, (response) => {
         Album.FetchById(response.Model.AlbumId, (album) => {
             response.Model.Album = album;
             Genre.FetchById(response.Model.GenreId, (genre) => {
                 response.Model.Genre = genre;
                 response.Model.FetchArtists(() => {
                     onSuccess(response.Model);
                 }, null, null);
             }, null, null);
         }, null, null);
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
     }, () => {
         Console.WriteLine("Exception@Song->FetchById()");
         onError?.Invoke();
     });
 }
Exemplo n.º 23
0
        /// <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();
            });
        }
Exemplo n.º 24
0
 /// <summary>
 /// Fetches all songs attached to this genre.
 /// </summary>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public void FetchSongs(Action <List <Song> > onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsyncMultiple <Song>("/genre/" + GenreId + "/songs", null, Song.JSON_EQUIVALENTS, (response) => {
         List <Song> songs = response.Model;
         foreach (var song in songs)
         {
             Album.FetchById(song.AlbumId, (album) => {
                 song.Album = album;
                 Genre.FetchById(song.GenreId, (genre) => {
                     song.Genre = genre;
                     song.FetchArtists(() => {
                         onSuccess(songs);
                     }, null, null);
                 }, null, null);
             }, null, null);
         }
     }, onFailure, () => {
         onError?.Invoke();
         Console.WriteLine("Exception@Playlist->FetchSongs()");
     });
 }
Exemplo n.º 25
0
 /// <summary>
 /// Fetches an album by its starting name.
 /// </summary>
 /// <param name="name">Album name</param>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public static void FetchByNameCoincidences(
     string name, Action <List <Album> > onSuccess, Action <NetworkResponse> onFailure, Action onError
     )
 {
     RestSharpTools.GetAsyncMultiple <Album>("/album/search/" + name, null, JSON_EQUIVALENTS, (response) => {
         if (response.Model.Count == 0)
         {
             onSuccess(response.Model);
             return;
         }
         foreach (var album in response.Model)
         {
             album.FetchArtists(() => {
                 onSuccess(response.Model);
             }, null, null);
         }
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
     }, () => {
         Console.WriteLine("Exception@Album->FetchByNameCoincidences()");
         onError?.Invoke();
     });
 }
Exemplo n.º 26
0
 /// <summary>
 /// Fetches all this album songs.
 /// </summary>
 /// <param name="onSuccess">On success</param>
 /// <param name="onFailure">On failure</param>
 /// <param name="onError">On error</param>
 public void FetchSongs(Action onSuccess, Action <NetworkResponse> onFailure, Action onError)
 {
     RestSharpTools.GetAsyncMultiple <Song>(
         "/album/" + AlbumId + "/songs", null, Song.JSON_EQUIVALENTS,
         (response) => {
         this.Songs = response.Model;
         foreach (var song in Songs)
         {
             song.Album = this;
             Genre.FetchById(song.GenreId, (genre) => {
                 song.Genre = genre;
                 song.FetchArtists(() => {
                     onSuccess();
                 }, null, null);
             }, null, null);
         }
     }, (errorResponse) => {
         onFailure?.Invoke(errorResponse);
     }, () => {
         Console.WriteLine("Exception@Album->FetchSongs()");
         onError?.Invoke();
     }
         );
 }
Exemplo n.º 27
0
 /// <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();
     });
 }