-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add wild card http request builder [WPB-11845] (#3075)
* chore: android gradle plugin update (#3064) * chore: update sqlcipher [WPB-11808] (#3069) (cherry picked from commit 2ddb183) * feat: add a wild card request * return response as string * detekt package name --------- Co-authored-by: Jakub Żerko <[email protected]> Co-authored-by: Michał Saleniuk <[email protected]>
- Loading branch information
1 parent
ebcf95a
commit 71aef39
Showing
9 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/WildCardApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.network.api.base.authenticated | ||
|
||
import com.wire.kalium.network.utils.NetworkResponse | ||
import io.ktor.http.HttpMethod | ||
|
||
interface WildCardApi { | ||
suspend fun customRequest( | ||
httpMethod: HttpMethod, | ||
requestPath: List<String>, | ||
body: String?, | ||
queryParam: Map<String, String>, | ||
customHeader: Map<String, String> | ||
): NetworkResponse<String> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
network/src/commonMain/kotlin/com/wire/kalium/network/api/vcommon/WildCardApiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.network.api.vcommon | ||
|
||
import com.wire.kalium.network.AuthenticatedNetworkClient | ||
import com.wire.kalium.network.api.base.authenticated.WildCardApi | ||
import com.wire.kalium.network.utils.NetworkResponse | ||
import com.wire.kalium.network.utils.wrapKaliumResponse | ||
import io.ktor.client.request.parameter | ||
import io.ktor.client.request.request | ||
import io.ktor.client.request.setBody | ||
import io.ktor.client.request.url | ||
import io.ktor.http.HttpMethod | ||
|
||
internal class WildCardApiImpl( | ||
private val authenticatedNetworkClient: AuthenticatedNetworkClient | ||
) : WildCardApi { | ||
override suspend fun customRequest( | ||
httpMethod: HttpMethod, | ||
requestPath: List<String>, | ||
body: String?, | ||
queryParam: Map<String, String>, | ||
customHeader: Map<String, String> | ||
): NetworkResponse<String> = wrapKaliumResponse { | ||
authenticatedNetworkClient.httpClient.request { | ||
method = httpMethod | ||
url(requestPath.joinToString("/")) | ||
body?.let { setBody(it) } | ||
queryParam.forEach { (key, value) -> | ||
parameter(key, value) | ||
} | ||
customHeader.forEach { (key, value) -> | ||
headers.append(key, value) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters