// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Threading.Tasks; using osu.Framework.Bindables; using osu.Game.Localisation; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; using osu.Game.Online.Notifications.WebSocket; using osu.Game.Users; namespace osu.Game.Online.API { public interface IAPIProvider { /// /// The local user. /// IBindable LocalUser { get; } /// /// The user's friends. /// IBindableList Friends { get; } /// /// The current user's activity. /// IBindable Activity { get; } /// /// The current user's online statistics. /// IBindable Statistics { get; } /// /// The language supplied by this provider to API requests. /// Language Language { get; } /// /// Retrieve the OAuth access token. /// string AccessToken { get; } /// /// Returns whether the local user is logged in. /// bool IsLoggedIn { get; } /// /// The last username provided by the end-user. /// May not be authenticated. /// string ProvidedUsername { get; } /// /// The URL endpoint for this API. Does not include a trailing slash. /// string APIEndpointUrl { get; } /// /// The root URL of the website, excluding the trailing slash. /// string WebsiteRootUrl { get; } /// /// The version of the API. /// int APIVersion { get; } /// /// The last login error that occurred, if any. /// Exception? LastLoginError { get; } /// /// The current connection state of the API. /// This is not thread-safe and should be scheduled locally if consumed from a drawable component. /// IBindable State { get; } /// /// Queue a new request. /// /// The request to perform. void Queue(APIRequest request); /// /// Perform a request immediately, bypassing any API state checks. /// /// /// Can be used to run requests as a guest user. /// /// The request to perform. void Perform(APIRequest request); /// /// Perform a request immediately, bypassing any API state checks. /// /// /// Can be used to run requests as a guest user. /// /// The request to perform. Task PerformAsync(APIRequest request); /// /// Attempt to login using the provided credentials. This is a non-blocking operation. /// /// The user's username. /// The user's password. void Login(string username, string password); /// /// Provide a second-factor authentication code for authentication. /// /// The 2FA code. void AuthenticateSecondFactor(string code); /// /// Log out the current user. /// void Logout(); /// /// Sets Statistics bindable. /// void UpdateStatistics(UserStatistics newStatistics); /// /// Constructs a new . May be null if not supported. /// /// The name of the client this connector connects for, used for logging. /// The endpoint to the hub. /// Whether to use MessagePack for serialisation if available on this platform. IHubClientConnector? GetHubConnector(string clientName, string endpoint, bool preferMessagePack = true); /// /// Accesses the used to receive asynchronous notifications from web. /// INotificationsClient NotificationsClient { get; } /// /// Creates a instance to use in order to chat. /// IChatClient GetChatClient(); /// /// Create a new user account. This is a blocking operation. /// /// The email to create the account with. /// The username to create the account with. /// The password to create the account with. /// Any errors encoutnered during account creation. RegistrationRequest.RegistrationRequestErrors? CreateAccount(string email, string username, string password); } }