public void ThrowIfNotSupported([CallerMemberName] string?name = null) { if (name == null) { return; } _versions ??= VersionsEndpoint.RequestVersions(); if (!((typeof(MatrixApi).GetMethod(name) ?? throw new InvalidOperationException()).GetCustomAttribute( typeof(MatrixSpecAttribute)) is MatrixSpecAttribute spec)) { #if DEBUG Log.LogWarning($"{name} has no MatrixSpec attribute, cannot determine homeserver support"); #endif return; } var clientServerContext = spec.SpecContext.Specification switch { Specification.ClientServer => ClientServer(spec.SpecContext) }; // Ensure we support a version of the spec >= the min version and <= the last version. if (!_versions.Versions .Any(version => version >= clientServerContext.AddedVersion && version <= clientServerContext.RemovedVersion)) { return; } var msg = "This homeserver doesn't support this endpoint."; if (clientServerContext.RemovedVersion != ClientServerVersion.Unknown) { msg += $"The endpoint was removed in spec version {clientServerContext.RemovedVersion.ToJsonString()}"; } else { msg += $"The endpoint was added in spec version {clientServerContext.AddedVersion.ToJsonString()}"; } throw new MatrixException(msg); } }
public MatrixApi(Uri url) { if (url != null && url.IsWellFormedOriginalString() && !url.IsAbsoluteUri) { throw new MatrixException(Resources.InvalidUrl); } _isAppservice = false; Backend = new HttpBackend(url, UserId); BaseUrl = url; Rng = new Random(DateTime.Now.Millisecond); Room = new RoomApi(this); LoginEndpoint = new LoginEndpoint(this); VersionsEndpoint = new VersionsEndpoint(this); Device = new DeviceApi(this); Media = new MediaApi(this); Profile = new ProfileApi(this); Sync = new SyncEndpoint(this); RoomDirectory = new RoomDirectoryApi(this); }