diff --git a/README.md b/README.md index a9494d1..ffa4c6d 100644 --- a/README.md +++ b/README.md @@ -1177,6 +1177,76 @@ if (response is NetworkResponse.Success) { +
+GetUsersIFollow +
+ +> A call to this endpoint will retrieve a list of users that I follow. + +**Available Parameters** + +| Name | Type | Description | Example | Default | +|:-------|:-----|:---------------------------------------|:--------|:--------| +| offset | Int | number of entries to skip | 100 | 0 | +| count | Int | number of entries to return (max: 500) | 50 | 100 | + +**Example** +```kotlin +val credentials = RetroCredentials("", "") +val api: RetroInterface = RetroClient(credentials).api + +val response: NetworkResponse = 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 +} +``` + +
+ +
+GetUsersFollowingMe +
+ +> A call to this endpoint will retrieve a list of users that are following me. + +**Available Parameters** + +| Name | Type | Description | Example | Default | +|:-------|:-----|:---------------------------------------|:--------|:--------| +| offset | Int | number of entries to skip | 100 | 0 | +| count | Int | number of entries to return (max: 500) | 50 | 100 | + +**Example** +```kotlin +val credentials = RetroCredentials("", "") +val api: RetroInterface = RetroClient(credentials).api + +val response: NetworkResponse = 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 +} +``` + +
+ ## Testing Apache maven must be correctly installed on the system. diff --git a/pom.xml b/pom.xml index 69c75cb..c3eef92 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.retroachievements api-kotlin - 1.0.12 + 1.0.13 diff --git a/src/main/kotlin/org/retroachivements/api/RetroInterface.kt b/src/main/kotlin/org/retroachivements/api/RetroInterface.kt index 9252e09..18144f4 100644 --- a/src/main/kotlin/org/retroachivements/api/RetroInterface.kt +++ b/src/main/kotlin/org/retroachivements/api/RetroInterface.kt @@ -171,6 +171,26 @@ interface RetroInterface { @Query("u") username: String ): NetworkResponse + /** + * A call to this endpoint will retrieve a list of users that I follow. + */ + @Mock @MockResponse(body = "/v1/user/GetUsersIFollow.json") + @POST("/API/API_GetUsersIFollow.php") + suspend fun getUsersIFollow( + @Query("o") offset: Int = 0, + @Query("c") count: Int = 100 + ): NetworkResponse + + /** + * A call to this endpoint will retrieve a list of users that are following me. + */ + @Mock @MockResponse(body = "/v1/user/GetUsersFollowingMe.json") + @POST("/API/GetUsersFollowingMe.php") + suspend fun getUsersFollowingMe( + @Query("o") offset: Int = 0, + @Query("c") count: Int = 100 + ): NetworkResponse + /** * A call to this endpoint will retrieve basic metadata about a game, targeted via its unique ID. */ diff --git a/src/main/kotlin/org/retroachivements/api/data/pojo/user/GetUsersFollowingMe.kt b/src/main/kotlin/org/retroachivements/api/data/pojo/user/GetUsersFollowingMe.kt new file mode 100644 index 0000000..12ad9c8 --- /dev/null +++ b/src/main/kotlin/org/retroachivements/api/data/pojo/user/GetUsersFollowingMe.kt @@ -0,0 +1,26 @@ +package org.retroachivements.api.data.pojo.user + +import com.google.gson.annotations.SerializedName + +class GetUsersFollowingMe { + data class Response( + @SerializedName("Count") + val count: Long, + @SerializedName("Total") + val total: Long, + @SerializedName("Results") + val results: List, + ) + + data class User( + @SerializedName("User") + val user: String, + @SerializedName("Points") + val points: Long, + @SerializedName("PointsSoftcore") + val pointsSoftcore: Long, + @SerializedName("AmIFollowing") + val amIFollowing: Boolean, + ) + +} diff --git a/src/main/kotlin/org/retroachivements/api/data/pojo/user/GetUsersIFollow.kt b/src/main/kotlin/org/retroachivements/api/data/pojo/user/GetUsersIFollow.kt new file mode 100644 index 0000000..817d843 --- /dev/null +++ b/src/main/kotlin/org/retroachivements/api/data/pojo/user/GetUsersIFollow.kt @@ -0,0 +1,26 @@ +package org.retroachivements.api.data.pojo.user + +import com.google.gson.annotations.SerializedName + +class GetUsersIFollow { + data class Response( + @SerializedName("Count") + val count: Long, + @SerializedName("Total") + val total: Long, + @SerializedName("Results") + val results: List, + ) + + data class User( + @SerializedName("User") + val user: String, + @SerializedName("Points") + val points: Long, + @SerializedName("PointsSoftcore") + val pointsSoftcore: Long, + @SerializedName("IsFollowingMe") + val isFollowingMe: Boolean, + ) + +} diff --git a/src/main/resources/mock/v1/user/GetUsersFollowingMe.json b/src/main/resources/mock/v1/user/GetUsersFollowingMe.json new file mode 100644 index 0000000..b8b31ba --- /dev/null +++ b/src/main/resources/mock/v1/user/GetUsersFollowingMe.json @@ -0,0 +1,24 @@ +{ + "Count": 3, + "Total": 3, + "Results": [ + { + "User": "zuliman92", + "Points": 2071, + "PointsSoftcore": 258, + "AmIFollowing": true + }, + { + "User": "SLOslobulus", + "Points": 7081, + "PointsSoftcore": 0, + "AmIFollowing": true + }, + { + "User": "Moderator", + "Points": 1000, + "PointsSoftcore": 100, + "AmIFollowing": false + } + ] +} diff --git a/src/main/resources/mock/v1/user/GetUsersIFollow.json b/src/main/resources/mock/v1/user/GetUsersIFollow.json new file mode 100644 index 0000000..da33f7d --- /dev/null +++ b/src/main/resources/mock/v1/user/GetUsersIFollow.json @@ -0,0 +1,24 @@ +{ + "Count": 3, + "Total": 3, + "Results": [ + { + "User": "zuliman92", + "Points": 2071, + "PointsSoftcore": 258, + "IsFollowingMe": true + }, + { + "User": "Jamiras", + "Points": 117273 , + "PointsSoftcore": 1350, + "IsFollowingMe": false + }, + { + "User": "SLOslobulus", + "Points": 7081, + "PointsSoftcore": 0, + "IsFollowingMe": true + } + ] +} diff --git a/src/test/kotlin/org/retroachivements/api/RetroInterfaceTest.kt b/src/test/kotlin/org/retroachivements/api/RetroInterfaceTest.kt index e3196da..0277dbd 100644 --- a/src/test/kotlin/org/retroachivements/api/RetroInterfaceTest.kt +++ b/src/test/kotlin/org/retroachivements/api/RetroInterfaceTest.kt @@ -308,6 +308,38 @@ class RetroInterfaceTest { } } + @Test + fun `check getUsersIFollow response parser`() { + + runBlocking { + + // obtain mocked version of the API + val api = createMockedApi() + + val getUsersIFollow: NetworkResponse = api.getUsersIFollow() + + assert(getUsersIFollow is NetworkResponse.Success) + + assertNotNull((getUsersIFollow as NetworkResponse.Success).body) + } + } + + @Test + fun `check getUsersFollowingMe response parser`() { + + runBlocking { + + // obtain mocked version of the API + val api = createMockedApi() + + val getUsersFollowingMe: NetworkResponse = api.getUsersFollowingMe() + + assert(getUsersFollowingMe is NetworkResponse.Success) + + assertNotNull((getUsersFollowingMe as NetworkResponse.Success).body) + } + } + @Test fun `check getGame response parser`() {