File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,15 +26,18 @@ public struct MatrixFilterRequest: MatrixRequest {
2626
2727 public typealias URLParameters = MatrixFilterId
2828
29- public func path ( with parameters: MatrixFilterId ) throws -> String {
29+ public func components ( for homeserver : MatrixHomeserver , with parameters: MatrixFilterId ) throws -> URLComponents {
3030 // FIXME: url encode
3131 guard
3232 let userId = parameters. user,
3333 let filterId = parameters. filter
3434 else {
3535 throw MatrixError . Unrecognized
3636 }
37- return " /_matrix/client/r0/user/ \( userId) /filter/ \( filterId) "
37+
38+ var components = homeserver. url
39+ components. path = " /_matrix/client/r0/user/ \( userId) /filter/ \( filterId) "
40+ return components
3841 }
3942
4043 public static var httpMethod = HttpMethod . GET
@@ -245,9 +248,11 @@ extension MatrixFilter: MatrixRequest {
245248 public typealias URLParameters = String
246249
247250 /// with -> userId
248- public func path ( with parameters: String ) -> String {
251+ public func components ( for homeserver : MatrixHomeserver , with parameters: String ) -> URLComponents {
249252 // TODO: url encode
250- return " /_matrix/client/r0/user/ \( parameters) /filter "
253+ var components = homeserver. url
254+ components. path = " /_matrix/client/r0/user/ \( parameters) /filter "
255+ return components
251256 }
252257
253258 public static var httpMethod = HttpMethod . POST
Original file line number Diff line number Diff line change @@ -34,8 +34,10 @@ public struct MatrixServerInfoRequest: MatrixRequest {
3434
3535 public typealias URLParameters = ( )
3636
37- public func path( with parameters: ( ) ) -> String {
38- return " /_matrix/client/versions "
37+ public func components( for homeserver: MatrixHomeserver , with parameters: ( ) ) -> URLComponents {
38+ var components = homeserver. url
39+ components. path = " /_matrix/client/versions "
40+ return components
3941 }
4042
4143 public static var httpMethod = HttpMethod . GET
@@ -62,8 +64,10 @@ public struct MatrixWellKnownRequest: MatrixRequest {
6264
6365 public typealias URLParameters = ( )
6466
65- public func path( with parameters: ( ) ) -> String {
66- return " /.well-known/matrix/client "
67+ public func components( for homeserver: MatrixHomeserver , with parameters: ( ) ) -> URLComponents {
68+ var components = homeserver. url
69+ components. path = " /.well-known/matrix/client "
70+ return components
6771 }
6872
6973 public static var httpMethod = HttpMethod . GET
Original file line number Diff line number Diff line change @@ -12,8 +12,10 @@ public struct MatrixLoginFlowRequest: MatrixRequest {
1212
1313 public typealias URLParameters = ( )
1414
15- public func path( with parameters: ( ) ) -> String {
16- return " /_matrix/client/r0/login "
15+ public func components( for homeserver: MatrixHomeserver , with parameters: ( ) ) -> URLComponents {
16+ var components = homeserver. url
17+ components. path = " /_matrix/client/r0/login "
18+ return components
1719 }
1820
1921 public static var httpMethod = HttpMethod . GET
@@ -241,8 +243,10 @@ extension MatrixLoginRequest: MatrixRequest {
241243
242244 public typealias URLParameters = ( )
243245
244- public func path( with parameters: ( ) ) -> String {
245- return " /_matrix/client/r0/login "
246+ public func components( for homeserver: MatrixHomeserver , with parameters: ( ) ) -> URLComponents {
247+ var components = homeserver. url
248+ components. path = " /_matrix/client/r0/login "
249+ return components
246250 }
247251
248252 public static var httpMethod = HttpMethod . POST
Original file line number Diff line number Diff line change @@ -12,12 +12,16 @@ public struct MatrixLogoutRequest: MatrixRequest {
1212
1313 public typealias URLParameters = Bool
1414
15- public func path( with all: Bool ) -> String {
15+ public func components( for homeserver: MatrixHomeserver , with all: Bool ) -> URLComponents {
16+ var components = homeserver. url
17+
1618 if all {
17- return " /_matrix/client/r0/logout/all "
19+ components . path = " /_matrix/client/r0/logout/all "
1820 } else {
19- return " /_matrix/client/r0/logout "
21+ components . path = " /_matrix/client/r0/logout "
2022 }
23+
24+ return components
2125 }
2226
2327 public static var httpMethod = HttpMethod . POST
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ public protocol MatrixRequest: Codable {
2020 associatedtype Response : MatrixResponse
2121
2222 associatedtype URLParameters
23- func path ( with parameters: URLParameters ) throws -> String
23+ func components ( for homeserver : MatrixHomeserver , with parameters: URLParameters ) throws -> URLComponents
2424
2525 static var httpMethod : HttpMethod { get }
2626 static var requiresAuth : Bool { get }
@@ -30,7 +30,7 @@ public protocol MatrixRequest: Codable {
3030
3131public extension MatrixRequest {
3232 func request( on homeserver: MatrixHomeserver , withToken token: String ? = nil , with parameters: URLParameters ) throws -> URLRequest {
33- let components = homeserver . path ( try self . path ( with: parameters) )
33+ let components = try components ( for : homeserver , with: parameters)
3434 // components.queryItems = self.queryParameters
3535
3636 var urlRequest = URLRequest ( url: components. url!)
Original file line number Diff line number Diff line change 11import Foundation
22
33public struct MatrixSyncRequest : MatrixRequest {
4- public func path ( with parameters: URLParameters ) throws -> String {
5- var components = URLComponents ( )
4+ public func components ( for homeserver : MatrixHomeserver , with parameters: URLParameters ) throws -> URLComponents {
5+ var components = homeserver . url
66 components. path = " /_matrix/client/r0/sync "
7-
7+
88 var queryItems = [ URLQueryItem] ( )
9-
9+
1010 if let filter = parameters. filter {
1111 queryItems. append ( URLQueryItem ( name: " filter " , value: filter) )
1212 }
13-
13+
1414 if let since = parameters. since {
1515 queryItems. append ( URLQueryItem ( name: " since " , value: since) )
1616 }
17-
17+
1818 // TODO: fullState
1919 // TODO: presence
20-
20+
2121 if let timeout = parameters. timeout {
2222 queryItems. append ( URLQueryItem ( name: " timeout " , value: String ( timeout) ) )
2323 }
24-
24+
2525 components. queryItems = queryItems
26-
27- return components. string ?? " /_matrix/client/r0/sync "
26+
27+ return components
2828 }
2929
3030 public typealias Response = MatrixSyncResponse
You can’t perform that action at this time.
0 commit comments