2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-04 14:40:24 +08:00
|
|
|
|
using System;
|
2019-11-29 19:03:14 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-02-16 12:47:30 +08:00
|
|
|
|
using osu.Game.Users;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-02-16 12:47:30 +08:00
|
|
|
|
namespace osu.Game.Online.API
|
|
|
|
|
{
|
2018-03-14 09:42:58 +08:00
|
|
|
|
public interface IAPIProvider
|
2018-02-16 12:47:30 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The local user.
|
|
|
|
|
/// </summary>
|
2021-11-04 17:02:44 +08:00
|
|
|
|
IBindable<APIUser> LocalUser { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-12-17 18:30:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The user's friends.
|
|
|
|
|
/// </summary>
|
2021-11-04 17:02:44 +08:00
|
|
|
|
IBindableList<APIUser> Friends { get; }
|
2020-12-17 18:30:55 +08:00
|
|
|
|
|
2019-06-12 17:04:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current user's activity.
|
|
|
|
|
/// </summary>
|
2020-12-18 14:16:36 +08:00
|
|
|
|
IBindable<UserActivity> Activity { get; }
|
2019-06-12 17:04:57 +08:00
|
|
|
|
|
2020-10-22 14:03:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieve the OAuth access token.
|
|
|
|
|
/// </summary>
|
2020-10-23 09:03:33 +08:00
|
|
|
|
string AccessToken { get; }
|
2020-10-22 14:03:43 +08:00
|
|
|
|
|
2018-02-16 12:47:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns whether the local user is logged in.
|
|
|
|
|
/// </summary>
|
|
|
|
|
bool IsLoggedIn { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-13 11:56:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The last username provided by the end-user.
|
|
|
|
|
/// May not be authenticated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
string ProvidedUsername { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The URL endpoint for this API. Does not include a trailing slash.
|
|
|
|
|
/// </summary>
|
2020-12-24 17:11:40 +08:00
|
|
|
|
string APIEndpointUrl { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The root URL of of the website, excluding the trailing slash.
|
|
|
|
|
/// </summary>
|
2020-12-24 20:44:46 +08:00
|
|
|
|
string WebsiteRootUrl { get; }
|
2019-03-13 11:56:47 +08:00
|
|
|
|
|
2022-02-17 17:33:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The version of the API.
|
|
|
|
|
/// </summary>
|
|
|
|
|
int APIVersion { get; }
|
|
|
|
|
|
2021-10-04 14:40:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The last login error that occurred, if any.
|
|
|
|
|
/// </summary>
|
|
|
|
|
Exception? LastLoginError { get; }
|
|
|
|
|
|
2020-10-22 13:56:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current connection state of the API.
|
|
|
|
|
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
|
|
|
|
|
/// </summary>
|
2020-10-22 13:19:12 +08:00
|
|
|
|
IBindable<APIState> State { get; }
|
2019-03-13 11:56:47 +08:00
|
|
|
|
|
2018-02-16 12:47:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Queue a new request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request to perform.</param>
|
|
|
|
|
void Queue(APIRequest request);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-11-29 19:03:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Perform a request immediately, bypassing any API state checks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Can be used to run requests as a guest user.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="request">The request to perform.</param>
|
|
|
|
|
void Perform(APIRequest request);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Perform a request immediately, bypassing any API state checks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Can be used to run requests as a guest user.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="request">The request to perform.</param>
|
|
|
|
|
Task PerformAsync(APIRequest request);
|
|
|
|
|
|
2019-03-13 11:56:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attempt to login using the provided credentials. This is a non-blocking operation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="username">The user's username.</param>
|
|
|
|
|
/// <param name="password">The user's password.</param>
|
|
|
|
|
void Login(string username, string password);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Log out the current user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void Logout();
|
|
|
|
|
|
2021-02-15 15:31:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a new <see cref="IHubClientConnector"/>. May be null if not supported.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clientName">The name of the client this connector connects for, used for logging.</param>
|
|
|
|
|
/// <param name="endpoint">The endpoint to the hub.</param>
|
2021-08-03 13:50:56 +08:00
|
|
|
|
/// <param name="preferMessagePack">Whether to use MessagePack for serialisation if available on this platform.</param>
|
2021-08-02 13:44:51 +08:00
|
|
|
|
IHubClientConnector? GetHubConnector(string clientName, string endpoint, bool preferMessagePack = true);
|
2021-02-15 15:31:00 +08:00
|
|
|
|
|
2019-03-13 11:56:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new user account. This is a blocking operation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="email">The email to create the account with.</param>
|
|
|
|
|
/// <param name="username">The username to create the account with.</param>
|
|
|
|
|
/// <param name="password">The password to create the account with.</param>
|
|
|
|
|
/// <returns>Any errors encoutnered during account creation.</returns>
|
2021-02-15 16:02:07 +08:00
|
|
|
|
RegistrationRequest.RegistrationRequestErrors? CreateAccount(string email, string username, string password);
|
2018-02-16 12:47:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|