# Leaderboard

## Opt in

To opt in or join a user into the leaderboard, the following API can be used.

#### Concrete Example

{% tabs %}
{% tab title="Swift" %}

```swift
let service = LeaderboardService()
service.optIn(then: { result in
        switch result {
        case .success:
            // leaderboard opt in successful
            break
        case .failure:
            // error
        }
})
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LeaderboardService()
service.optIn() { result: Result<Content?>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
    }
})
```

{% endtab %}
{% endtabs %}

## Opt out

To opt out or leave the leaderboard, the following API can be used.

#### Concrete Example

{% tabs %}
{% tab title="Swift" %}

```swift
let service = LeaderboardService()
service.optOut(then: { result in
    switch result {
    case .success:
        // opts out successful
        break
    case .failure:
        // error
    }
})
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LeaderboardService()
service.optOut() { result: Result<Content?>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
        completionHandler(content)
    }
})
```

{% endtab %}
{% endtabs %}

## Fetch

To fetch the leaderboard, the following API can be used.

#### Parameters:

* `dateComponents`: The date (by component) to fetch the `Leaderboard` for. Leaderboards are fetched by month, so specifying the year and month in the components are necessary to receive the correct leaderboard. Defaults to fetching the current leaderboard.

{% tabs %}
{% tab title="Swift" %}

```swift
let service = LeaderboardService()
service.fetch(dateComponents: DateComponents(year, month)) { result in
    switch result {
    case .success:
        // fetch succesful
        break
    default:
        // error
    }
})
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LeaderboardService()
val dataComponents = DataComponents(Date())
val filters = Set<Filter>

service.fetch(dataComponents, filters) { result: Result<Content?>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
        completionHandler(content)
    }
})
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sdk.ims.tech/drivesync-portal/leaderboard.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
