Skip to content

yonatankarp/cat-fact-client

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 

Cat Fact Client

Type Status
CI pipelines Release Gradle Upgrade Linters

A Client library in Kotlin for https://catfact.ninja/fact

This is the example client library as described in the article link to article.

The library would do a best effort to supply the required number of facts, but it is not guaranteed that the number of facts returned would be the same as the number requested, but only limited by it.

Usage

The library can be used as follows:

val client = CatFactFactory.getInstabce(API, objectMapper)
val facts = client.getFacts(3)

Alternatively, you can use the mock version of the library that does not require any network calls:

val client = CatFactFactory.getInstabce(MOCK, objectMapper)
val facts = client.getFacts(3)

Adding the library to your project

The library is available on GitHub Packages, and can be added to your project as follows:

Add to your build.gradle.kts:

repositories {
    maven {
        url = uri("https://maven.pkg.github.com/yonatankarp/cat-fact-client")
        credentials {
            username = project.findProperty("gpr.user")?.toString() ?: System.getenv("GITHUB_ACTOR")
            password = project.findProperty("gpr.key")?.toString() ?: System.getenv("GITHUB_TOKEN")
        }
    }
}

You can then add the library as a dependency:

dependencies {
    implementation("com.yonatankarp:cat-fact-client:0.2.0")
}

Authors