/// <summary> /// Logins the specified user by username and password in background. /// <para>This is preferable to using <see cref="Login(string, string)"/>, unless your code is already /// running from a background thread.</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> /// <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> /// <seealso cref="LoginResponse"/> public static void LoginInBackground(string username, string password, Action <BacktoryResponse <LoginResponse> > callback) { Backtory.ExecuteRequestAsync <LoginResponse>(LoginRequest(username, password), loginResopnse => { // this will be called in main thread since we're using backtory API if (loginResopnse.Successful) { Backtory.ExecuteRequestAsync <BacktoryUser>(UserByUsernameRequest(username, loginResopnse.Body.AccessToken), userResponse => { // also on main thread if (userResponse.Successful) { //DispatchSaveCurrentUser(userResponse.Body); //DispatchSaveLoginInfo(loginResopnse.Body); SaveAsCurrentUserInMemoryAndStorage(userResponse.Body); SaveLoginInfo(loginResopnse.Body); callback(loginResopnse); } else { callback(BacktoryResponse <LoginResponse> .Unknown(userResponse.Message)); } }); } else { callback(loginResopnse); } }); }
/// <summary> /// Converts a guest user to a normal one with passed information in background. /// <para>You should get the user object by <see cref="GetCurrentUser"/> because it contains the /// information which backtory server needs to distinct the guest user from others.</para> /// <para>This is preferable to using <see cref="CompleteRegistration(GuestCompletionParam)"/>, /// unless your code is already running from a background thread.</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> /// <param name="callback"></param> public void ChangePasswordInBackground(string oldPassword, string newPassword, Action <BacktoryResponse <object> > callback) { if (Guest) { throw new InvalidOperationException("guest user con not change it's password"); } Backtory.ExecuteRequestAsync(ChangePassRequest(oldPassword, newPassword), callback); }
/// <summary> /// Updates this user changes in backtory server in background. /// <para>This is preferable to using <see cref="UpdateUser"/> /// unless your code is already running from a background thread.</para> /// </summary> /// <param name="callback">backtoryCallBack callback notified upon receiving server response or any error in the /// process. Server response is updated user wrapped in a <c>BacktoryRespone</c></param> public void UpdateUserInBackground(Action <BacktoryResponse <BacktoryUser> > callback) { Backtory.ExecuteRequestAsync <BacktoryUser>(UpdateUserRequest(this), updateResponse => { if (updateResponse.Successful) { SaveAsCurrentUserInMemoryAndStorage(updateResponse.Body); } callback(updateResponse); }); }
/// <summary> /// Converts a guest user to a normal one with passed information in background. /// <para>You should get the user object by <see cref="GetCurrentUser()"/> because it contains the /// information which backtory server needs to distinct the guest user from others.</para> /// <para>This is preferable to using <see cref="CompleteRegistration(GuestCompletionParam)"/>, /// unless your code is already running from a background thread</para> /// </summary> /// <param name="guestRegistrationParam">information required for converting guest user to normal user</param> /// <param name="callback">callback notified upon receiving server response or any error in the /// process. Server response is newly converted user wrapped in a <c>BacktoryResponse</c></param> public void CompleteRegistrationInBackgrond(GuestCompletionParam guestRegistrationParam, Action <BacktoryResponse <BacktoryUser> > callback) { Backtory.ExecuteRequestAsync <BacktoryUser>(CompleteRegRequest(guestRegistrationParam), completeRegResponse => { if (completeRegResponse.Successful) { SaveAsCurrentUserInMemoryAndStorage(completeRegResponse.Body); } callback(completeRegResponse); }); }
/// <summary> /// Logouts the current user from backtory server and clears every data related to current /// user. After this method <see cref="GetCurrentUser"/> will return <c>null</c>. /// <para>This is preferable to using <see cref="Logout"/>, unless your code is already running from a /// background thread.</para> /// </summary> public static void LogoutInBackground() { Backtory.ExecuteRequestAsync <object>(LogoutRequest(ClearStorageAndReturnRefreshToken()), null); }
/// <summary> /// This is for test. /// </summary> /// <returns></returns> internal static void NewAccessTokenInBackground(Action <BacktoryResponse <LoginResponse> > callback) { Backtory.ExecuteRequestAsync(NewAccessTokenRequest(), callback); }
/// <summary> /// Registers this user on Backtory server in background. This is separate from activation process /// but if activation not set in Backtory panel, user will be active after this method execution. /// <para>This is preferable to using <see cref="Register"/>, unless your code is already running from a /// background thread.</para> /// </summary> /// <param name="callback"></param> public void RegisterInBackground(Action <BacktoryResponse <BacktoryUser> > callback) { Backtory.ExecuteRequestAsync(RegisterRequest(this), callback); }
/// <summary> /// Gets players in leaderboard who are around of current user in background. /// </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> /// <param name="backtoryCallBack"> 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}"/></param> public void GetPlayersAroundMeInBackground(int count, Action <BacktoryResponse <LeaderBoardResponse> > backtoryCallBack) { Backtory.ExecuteRequestAsync(AroundMeRequest(count), backtoryCallBack); }
/// <summary> /// Gets the current user position in this leaderboard in background. /// </summary> /// <param name="backtoryCallBack">backtoryCallBack callback notified upon receiving server response or any error in the /// process. Server response is a LeaderBoardRank object which presents current user position in /// leaderboard wrapped in a <see cref="BacktoryResponse{T}"/></param> /// <seealso cref="LeaderBoardRank"/> public void GetPlayerRankInBackground(Action <BacktoryResponse <LeaderBoardRank> > backtoryCallBack) { Backtory.ExecuteRequestAsync(PlayerRankRequest(), backtoryCallBack); }
/// <summary> /// Sends the argument for backtory cloud function specified with <c>functionName</c> in /// background and returns its execution 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> /// <param name="callback">callback notified upon receiving server response or any error in the /// process. Server response is the result of cloud function execution wrapped in a <see cref="BacktoryResponse{T}"/></param> public static void RunInBackground <T>(string functionName, object requestBody, Action <BacktoryResponse <T> > callback) where T : class { Backtory.ExecuteRequestAsync(instance.CloudCodeRequest(functionName, requestBody, typeof(T)), callback); }
/// <summary> /// Sends this event to update its corresponding leaderboard in background. /// <para>This is preferable to using <see cref="Send"/>, 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 a Backtory user registered on server wrapped in a <see cref="BacktoryResponse{T}"/>. /// Server response contains nothing.</param> /// <seealso cref="BacktoryLeaderBoard"/> public void SendInBackground(Action <BacktoryResponse <object> > callBack) { InitFieldsUsingAnnotations(this); Backtory.ExecuteRequestAsync(SendEventRequest(this), callBack); }