aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFinn Behrens <me@kloenk.dev>2021-09-30 10:13:05 +0200
committerFinn Behrens <me@kloenk.dev>2021-09-30 10:13:05 +0200
commit88baeb12a444b63856b6b6df80a049d6ea594072 (patch)
treea1e5c434181ffdd4d8193b563832f03ebee08480
parent8b57b61e66ab5ce51698c74fa3bf7b69423a3741 (diff)
downloadMatrixCore-88baeb12a444b63856b6b6df80a049d6ea594072.tar.gz
MatrixCore-88baeb12a444b63856b6b6df80a049d6ea594072.tar.xz
MatrixCore-88baeb12a444b63856b6b6df80a049d6ea594072.zip
add availability
-rw-r--r--Sources/MatrixClient/API/Request.swift4
-rw-r--r--Sources/MatrixClient/MatrixClient.swift11
-rw-r--r--Tests/MatrixClientTests/ClientTests.swift1
3 files changed, 13 insertions, 3 deletions
diff --git a/Sources/MatrixClient/API/Request.swift b/Sources/MatrixClient/API/Request.swift
index 7009cc2..f269f75 100644
--- a/Sources/MatrixClient/API/Request.swift
+++ b/Sources/MatrixClient/API/Request.swift
@@ -27,6 +27,7 @@ public protocol MatrixRequest: Codable {
// TODO: rate limited property?
}
+
public extension MatrixRequest {
func request(on homeserver: MatrixHomeserver, withToken token: String? = nil, with parameters: URLParameters) throws -> URLRequest {
let components = homeserver.path(self.path(with: parameters))
@@ -49,6 +50,7 @@ public extension MatrixRequest {
return urlRequest
}
+ @available(swift, introduced: 5.5)
func repsonse(on homeserver: MatrixHomeserver, withToken token: String? = nil, with parameters: URLParameters, withUrlSession urlSession: URLSession = URLSession.shared) async throws -> Response {
let request = try request(on: homeserver, withToken: token, with: parameters)
@@ -65,11 +67,11 @@ public extension MatrixRequest {
}
}
+/// Protocol for a Matrix server response
public protocol MatrixResponse: Codable {
}
public extension MatrixResponse {
- /// Init from http json data
init(fromMatrixRequestData data: Data) throws {
let decoder = JSONDecoder()
self = try decoder.decode(Self.self, from: data)
diff --git a/Sources/MatrixClient/MatrixClient.swift b/Sources/MatrixClient/MatrixClient.swift
index 440057b..1bdb496 100644
--- a/Sources/MatrixClient/MatrixClient.swift
+++ b/Sources/MatrixClient/MatrixClient.swift
@@ -32,6 +32,7 @@ public struct MatrixClient {
/// Rate-limited: No.
/// Requires auth: No.
/// ```
+ @available(swift, introduced: 5.5)
public func getVersions() async throws -> MatrixServerInfo {
return try await MatrixServerInfoRequest().repsonse(on: homeserver, with: (), withUrlSession: urlSession)
}
@@ -45,6 +46,7 @@ public struct MatrixClient {
/// Rate-limited: No.
/// Requires auth: No.
///```
+ @available(swift, introduced: 5.5)
public func getWellKnown() async throws -> MatrixWellKnown {
return try await MatrixWellKnownRequest().repsonse(on: homeserver, with: (), withUrlSession: urlSession)
}
@@ -55,6 +57,7 @@ public struct MatrixClient {
/// Rate-limited: Yes.
/// Requires auth: No.
/// ```
+ @available(swift, introduced: 5.5)
public func getLoginFlows() async throws -> [MatrixLoginFlow] {
let flows = try await MatrixLoginFlowRequest().repsonse(on: homeserver, with: (), withUrlSession: urlSession)
@@ -72,6 +75,7 @@ public struct MatrixClient {
/// Rate-limited: Yes.
/// Requires auth: No.
///```
+ @available(swift, introduced: 5.5)
public func login(token: Bool = false, username: String, password: String, displayName: String? = nil, deviceId: String? = nil) async throws -> MatrixLogin {
let flow: MatrixLoginFlow
if token {
@@ -100,6 +104,7 @@ public struct MatrixClient {
/// Rate-limited: Yes.
/// Requires auth: No.
///```
+ @available(swift, introduced: 5.5)
public func login(request: MatrixLoginRequest) async throws -> MatrixLogin {
return try await request.repsonse(on: homeserver, with: (), withUrlSession: urlSession)
}
@@ -114,8 +119,9 @@ public struct MatrixClient {
/// Rate-limited: No.
/// Requires auth: Yes.
///```
+ @available(swift, introduced: 5.5)
public func logout() async throws {
- try await MatrixLogoutRequest().repsonse(on: homeserver, with: false, withUrlSession: urlSession)
+ let _ = try await MatrixLogoutRequest().repsonse(on: homeserver, with: false, withUrlSession: urlSession)
}
/// Invalidates all access tokens for a user, so that they can no longer be used for authorization. This includes the access token that made this request.
@@ -130,8 +136,9 @@ public struct MatrixClient {
/// Rate-limited: No.
/// Requires auth: Yes.
///```
+ @available(swift, introduced: 5.5)
public func logoutAll() async throws {
- try await MatrixLogoutRequest().repsonse(on: homeserver, with: true, withUrlSession: urlSession)
+ let _ = try await MatrixLogoutRequest().repsonse(on: homeserver, with: true, withUrlSession: urlSession)
}
}
diff --git a/Tests/MatrixClientTests/ClientTests.swift b/Tests/MatrixClientTests/ClientTests.swift
index 181a0c3..99eaab1 100644
--- a/Tests/MatrixClientTests/ClientTests.swift
+++ b/Tests/MatrixClientTests/ClientTests.swift
@@ -8,6 +8,7 @@
import XCTest
@testable import MatrixClient
+@available(swift, introduced: 5.5)
final class MatrixClientTests: XCTestCase {
let client = MatrixClient(homeserver: MatrixHomeserver(string: "https://matrix-client.matrix.org")!)