Minor cleanup
This commit is contained in:
parent
f5ecf2d1b4
commit
7c96301dc0
4 changed files with 17 additions and 15 deletions
20
README.md
20
README.md
|
@ -1,10 +1,16 @@
|
|||
[](https://opensource.org/licenses/BSD-3-Clause) <!-- [](https://github.com/ethauvin/jokeapi/releases/latest) [](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/jokeapi) --> [](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/jokeapi/)
|
||||
[](https://opensource.org/licenses/BSD-3-Clause)
|
||||
[](https://kotlinlang.org/)
|
||||
[](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/jokeapi/)
|
||||
[](https://github.com/ethauvin/jokeapi/releases/latest)
|
||||
[](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/jokeapi)
|
||||
|
||||
[](https://sonarcloud.io/dashboard?id=ethauvin_jokeapi) [](https://github.com/ethauvin/jokeapi/actions/workflows/gradle.yml) [](https://circleci.com/gh/ethauvin/jokeapi/tree/master)
|
||||
[](https://sonarcloud.io/dashboard?id=ethauvin_jokeapi)
|
||||
[](https://github.com/ethauvin/jokeapi/actions/workflows/gradle.yml)
|
||||
[](https://circleci.com/gh/ethauvin/jokeapi/tree/master)
|
||||
|
||||
# JokeAPI for Kotlin/Java
|
||||
# JokeAPI for Kotlin, Java and Android
|
||||
|
||||
A simple Kotlin/Java library to retrieve jokes from [Sv443's JokeAPI](https://v2.jokeapi.dev/).
|
||||
A simple library to retrieve jokes from [Sv443's JokeAPI](https://v2.jokeapi.dev/).
|
||||
|
||||
## Examples (TL;DR)
|
||||
|
||||
|
@ -17,7 +23,7 @@ val pun = getJoke(categories = setOf(Category.PUN))
|
|||
```
|
||||
The parameters match the [joke endpoint](https://v2.jokeapi.dev/#joke-endpoint).
|
||||
|
||||
A `Joke` class instance is returned:
|
||||
A `Joke` class instance is returned, matching the [response](https://v2.jokeapi.dev/joke/Any?type=single):
|
||||
|
||||
```kotlin
|
||||
data class Joke(
|
||||
|
@ -45,7 +51,7 @@ frenchJokes.forEach {
|
|||
- View more [examples](https://github.com/ethauvin/jokeapi/blob/master/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt)...
|
||||
|
||||
|
||||
If an error occurs, a `JokeException` is thrown:
|
||||
If an error occurs, a `JokeException` is thrown, matching the [JokeAPI errors](https://sv443.net/jokeapi/v2/#errors):
|
||||
|
||||
```kotlin
|
||||
class JokeException(
|
||||
|
@ -88,7 +94,7 @@ To use with [Gradle](https://gradle.org/), include the following dependency in y
|
|||
```gradle
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
|
||||
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } // only needed for SNAPSHOT
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues/>
|
||||
<CurrentIssues>
|
||||
<ID>ComplexMethod:JokeApi.kt$fun getRawJokes( categories: Set<Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set<Flag> = emptySet(), type: Type = Type.ALL, format: Format = Format.JSON, contains: String = "", idRange: IdRange = IdRange(), amount: Int = 1, safe: Boolean = false, auth: String = "" ): String</ID>
|
||||
<ID>LongParameterList:JokeApi.kt$( amount: Int, categories: Set<Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set<Flag> = emptySet(), type: Type = Type.ALL, contains: String = "", idRange: IdRange = IdRange(), safe: Boolean = false, auth: String = "", splitNewLine: Boolean = false )</ID>
|
||||
<ID>LongParameterList:JokeApi.kt$( categories: Set<Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set<Flag> = emptySet(), type: Type = Type.ALL, contains: String = "", idRange: IdRange = IdRange(), safe: Boolean = false, auth: String = "", splitNewLine: Boolean = false )</ID>
|
||||
<ID>LongParameterList:JokeApi.kt$( categories: Set<Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set<Flag> = emptySet(), type: Type = Type.ALL, format: Format = Format.JSON, contains: String = "", idRange: IdRange = IdRange(), amount: Int = 1, safe: Boolean = false, auth: String = "" )</ID>
|
||||
|
@ -19,6 +18,5 @@
|
|||
<ID>MagicNumber:util.kt$500</ID>
|
||||
<ID>MagicNumber:util.kt$523</ID>
|
||||
<ID>TooManyFunctions:JokeConfig.kt$JokeConfig$Builder</ID>
|
||||
<ID>UnusedPrivateMember:JokeConfig.kt$JokeConfig.Builder$search: String</ID>
|
||||
</CurrentIssues>
|
||||
</SmellBaseline>
|
||||
|
|
|
@ -311,18 +311,16 @@ fun getRawJokes(
|
|||
if (idRange.start >= 0) {
|
||||
if (idRange.end == -1 || idRange.start == idRange.end) {
|
||||
params[Parameter.RANGE] = idRange.start.toString()
|
||||
} else if (idRange.end > idRange.start) {
|
||||
params[Parameter.RANGE] = "${idRange.start}-${idRange.end}"
|
||||
} else {
|
||||
throw IllegalArgumentException("Invalid ID Range: ${idRange.start}, ${idRange.end}")
|
||||
require(idRange.end > idRange.start) { "Invalid ID Range: ${idRange.start}, ${idRange.end}" }
|
||||
params[Parameter.RANGE] = "${idRange.start}-${idRange.end}"
|
||||
}
|
||||
}
|
||||
|
||||
// Amount
|
||||
require(amount > 0) { "Invalid Amount: $amount" }
|
||||
if (amount > 1) {
|
||||
params[Parameter.AMOUNT] = amount.toString()
|
||||
} else if (amount <= 0) {
|
||||
throw IllegalArgumentException("Invalid Amount: $amount")
|
||||
}
|
||||
|
||||
// Safe
|
||||
|
|
|
@ -77,7 +77,7 @@ class JokeConfig private constructor(
|
|||
var safe: Boolean = false,
|
||||
var auth: String = "",
|
||||
var splitNewLine: Boolean = false
|
||||
) {
|
||||
) {
|
||||
fun categories(categories: Set<Category>) = apply { this.categories = categories }
|
||||
fun lang(language: Language) = apply { lang = language }
|
||||
fun blacklistFlags(flags: Set<Flag>) = apply { blacklistFlags = flags }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue