Skip to content

Commit e9f3175

Browse files
authored
chore: add support for new friends APIs (#35)
1 parent 49958cb commit e9f3175

File tree

8 files changed

+223
-1
lines changed

8 files changed

+223
-1
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,76 @@ if (response is NetworkResponse.Success) {
11771177

11781178
</details>
11791179

1180+
<details>
1181+
<summary>GetUsersIFollow</summary>
1182+
<br>
1183+
1184+
> A call to this endpoint will retrieve a list of users that I follow.
1185+
1186+
**Available Parameters**
1187+
1188+
| Name | Type | Description | Example | Default |
1189+
|:-------|:-----|:---------------------------------------|:--------|:--------|
1190+
| offset | Int | number of entries to skip | 100 | 0 |
1191+
| count | Int | number of entries to return (max: 500) | 50 | 100 |
1192+
1193+
**Example**
1194+
```kotlin
1195+
val credentials = RetroCredentials("<username>", "<web api key>")
1196+
val api: RetroInterface = RetroClient(credentials).api
1197+
1198+
val response: NetworkResponse<GetUsersIFollow.Response, ErrorResponse> = api.getUsersIFollow()
1199+
1200+
if (response is NetworkResponse.Success) {
1201+
// handle the data
1202+
val users: GetUsersIFollow.Response = response.body
1203+
1204+
} else if (response is NetworkResponse.Error) {
1205+
// if the server returns an error it be found here
1206+
val errorResponse: ErrorResponse? = response.body
1207+
1208+
// if the api (locally) had an internal error, it'll be found here
1209+
val internalError: Throwable? = response.error
1210+
}
1211+
```
1212+
1213+
</details>
1214+
1215+
<details>
1216+
<summary>GetUsersFollowingMe</summary>
1217+
<br>
1218+
1219+
> A call to this endpoint will retrieve a list of users that are following me.
1220+
1221+
**Available Parameters**
1222+
1223+
| Name | Type | Description | Example | Default |
1224+
|:-------|:-----|:---------------------------------------|:--------|:--------|
1225+
| offset | Int | number of entries to skip | 100 | 0 |
1226+
| count | Int | number of entries to return (max: 500) | 50 | 100 |
1227+
1228+
**Example**
1229+
```kotlin
1230+
val credentials = RetroCredentials("<username>", "<web api key>")
1231+
val api: RetroInterface = RetroClient(credentials).api
1232+
1233+
val response: NetworkResponse<GetUsersFollowingMe.Response, ErrorResponse> = api.getUsersFollowingMe()
1234+
1235+
if (response is NetworkResponse.Success) {
1236+
// handle the data
1237+
val users: GetUsersFollowingMe.Response = response.body
1238+
1239+
} else if (response is NetworkResponse.Error) {
1240+
// if the server returns an error it be found here
1241+
val errorResponse: ErrorResponse? = response.body
1242+
1243+
// if the api (locally) had an internal error, it'll be found here
1244+
val internalError: Throwable? = response.error
1245+
}
1246+
```
1247+
1248+
</details>
1249+
11801250
## Testing
11811251

11821252
Apache maven must be correctly installed on the system.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.retroachievements</groupId>
88
<artifactId>api-kotlin</artifactId>
9-
<version>1.0.12</version>
9+
<version>1.0.13</version>
1010

1111
<dependencyManagement>
1212
<dependencies>

src/main/kotlin/org/retroachivements/api/RetroInterface.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ interface RetroInterface {
171171
@Query("u") username: String
172172
): NetworkResponse<GetUserCompletedGames.Response, ErrorResponse>
173173

174+
/**
175+
* A call to this endpoint will retrieve a list of users that I follow.
176+
*/
177+
@Mock @MockResponse(body = "/v1/user/GetUsersIFollow.json")
178+
@POST("/API/API_GetUsersIFollow.php")
179+
suspend fun getUsersIFollow(
180+
@Query("o") offset: Int = 0,
181+
@Query("c") count: Int = 100
182+
): NetworkResponse<GetUsersIFollow.Response, ErrorResponse>
183+
184+
/**
185+
* A call to this endpoint will retrieve a list of users that are following me.
186+
*/
187+
@Mock @MockResponse(body = "/v1/user/GetUsersFollowingMe.json")
188+
@POST("/API/GetUsersFollowingMe.php")
189+
suspend fun getUsersFollowingMe(
190+
@Query("o") offset: Int = 0,
191+
@Query("c") count: Int = 100
192+
): NetworkResponse<GetUsersFollowingMe.Response, ErrorResponse>
193+
174194
/**
175195
* A call to this endpoint will retrieve basic metadata about a game, targeted via its unique ID.
176196
*/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.retroachivements.api.data.pojo.user
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
class GetUsersFollowingMe {
6+
data class Response(
7+
@SerializedName("Count")
8+
val count: Long,
9+
@SerializedName("Total")
10+
val total: Long,
11+
@SerializedName("Results")
12+
val results: List<User>,
13+
)
14+
15+
data class User(
16+
@SerializedName("User")
17+
val user: String,
18+
@SerializedName("Points")
19+
val points: Long,
20+
@SerializedName("PointsSoftcore")
21+
val pointsSoftcore: Long,
22+
@SerializedName("AmIFollowing")
23+
val amIFollowing: Boolean,
24+
)
25+
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.retroachivements.api.data.pojo.user
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
class GetUsersIFollow {
6+
data class Response(
7+
@SerializedName("Count")
8+
val count: Long,
9+
@SerializedName("Total")
10+
val total: Long,
11+
@SerializedName("Results")
12+
val results: List<User>,
13+
)
14+
15+
data class User(
16+
@SerializedName("User")
17+
val user: String,
18+
@SerializedName("Points")
19+
val points: Long,
20+
@SerializedName("PointsSoftcore")
21+
val pointsSoftcore: Long,
22+
@SerializedName("IsFollowingMe")
23+
val isFollowingMe: Boolean,
24+
)
25+
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"Count": 3,
3+
"Total": 3,
4+
"Results": [
5+
{
6+
"User": "zuliman92",
7+
"Points": 2071,
8+
"PointsSoftcore": 258,
9+
"AmIFollowing": true
10+
},
11+
{
12+
"User": "SLOslobulus",
13+
"Points": 7081,
14+
"PointsSoftcore": 0,
15+
"AmIFollowing": true
16+
},
17+
{
18+
"User": "Moderator",
19+
"Points": 1000,
20+
"PointsSoftcore": 100,
21+
"AmIFollowing": false
22+
}
23+
]
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"Count": 3,
3+
"Total": 3,
4+
"Results": [
5+
{
6+
"User": "zuliman92",
7+
"Points": 2071,
8+
"PointsSoftcore": 258,
9+
"IsFollowingMe": true
10+
},
11+
{
12+
"User": "Jamiras",
13+
"Points": 117273 ,
14+
"PointsSoftcore": 1350,
15+
"IsFollowingMe": false
16+
},
17+
{
18+
"User": "SLOslobulus",
19+
"Points": 7081,
20+
"PointsSoftcore": 0,
21+
"IsFollowingMe": true
22+
}
23+
]
24+
}

src/test/kotlin/org/retroachivements/api/RetroInterfaceTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,38 @@ class RetroInterfaceTest {
308308
}
309309
}
310310

311+
@Test
312+
fun `check getUsersIFollow response parser`() {
313+
314+
runBlocking {
315+
316+
// obtain mocked version of the API
317+
val api = createMockedApi()
318+
319+
val getUsersIFollow: NetworkResponse<GetUsersIFollow.Response, ErrorResponse> = api.getUsersIFollow()
320+
321+
assert(getUsersIFollow is NetworkResponse.Success)
322+
323+
assertNotNull((getUsersIFollow as NetworkResponse.Success).body)
324+
}
325+
}
326+
327+
@Test
328+
fun `check getUsersFollowingMe response parser`() {
329+
330+
runBlocking {
331+
332+
// obtain mocked version of the API
333+
val api = createMockedApi()
334+
335+
val getUsersFollowingMe: NetworkResponse<GetUsersFollowingMe.Response, ErrorResponse> = api.getUsersFollowingMe()
336+
337+
assert(getUsersFollowingMe is NetworkResponse.Success)
338+
339+
assertNotNull((getUsersFollowingMe as NetworkResponse.Success).body)
340+
}
341+
}
342+
311343
@Test
312344
fun `check getGame response parser`() {
313345

0 commit comments

Comments
 (0)