diff --git a/src/main/kotlin/ca/gosyer/data/server/interactions/DownloadInteractionHandler.kt b/src/main/kotlin/ca/gosyer/data/server/interactions/DownloadInteractionHandler.kt new file mode 100644 index 00000000..61067450 --- /dev/null +++ b/src/main/kotlin/ca/gosyer/data/server/interactions/DownloadInteractionHandler.kt @@ -0,0 +1,40 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.data.server.interactions + +import ca.gosyer.data.server.Http +import ca.gosyer.data.server.ServerPreferences +import ca.gosyer.data.server.requests.downloadsClearRequest +import ca.gosyer.data.server.requests.downloadsStartRequest +import ca.gosyer.data.server.requests.downloadsStopRequest +import ca.gosyer.util.lang.withIOContext +import io.ktor.client.statement.HttpResponse +import javax.inject.Inject + +class DownloadInteractionHandler @Inject constructor( + client: Http, + serverPreferences: ServerPreferences +) : BaseInteractionHandler(client, serverPreferences) { + + suspend fun startDownloading() = withIOContext { + client.getRepeat( + serverUrl + downloadsStartRequest() + ) + } + + suspend fun stopDownloading() = withIOContext { + client.getRepeat( + serverUrl + downloadsStopRequest() + ) + } + + suspend fun clearDownloadQueue() = withIOContext { + client.getRepeat( + serverUrl + downloadsClearRequest() + ) + } +} diff --git a/src/main/kotlin/ca/gosyer/data/server/requests/Downloads.kt b/src/main/kotlin/ca/gosyer/data/server/requests/Downloads.kt index a087549b..3ad4f833 100644 --- a/src/main/kotlin/ca/gosyer/data/server/requests/Downloads.kt +++ b/src/main/kotlin/ca/gosyer/data/server/requests/Downloads.kt @@ -6,14 +6,18 @@ package ca.gosyer.data.server.requests +@Get fun downloadsQuery() = "/api/v1/downloads" +@Get fun downloadsStartRequest() = "/api/v1/downloads/start" +@Get fun downloadsStopRequest() = "/api/v1/downloads/stop" +@Get fun downloadsClearRequest() = "/api/v1/downloads/clear"