Skip to content

docs: add missing Kotlin examples of usage #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 70 additions & 4 deletions docs/v1/get-comments.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,72 @@ A call to this endpoint returns comments of a specified kind: game, achievement,

## Client Library

Not yet supported.
::: code-group

```Kotlin [User]
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetComments.Response, ErrorResponse> = api.getCommentsOnUserWall(
username = "MaxMilyin",
)

if (response is NetworkResponse.Success) {
// handle the data
val comments: GetComments.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

```Kotlin [Game]
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetComments.Response, ErrorResponse> = api.getCommentsOnGameWall(
gameId = 14402,
)

if (response is NetworkResponse.Success) {
// handle the data
val comments: GetComments.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

```Kotlin [Achievement]
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetComments.Response, ErrorResponse> = api.getCommentsOnAchievementWall(
achievementId = 14402,
)

if (response is NetworkResponse.Success) {
// handle the data
val comments: GetComments.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

:::

## Response

@@ -49,6 +114,7 @@ Not yet supported.

## Source

| Repo | URL |
| :---- | :------------------------------------------------------------------------------------ |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetComments.php |
| Repo | URL |
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetComments.php |
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |
32 changes: 28 additions & 4 deletions docs/v1/get-game-hashes.md
Original file line number Diff line number Diff line change
@@ -27,7 +27,30 @@ This data can be found on the Supported Game Files page, for example, [Sonic the

## Client Library

Not yet supported.
::: code-group

```Kotlin
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetGameHashes.Response, ErrorResponse> = api.getGameHashes(
gameId = 14402
)

if (response is NetworkResponse.Success) {
// handle the data
val gameHashes: GetGameHashes.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

:::

## Response

@@ -56,6 +79,7 @@ Not yet supported.

## Source

| Repo | URL |
| :---- | :-------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetGameHashes.php |
| Repo | URL |
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetGameHashes.php |
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |
32 changes: 28 additions & 4 deletions docs/v1/get-game-leaderboards.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,30 @@ A games's list of leaderboards can be found on on the game's page:

## Client Library

Not yet supported.
::: code-group

```Kotlin
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetGameLeaderboards.Response, ErrorResponse> = api.getGameLeaderboards(
gameId = 14402
)

if (response is NetworkResponse.Success) {
// handle the data
val gameLeaderboards: GetGameLeaderboards.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

:::

## Response

@@ -61,6 +84,7 @@ Not yet supported.

## Source

| Repo | URL |
| :---- | :-------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetGameLeaderboards.php |
| Repo | URL |
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetGameLeaderboards.php |
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |
32 changes: 28 additions & 4 deletions docs/v1/get-leaderboard-entries.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,30 @@ A leaderboards's entries can be found on the leaderboard info page:

## Client Library

Not yet supported.
::: code-group

```Kotlin
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetLeaderboardEntries.Response, ErrorResponse> = api.getLeaderboardEntries(
gameId = 14402
)

if (response is NetworkResponse.Success) {
// handle the data
val leaderboardEntries: GetLeaderboardEntries.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

:::

## Response

@@ -56,6 +79,7 @@ Not yet supported.

## Source

| Repo | URL |
| :---- | :---------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetLeaderboardEntries.php |
| Repo | URL |
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetLeaderboardEntries.php |
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |
28 changes: 24 additions & 4 deletions docs/v1/get-recent-game-awards.md
Original file line number Diff line number Diff line change
@@ -48,6 +48,25 @@ const authorization = buildAuthorization({ username, webApiKey });
const game = await getRecentGameAwards(authorization);
```

```Kotlin
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetRecentGameAwards.Response, ErrorResponse> = api.getRecentGameAwards()

if (response is NetworkResponse.Success) {
// handle the data
val topUsers: GetRecentGameAwards.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

:::

## Response
@@ -96,7 +115,8 @@ const game = await getRecentGameAwards(authorization);

## Source

| Repo | URL |
| :----- | :-------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetRecentGameAwards.php |
| api-js | https://github.com/RetroAchievements/api-js/blob/main/src/feed/getRecentGameAwards.ts |
| Repo | URL |
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetRecentGameAwards.php |
| api-js | https://github.com/RetroAchievements/api-js/blob/main/src/feed/getRecentGameAwards.ts |
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |
32 changes: 28 additions & 4 deletions docs/v1/get-user-want-to-play-list.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,30 @@ The user's Want to Play Games list page looks like:

## Client Library

Not yet supported.
::: code-group

```Kotlin
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetUserWantToPlayList.Response, ErrorResponse> = api.getUserWantToPlayList(
username = "MaxMilyin",
)

if (response is NetworkResponse.Success) {
// handle the data
val wantToPlayList: GetUserWantToPlayList.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

:::

## Response

@@ -58,6 +81,7 @@ Not yet supported.

## Source

| Repo | URL |
| :---- | :---------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUserWantToPlayList.php |
| Repo | URL |
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUserWantToPlayList.php |
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |
30 changes: 26 additions & 4 deletions docs/v1/get-users-following-me.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,28 @@ The user's Followers Users List page looks like:

## Client Library

Not yet supported.
::: code-group

```Kotlin
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetUsersFollowingMe.Response, ErrorResponse> = api.getUsersFollowingMe()

if (response is NetworkResponse.Success) {
// handle the data
val users: GetUsersFollowingMe.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

:::

## Response

@@ -54,6 +75,7 @@ Not yet supported.

## Source

| Repo | URL |
| :---- | :-------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUsersFollowingMe.php |
| Repo | URL |
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUsersFollowingMe.php |
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |
30 changes: 26 additions & 4 deletions docs/v1/get-users-i-follow.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,28 @@ The user's Followers Users List page looks like:

## Client Library

Not yet supported.
::: code-group

```Kotlin
val credentials = RetroCredentials("<username>", "<web api key>")
val api: RetroInterface = RetroClient(credentials).api

val response: NetworkResponse<GetUsersIFollow.Response, ErrorResponse> = api.getUsersIFollow()

if (response is NetworkResponse.Success) {
// handle the data
val users: GetUsersIFollow.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: ErrorResponse? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

:::

## Response

@@ -54,6 +75,7 @@ Not yet supported.

## Source

| Repo | URL |
| :---- | :---------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUsersIFollow.php |
| Repo | URL |
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUsersIFollow.php |
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |