Skip to content
Snippets Groups Projects
Commit e12d311e authored by William Walker's avatar William Walker
Browse files

Cleanup & consistency

--Remove unused Apple target source sets
--Rename CacheFlag enum objects for best practice
--Add 30s timeout for network requests
parent d2eb4c10
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ import edu.ucsc.its.temerity.remote.Group
import edu.ucsc.its.temerity.remote.User
import edu.ucsc.its.temerity.shared.AppSettings
import edu.ucsc.its.temerity.shared.data.repository.PlatformRepositoryInterface.CacheFlag
import edu.ucsc.its.temerity.shared.data.repository.PlatformRepositoryInterface.CacheFlag.DISABLE_CACHE
import edu.ucsc.its.temerity.shared.data.repository.PlatformRepositoryInterface.CacheFlag.DISABLE
import edu.ucsc.its.temerity.shared.database.AppDatabase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
......@@ -39,13 +39,13 @@ import org.koin.core.parameter.parametersOf
interface PlatformRepositoryInterface {
sealed class CacheFlag(val enable: Boolean) {
data object ENABLE_CACHE: CacheFlag(true)
data object DISABLE_CACHE: CacheFlag(false)
data object ENABLE: CacheFlag(true)
data object DISABLE: CacheFlag(false)
}
suspend fun fetchGroups(flag: CacheFlag = DISABLE_CACHE): List<Group>
suspend fun fetchUsers(flag: CacheFlag = DISABLE_CACHE): List<User>
suspend fun fetchDevices(flag: CacheFlag = DISABLE_CACHE): List<Device>
suspend fun fetchGroups(flag: CacheFlag = DISABLE): List<Group>
suspend fun fetchUsers(flag: CacheFlag = DISABLE): List<User>
suspend fun fetchDevices(flag: CacheFlag = DISABLE): List<Device>
}
class PlatformRepository : KoinComponent, PlatformRepositoryInterface {
......
......@@ -20,13 +20,16 @@ package edu.ucsc.its.temerity
import edu.ucsc.its.temerity.di.libModule
import org.koin.dsl.koinApplication
/**
* TemerityLibrary is the main entry point for the Temerity library.
* TemerityLibraryKoinContext is the main entry point for the Temerity library.
*
* This object is used to initialize the Koin dependency injection framework
*
*/
internal object TemerityLibraryKoinContext {
internal const val TIMEOUT = 3000L
private val koinApp = koinApplication {
modules(libModule)
}
......
......@@ -31,6 +31,7 @@ import edu.ucsc.its.temerity.remote.PlatformApi
import edu.ucsc.its.temerity.remote.createPlatformApi
import io.ktor.client.HttpClient
import io.ktor.client.engine.HttpClientEngine
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.defaultRequest
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logger
......@@ -108,6 +109,11 @@ private fun createHttpClient(httpClientEngine: HttpClientEngine, enableNetworkLo
}
}
install(HttpTimeout) {
connectTimeoutMillis = TemerityLibraryKoinContext.TIMEOUT
requestTimeoutMillis = TemerityLibraryKoinContext.TIMEOUT
socketTimeoutMillis = TemerityLibraryKoinContext.TIMEOUT
}
// Pass the stored authToken as a header in every request
defaultRequest {
header("authToken", authToken)
......
/*
* Designed and developed in 2022-2024 by William Walker (wnwalker@ucsc.edu)
* Copyright 2022-2024 The Regents of the University of California. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package edu.ucsc.its.temerity
import io.ktor.client.engine.darwin.Darwin
import org.koin.dsl.module
// This annotation is necessary to safely access native NSUserDefaults object
internal actual fun platformModule() = module {
factory { Darwin.create() }
}
/*
* Designed and developed in 2022-2024 by William Walker (wnwalker@ucsc.edu)
* Copyright 2022-2024 The Regents of the University of California. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package edu.ucsc.its.temerity
import io.ktor.client.engine.darwin.Darwin
import org.koin.dsl.module
// This annotation is necessary to safely access native NSUserDefaults object
internal actual fun platformModule() = module {
factory { Darwin.create() }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment