Created
May 22, 2019 09:46
-
-
Save zamahaka/f570f654e54df1f6cac460e58a096565 to your computer and use it in GitHub Desktop.
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
suspend fun apiIsOutdated(): Boolean = try { | |
val appApiVersionInfo = apiMeta.apiVersion | |
val realApiVersionInfo = getApiInfo() | |
.map(ApiInfo::version) | |
.fold( | |
onSuccess = ::identity, | |
onFailure = { appApiVersionInfo } | |
) | |
fun String.getVersions() = split(".").map(String::toInt) | |
val (appMajorVersion, appMinorVersion, appSubVersion) = appApiVersionInfo.getVersions() | |
val (apiMajorVersion, apiMinorVersion, apiSubVersion) = realApiVersionInfo.getVersions() | |
when { | |
apiMajorVersion < appMajorVersion -> false | |
apiMinorVersion < appMinorVersion -> false | |
(apiSubVersion - appSubVersion) >= apiMeta.apiUpdateAppThreshold -> true | |
else -> false | |
} | |
} catch (e: Exception) { | |
true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment