Kotlin Multiplatform Mobile SDK

Overview of the Kotlin Multiplatform Mobile SDK for Fans United platform.

The Fans United Kotlin Multiplatform Mobile SDK supports both iOS and Android platforms using Kotlin Multiplatform Mobile technology. The SDK provides complete coverage of the Fans United APIs and is organized into different namespaces based on functionality.

Features

  • Profile Operations
  • Football Operations
  • Predictor Operations
  • Top X Operations
  • Match Quiz Operations
  • Loyalty Operations
  • Activity Operations
  • Discussion Operations

Installation

Gradle Setup

Add the dependency to your KMM project's shared module build.gradle.kts:

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation(libs.kotlinx.coroutines.core)
            implementation(libs.kotlinx.serialization.json)
            implementation(libs.kotlinx.datetime)
            implementation(libs.ktor.client.core)
            implementation(libs.ktor.client.logging)
            implementation(libs.ktor.client.content.negotiation)
            implementation(libs.ktor.serialization.kotlinx.json)
            implementation("com.fansunitedmedia.sdk:fansunited-sdk:1.0.0")
        }
        iosSimulatorArm64Main.dependencies {
            implementation("com.fansunitedmedia.sdk:fansunited-sdk-iossimulatorarm64:1.0.0")
        }
    }
}

build.gradle.kts for Android target:

dependencies {
    implementation("com.fansunitedmedia.sdk:fansunited-sdk-android:1.0.0")
}

Usage

The SDK requires configuration and token provider implementation. All operations are suspending functions using Kotlin Coroutines.

Initialize the SDK

val tokenProvider = object : IFUSDKTokenProvider {
    override suspend fun getToken(): String? {
        // Provide implementation that returns valid token, refresh token if needed and always return valid one
        return "your-token"
    }
    
    override suspend fun logout() {
        // Handle logout
    }
}

val config = FUSDKConfig(
    apiKey = "fans-united-api-key",
    clientId = "fans-united-client-id",
    lang = "en", // Optional, default: "en"
    idSchema = IDSchema.NATIVE, // Options: NATIVE|ENETPULSE|SPORTRADAR|SPORTAL365
    environment = "prod", // Optional, default: "prod"
    authProvider = tokenProvider,
)

val sdk = FansUnitedSDK.init(config)

Making API Calls

// Football operations
val team = sdk.football().getTeamById("team-id")
val matches = sdk.football().getMatches(filters)

// Profile operations
val profile = sdk.profile().getOwn()

// Predictions
val predictions = sdk.predictor().getPredictions()

Error Handling

The SDK uses FansUnitedException for error handling:

try {
    sdk.football().getMatches(filters)
} catch (e: FansUnitedException) {
    // Handle specific error codes and statuses
    println("Error code: ${e.code}")
    println("Error status: ${e.status}")
    println("Error message: ${e.message}")
}