forked from MRepoApp/MRepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ya0211
committed
Mar 12, 2023
1 parent
a63a32a
commit f22f50d
Showing
8 changed files
with
171 additions
and
181 deletions.
There are no files selected for viewing
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
20 changes: 5 additions & 15 deletions
20
app/src/main/kotlin/com/sanmer/mrepo/provider/spdx/LicenseProvider.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 |
---|---|---|
@@ -1,27 +1,17 @@ | ||
package com.sanmer.mrepo.provider.spdx | ||
|
||
import com.sanmer.mrepo.utils.expansion.runRequest | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
object LicenseProvider { | ||
private val api by lazy { SpdxService.create() } | ||
|
||
suspend fun getLicense(id: String) = withContext(Dispatchers.IO) { | ||
try { | ||
val response = api.getLicense(id).execute() | ||
|
||
if (response.isSuccessful) { | ||
val data = response.body() | ||
return@withContext if (data != null) { | ||
Result.success(data) | ||
}else { | ||
Result.failure(NullPointerException("The data is null!")) | ||
} | ||
} else { | ||
return@withContext Result.failure(RuntimeException("The specified key does not exist!")) | ||
} | ||
} catch (e: Exception) { | ||
return@withContext Result.failure(e) | ||
runRequest { | ||
api.getLicense(id).execute() | ||
}.onFailure { | ||
return@withContext Result.failure(RuntimeException("The specified key does not exist!")) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.