Skip to content

Commit c3fcb6e

Browse files
authored
docs: add missing Kotlin examples of usage (#67)
1 parent c8d14db commit c3fcb6e

8 files changed

+258
-32
lines changed

docs/v1/get-comments.md

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,72 @@ A call to this endpoint returns comments of a specified kind: game, achievement,
2424

2525
## Client Library
2626

27-
Not yet supported.
27+
::: code-group
28+
29+
```Kotlin [User]
30+
val credentials = RetroCredentials("<username>", "<web api key>")
31+
val api: RetroInterface = RetroClient(credentials).api
32+
33+
val response: NetworkResponse<GetComments.Response, ErrorResponse> = api.getCommentsOnUserWall(
34+
username = "MaxMilyin",
35+
)
36+
37+
if (response is NetworkResponse.Success) {
38+
// handle the data
39+
val comments: GetComments.Response = response.body
40+
41+
} else if (response is NetworkResponse.Error) {
42+
// if the server returns an error it be found here
43+
val errorResponse: ErrorResponse? = response.body
44+
45+
// if the api (locally) had an internal error, it'll be found here
46+
val internalError: Throwable? = response.error
47+
}
48+
```
49+
50+
```Kotlin [Game]
51+
val credentials = RetroCredentials("<username>", "<web api key>")
52+
val api: RetroInterface = RetroClient(credentials).api
53+
54+
val response: NetworkResponse<GetComments.Response, ErrorResponse> = api.getCommentsOnGameWall(
55+
gameId = 14402,
56+
)
57+
58+
if (response is NetworkResponse.Success) {
59+
// handle the data
60+
val comments: GetComments.Response = response.body
61+
62+
} else if (response is NetworkResponse.Error) {
63+
// if the server returns an error it be found here
64+
val errorResponse: ErrorResponse? = response.body
65+
66+
// if the api (locally) had an internal error, it'll be found here
67+
val internalError: Throwable? = response.error
68+
}
69+
```
70+
71+
```Kotlin [Achievement]
72+
val credentials = RetroCredentials("<username>", "<web api key>")
73+
val api: RetroInterface = RetroClient(credentials).api
74+
75+
val response: NetworkResponse<GetComments.Response, ErrorResponse> = api.getCommentsOnAchievementWall(
76+
achievementId = 14402,
77+
)
78+
79+
if (response is NetworkResponse.Success) {
80+
// handle the data
81+
val comments: GetComments.Response = response.body
82+
83+
} else if (response is NetworkResponse.Error) {
84+
// if the server returns an error it be found here
85+
val errorResponse: ErrorResponse? = response.body
86+
87+
// if the api (locally) had an internal error, it'll be found here
88+
val internalError: Throwable? = response.error
89+
}
90+
```
91+
92+
:::
2893

2994
## Response
3095

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

50115
## Source
51116

52-
| Repo | URL |
53-
| :---- | :------------------------------------------------------------------------------------ |
54-
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetComments.php |
117+
| Repo | URL |
118+
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
119+
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetComments.php |
120+
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |

docs/v1/get-game-hashes.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,30 @@ This data can be found on the Supported Game Files page, for example, [Sonic the
2727

2828
## Client Library
2929

30-
Not yet supported.
30+
::: code-group
31+
32+
```Kotlin
33+
val credentials = RetroCredentials("<username>", "<web api key>")
34+
val api: RetroInterface = RetroClient(credentials).api
35+
36+
val response: NetworkResponse<GetGameHashes.Response, ErrorResponse> = api.getGameHashes(
37+
gameId = 14402
38+
)
39+
40+
if (response is NetworkResponse.Success) {
41+
// handle the data
42+
val gameHashes: GetGameHashes.Response = response.body
43+
44+
} else if (response is NetworkResponse.Error) {
45+
// if the server returns an error it be found here
46+
val errorResponse: ErrorResponse? = response.body
47+
48+
// if the api (locally) had an internal error, it'll be found here
49+
val internalError: Throwable? = response.error
50+
}
51+
```
52+
53+
:::
3154

3255
## Response
3356

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

5780
## Source
5881

59-
| Repo | URL |
60-
| :---- | :-------------------------------------------------------------------------------------- |
61-
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetGameHashes.php |
82+
| Repo | URL |
83+
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
84+
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetGameHashes.php |
85+
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |

docs/v1/get-game-leaderboards.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,30 @@ A games's list of leaderboards can be found on on the game's page:
2929

3030
## Client Library
3131

32-
Not yet supported.
32+
::: code-group
33+
34+
```Kotlin
35+
val credentials = RetroCredentials("<username>", "<web api key>")
36+
val api: RetroInterface = RetroClient(credentials).api
37+
38+
val response: NetworkResponse<GetGameLeaderboards.Response, ErrorResponse> = api.getGameLeaderboards(
39+
gameId = 14402
40+
)
41+
42+
if (response is NetworkResponse.Success) {
43+
// handle the data
44+
val gameLeaderboards: GetGameLeaderboards.Response = response.body
45+
46+
} else if (response is NetworkResponse.Error) {
47+
// if the server returns an error it be found here
48+
val errorResponse: ErrorResponse? = response.body
49+
50+
// if the api (locally) had an internal error, it'll be found here
51+
val internalError: Throwable? = response.error
52+
}
53+
```
54+
55+
:::
3356

3457
## Response
3558

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

6285
## Source
6386

64-
| Repo | URL |
65-
| :---- | :-------------------------------------------------------------------------------------------- |
66-
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetGameLeaderboards.php |
87+
| Repo | URL |
88+
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
89+
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetGameLeaderboards.php |
90+
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |

docs/v1/get-leaderboard-entries.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,30 @@ A leaderboards's entries can be found on the leaderboard info page:
2929

3030
## Client Library
3131

32-
Not yet supported.
32+
::: code-group
33+
34+
```Kotlin
35+
val credentials = RetroCredentials("<username>", "<web api key>")
36+
val api: RetroInterface = RetroClient(credentials).api
37+
38+
val response: NetworkResponse<GetLeaderboardEntries.Response, ErrorResponse> = api.getLeaderboardEntries(
39+
gameId = 14402
40+
)
41+
42+
if (response is NetworkResponse.Success) {
43+
// handle the data
44+
val leaderboardEntries: GetLeaderboardEntries.Response = response.body
45+
46+
} else if (response is NetworkResponse.Error) {
47+
// if the server returns an error it be found here
48+
val errorResponse: ErrorResponse? = response.body
49+
50+
// if the api (locally) had an internal error, it'll be found here
51+
val internalError: Throwable? = response.error
52+
}
53+
```
54+
55+
:::
3356

3457
## Response
3558

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

5780
## Source
5881

59-
| Repo | URL |
60-
| :---- | :---------------------------------------------------------------------------------------------- |
61-
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetLeaderboardEntries.php |
82+
| Repo | URL |
83+
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
84+
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetLeaderboardEntries.php |
85+
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |

docs/v1/get-recent-game-awards.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ const authorization = buildAuthorization({ username, webApiKey });
4848
const game = await getRecentGameAwards(authorization);
4949
```
5050

51+
```Kotlin
52+
val credentials = RetroCredentials("<username>", "<web api key>")
53+
val api: RetroInterface = RetroClient(credentials).api
54+
55+
val response: NetworkResponse<GetRecentGameAwards.Response, ErrorResponse> = api.getRecentGameAwards()
56+
57+
if (response is NetworkResponse.Success) {
58+
// handle the data
59+
val topUsers: GetRecentGameAwards.Response = response.body
60+
61+
} else if (response is NetworkResponse.Error) {
62+
// if the server returns an error it be found here
63+
val errorResponse: ErrorResponse? = response.body
64+
65+
// if the api (locally) had an internal error, it'll be found here
66+
val internalError: Throwable? = response.error
67+
}
68+
```
69+
5170
:::
5271

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

97116
## Source
98117

99-
| Repo | URL |
100-
| :----- | :-------------------------------------------------------------------------------------------- |
101-
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetRecentGameAwards.php |
102-
| api-js | https://github.com/RetroAchievements/api-js/blob/main/src/feed/getRecentGameAwards.ts |
118+
| Repo | URL |
119+
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
120+
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetRecentGameAwards.php |
121+
| api-js | https://github.com/RetroAchievements/api-js/blob/main/src/feed/getRecentGameAwards.ts |
122+
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |

docs/v1/get-user-want-to-play-list.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,30 @@ The user's Want to Play Games list page looks like:
2929

3030
## Client Library
3131

32-
Not yet supported.
32+
::: code-group
33+
34+
```Kotlin
35+
val credentials = RetroCredentials("<username>", "<web api key>")
36+
val api: RetroInterface = RetroClient(credentials).api
37+
38+
val response: NetworkResponse<GetUserWantToPlayList.Response, ErrorResponse> = api.getUserWantToPlayList(
39+
username = "MaxMilyin",
40+
)
41+
42+
if (response is NetworkResponse.Success) {
43+
// handle the data
44+
val wantToPlayList: GetUserWantToPlayList.Response = response.body
45+
46+
} else if (response is NetworkResponse.Error) {
47+
// if the server returns an error it be found here
48+
val errorResponse: ErrorResponse? = response.body
49+
50+
// if the api (locally) had an internal error, it'll be found here
51+
val internalError: Throwable? = response.error
52+
}
53+
```
54+
55+
:::
3356

3457
## Response
3558

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

5982
## Source
6083

61-
| Repo | URL |
62-
| :---- | :---------------------------------------------------------------------------------------------- |
63-
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUserWantToPlayList.php |
84+
| Repo | URL |
85+
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
86+
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUserWantToPlayList.php |
87+
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |

docs/v1/get-users-following-me.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,28 @@ The user's Followers Users List page looks like:
2828

2929
## Client Library
3030

31-
Not yet supported.
31+
::: code-group
32+
33+
```Kotlin
34+
val credentials = RetroCredentials("<username>", "<web api key>")
35+
val api: RetroInterface = RetroClient(credentials).api
36+
37+
val response: NetworkResponse<GetUsersFollowingMe.Response, ErrorResponse> = api.getUsersFollowingMe()
38+
39+
if (response is NetworkResponse.Success) {
40+
// handle the data
41+
val users: GetUsersFollowingMe.Response = response.body
42+
43+
} else if (response is NetworkResponse.Error) {
44+
// if the server returns an error it be found here
45+
val errorResponse: ErrorResponse? = response.body
46+
47+
// if the api (locally) had an internal error, it'll be found here
48+
val internalError: Throwable? = response.error
49+
}
50+
```
51+
52+
:::
3253

3354
## Response
3455

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

5576
## Source
5677

57-
| Repo | URL |
58-
| :---- | :-------------------------------------------------------------------------------------------- |
59-
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUsersFollowingMe.php |
78+
| Repo | URL |
79+
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
80+
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUsersFollowingMe.php |
81+
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |

docs/v1/get-users-i-follow.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,28 @@ The user's Followers Users List page looks like:
2828

2929
## Client Library
3030

31-
Not yet supported.
31+
::: code-group
32+
33+
```Kotlin
34+
val credentials = RetroCredentials("<username>", "<web api key>")
35+
val api: RetroInterface = RetroClient(credentials).api
36+
37+
val response: NetworkResponse<GetUsersIFollow.Response, ErrorResponse> = api.getUsersIFollow()
38+
39+
if (response is NetworkResponse.Success) {
40+
// handle the data
41+
val users: GetUsersIFollow.Response = response.body
42+
43+
} else if (response is NetworkResponse.Error) {
44+
// if the server returns an error it be found here
45+
val errorResponse: ErrorResponse? = response.body
46+
47+
// if the api (locally) had an internal error, it'll be found here
48+
val internalError: Throwable? = response.error
49+
}
50+
```
51+
52+
:::
3253

3354
## Response
3455

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

5576
## Source
5677

57-
| Repo | URL |
58-
| :---- | :---------------------------------------------------------------------------------------- |
59-
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUsersIFollow.php |
78+
| Repo | URL |
79+
| :--------- | :------------------------------------------------------------------------------------------------------------------- |
80+
| RAWeb | https://github.com/RetroAchievements/RAWeb/blob/master/public/API/API_GetUsersIFollow.php |
81+
| api-kotlin | https://github.com/RetroAchievements/api-kotlin/blob/main/src/main/kotlin/org/retroachivements/api/RetroInterface.kt |

0 commit comments

Comments
 (0)