.gitbook.1.0.1.source-code.Main.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gitbook Show documentation
Show all versions of gitbook Show documentation
Access GitBook's API without the raw JSON/HTTPS requests
The newest version!
import com.cjcrafter.gitbook.*
import com.cjcrafter.gitbook.search.AskRequest
import com.cjcrafter.gitbook.search.AskResponse
fun main() {
val gitbook = GitBookApi.builder()
.apiKey("gb_api_DNYFGhsLoF79DeJZWo0BHepOkoF3UoLQSfqHH8zm")
.build()
val request = AskRequest(query = "Shoot 5 projectiles")
//val location = SearchLocation.Organization("MgHAZkcfIhs3YcmBjk2r")
val response = gitbook.ask(request)
if (response.isFailure) {
println("Failed to connect to API: ${response.exceptionOrNull()}")
return
}
val answer = response.getOrThrow().answer
if (answer == null) {
println("You must have asked for forbidden knowledge, since the wiki could not confidently answer your question.")
return
}
println("The wiki says: ${answer.text}")
for (source in answer.sources) {
println("Source: $source")
}
}