/// <summary> /// Registers a guest account on server and logins with that in background. /// <para>This is preferable to using <see cref="LoginAsGuest"/>, unless your code is already /// running from a background thread.</para> /// </summary> /// <param name="callback">callback notified upon receiving server response or any error in the /// process. Server response is login session details wrapped in a <c>BacktoryResponse</c>.</param> public static void LoginAsGuestInBackground(Action <BacktoryResponse <LoginResponse> > callback) { // Simplifying this by removing "BacktoryUser" type parameter leads to error though compiler suggests, but why?! Backtory.RestClient.ExecuteAsync <BacktoryUser>(GuestRegisterRequest(), response => { // **this part will be called on background thread! (Since we're using restsharp async method)** // if guest register failed don't proceed to login if (!response.IsSuccessful()) { Backtory.Dispatch(() => BacktoryResponse <LoginResponse> .Unknown(response.ErrorMessage)); return; } var guest = response.Data; var loginResponse = Backtory.ExecuteRequest <LoginResponse>(LoginRequest(guest.Username, guest.Password)); if (loginResponse.Successful) { DispatchSaveCurrentUser(guest); DispatchSaveGuestPassword(guest.Password); DispatchSaveLoginInfo(loginResponse.Body); } Backtory.Dispatch(() => callback(loginResponse)); }); }
/// <summary> /// Synchronously changes the user password in backtory server and returns its response. /// <para>Typically, you should use <see cref="ChangePasswordInBackground(string, string, Action{BacktoryResponse{object}})"/> /// instead of this, unless you are managing your own threading.</para> /// <para><b>You can't change a guest users's password.</b></para> /// </summary> /// <param name="oldPassword">old password user wants to change</param> /// <param name="newPassword">newPassword new password user wants to change old one into it.</param> /// <exception cref="InvalidOperationException">If you call this on a guest user</exception> /// <returns>Server response containing no body</returns> public BacktoryResponse <object> ChangePassword(string oldPassword, string newPassword) { if (Guest) { throw new InvalidOperationException("guest user con not change it's password"); } return(Backtory.ExecuteRequest <object>(ChangePassRequest(oldPassword, newPassword))); }
// TODO: check if user been changed in at least on field. /// <summary> /// Synchronously updates this user changes in backtory server. /// <para>Typically, you should use <see cref="UpdateUserInBackground(Action{BacktoryResponse{BacktoryUser}})"/> /// instead of this, unless you are managing your own threading.</para> /// </summary> /// <returns>updated user wrapped in a <c>BacktoryResponse</c></returns> public BacktoryResponse <BacktoryUser> UpdateUser() { var updateResponse = Backtory.ExecuteRequest <BacktoryUser>(UpdateUserRequest(this)); if (updateResponse.Successful) { DispatchSaveCurrentUser(updateResponse.Body); } return(updateResponse); }
/// <summary> /// Synchronously converts a guest user to a normal one with passed information /// in backtory server and returns its response. /// <para>You should get the user object by <see cref="GetCurrentUser"/> because it encloses the /// information which backtory server needs to distinct the guest user from others.</para> /// </summary> /// <param name="guestRegistrationParam">information required for converting guest user to normal user</param> /// <returns>newly converted user wrapped in a <c>BacktoryResponse</c></returns> public BacktoryResponse <BacktoryUser> CompleteRegistration(GuestCompletionParam guestRegistrationParam) { var completeRegResponse = Backtory.ExecuteRequest <BacktoryUser>(CompleteRegRequest(guestRegistrationParam)); if (completeRegResponse.Successful) { DispatchSaveCurrentUser(completeRegResponse.Body); } return(completeRegResponse); }
/// <summary> /// Synchronously registers a guest account on server and logins with that. /// <para>Typically, you should use <see cref="LoginAsGuestInBackground(Action{BacktoryResponse{LoginResponse}})"></see> /// instead of this, unless you are managing your own threading.</para> /// <para>Data of guest user automatically stored on this request succession and you can access that with /// <see cref="GetCurrentUser"></see></para> /// </summary> /// <returns>Login session details wrapped in a <c>BacktoryResponse</c>.</returns> public static BacktoryResponse <LoginResponse> LoginAsGuest() { var regResponse = Backtory.ExecuteRequest <BacktoryUser>(GuestRegisterRequest()); if (!regResponse.Successful) { return(BacktoryResponse.Error <BacktoryUser, LoginResponse>(regResponse)); } var guest = regResponse.Body; var loginResponse = Backtory.ExecuteRequest <LoginResponse>(LoginRequest(guest.Username, guest.Password)); if (loginResponse.Successful) { DispatchSaveCurrentUser(guest); DispatchSaveGuestPassword(guest.Password); DispatchSaveLoginInfo(loginResponse.Body); } return(loginResponse); }
/// <summary> /// Synchronously logins the specified user by username and password and returns its response. /// <para>Typically, you should use <see cref="LoginInBackground(string, string, Action{BacktoryResponse{BacktoryUser.LoginResponse}})"/> /// instead of this, unless you are managing your own threading.</para> /// </summary> /// <param name="username">username of application user who wants to login into the app.</param> /// <param name="password">password of application user who wants to login into the app.</param> /// <returns>Login session details wrapped in a <c>BacktoryResponse</c>.</returns> /// <seealso cref="LoginResponse"/> public static BacktoryResponse <LoginResponse> Login(string username, string password) { var loginResponse = Backtory.ExecuteRequest <LoginResponse>(LoginRequest(username, password)); if (loginResponse.Successful) { var userResponse = Backtory.ExecuteRequest <BacktoryUser>(UserByUsernameRequest(username, loginResponse.Body.AccessToken)); if (userResponse.Successful) { DispatchSaveCurrentUser(userResponse.Body); DispatchSaveLoginInfo(loginResponse.Body); } else { BacktoryResponse <LoginResponse> .Unknown(userResponse.Message); Debug.Log("error getting user info by username\n" + userResponse.Message); } } return(loginResponse); }
/// <summary> /// Synchronously logouts the current user from backtory server and clears every data related to /// user. After this method <see cref="GetCurrentUser"/> will return <c>null.</c> /// <para>Typically, you should use <see cref="LogoutInBackground"/> /// instead of this, unless you are managing your own threading</para> /// </summary> public static void Logout() { Backtory.ExecuteRequest <object>(LogoutRequest(ClearStorageAndReturnRefreshToken())); }
// TODO change to getCurrentUser by access token internal static BacktoryResponse <BacktoryUser> GetUserByUsername(string username) { return(Backtory.ExecuteRequest <BacktoryUser>(UserByUsernameRequest(username))); }
/// <summary> /// Synchronously registers this user on backtory servers and returns its response. /// This is separate from activation process /// but if activation not set in Backtory panel, user will be active after this method execution. /// <para>Typically, you should <see cref="RegisterInBackground(Action{BacktoryResponse{BacktoryUser}})"/>use instead of this, /// unless you are managing your own threading.</para> /// </summary> /// <returns>Backtory user registered on server wrapped in a <c>BacktoryResponse</c></returns> public BacktoryResponse <BacktoryUser> Register() { return(Backtory.ExecuteRequest <BacktoryUser>(RegisterRequest(this))); }
/// <summary> /// Synchronously gets the current user position in this leaderboard and returns its response. /// </summary> /// <returns>a LeaderBoardRank object which presents current user rank in this leaderboard wrapped /// in a <see cref="BacktoryResponse{T}"/></returns> /// <seealso cref="LeaderBoardRank"/> public BacktoryResponse <LeaderBoardRank> GetPlayerRank() { return(Backtory.ExecuteRequest <LeaderBoardRank>(PlayerRankRequest())); }
/// <summary> /// Synchronously gets players in leaderboard who are around of current user. /// </summary> /// <param name="count">number of players around of current user you want to receive. Half of this number /// would be on top of current user and half would be under. Limited to 20.</param> /// <returns> callback notified upon receiving server response or any error in the /// process. Server response is a a LeaderBoardResponse object presenting players info /// wrapped in a <see cref="BacktoryResponse{T}"/></returns> public BacktoryResponse <LeaderBoardResponse> GetPlayersAroundMe(int count) { return(Backtory.ExecuteRequest <LeaderBoardResponse>(AroundMeRequest(count))); }
/// <summary> /// Synchronously gets top players of this leaderboard. /// </summary> /// <param name="count">count number of players in top of leaderboard you want to receive. Limited to 100.</param> /// <returns>a LeaderBoardResponse object presenting players info wrapped in a <see cref="BacktoryResponse{T}"/></returns> public BacktoryResponse <LeaderBoardResponse> GetTopPlayers(int count) { return(Backtory.ExecuteRequest <LeaderBoardResponse>(TopPlayersRequest(count))); }
/// <summary> /// Synchronously sends the argument for backtory cloud function specified with <c>functionName</c> /// waits for execution and returns its response. /// </summary> /// <typeparam name="T"> Type of expected response.</typeparam> /// <param name="functionName">name of cloud function you've set in backtory panel.</param> /// <param name="requestBody">input argument for cloud function.If a String object, will be send intact if anything else will be serialized to json.</param> /// <returns>result of cloud function execution wrapped in a <see cref="BacktoryResponse{T}"/></returns> public static BacktoryResponse <T> Run <T>(string functionName, object requestBody) where T : class { return(Backtory.ExecuteRequest <T>(instance.CloudCodeRequest(functionName, requestBody, typeof(T)))); }
/// <summary> /// Synchronously sends this event to update its corresponding leaderboard and returns its response. /// <para>Typically, you should use {@link #sendAsync(BacktoryCallBack)} instead of this, unless /// you are managing your own threading.</para> /// </summary> /// <returns>Empty body wrapped in a <see cref="BacktoryResponse{T}"/>.</returns> /// <seealso cref="BacktoryLeaderBoard"/> public BacktoryResponse <object> Send() { InitFieldsUsingAnnotations(this); // TODO: some precondition check e.g. values are numbers return(Backtory.ExecuteRequest <object>(SendEventRequest(this))); }