From 10edc5d94eaac41122c50effe86fbe599ab9a880 Mon Sep 17 00:00:00 2001 From: StayBlue Date: Thu, 30 May 2024 22:19:09 -0700 Subject: [PATCH 01/18] Added a more descriptive error message when ranking user fails --- src/main/kotlin/dev/roava/group/Group.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/dev/roava/group/Group.kt b/src/main/kotlin/dev/roava/group/Group.kt index caf28ec..f83cc0b 100644 --- a/src/main/kotlin/dev/roava/group/Group.kt +++ b/src/main/kotlin/dev/roava/group/Group.kt @@ -243,7 +243,7 @@ class Group { } } }.onFailure { - throw RuntimeException("Could not rank the provided user!") + throw RuntimeException("Could not rank user due to: ${it.message}") } } From 5f8cd4dae660c1803a75dadf30baffab306c87e6 Mon Sep 17 00:00:00 2001 From: StayBlue Date: Thu, 30 May 2024 22:40:40 -0700 Subject: [PATCH 02/18] Fixed an issue where requests would repeat if they required authentication This should fix an issue where the tokens wouldn't be stored, making it so that if the requests being made required authentication, it would always demand an additional request just to get the token. --- .../kotlin/dev/roava/client/RoavaInterceptor.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/dev/roava/client/RoavaInterceptor.kt b/src/main/kotlin/dev/roava/client/RoavaInterceptor.kt index 7b4aaf5..7570a46 100644 --- a/src/main/kotlin/dev/roava/client/RoavaInterceptor.kt +++ b/src/main/kotlin/dev/roava/client/RoavaInterceptor.kt @@ -32,11 +32,20 @@ import okhttp3.Response * For Intercepting calls and adding the X-CSRF-TOKEN to the header if the original request failed (for internal use only). */ internal class RoavaInterceptor: Interceptor { + private val header = "X-CSRF-TOKEN" + + private var token: String? = null + override fun intercept(chain: Interceptor.Chain): Response { - var response = chain.proceed(chain.request()) + val orig = chain.request() + val request = orig.newBuilder() + .header(header, token ?: "") + .build() + + var response = chain.proceed(request) if (response.code() == 403 && !hasToken(response)) { - val token: String? = response.header("X-CSRF-TOKEN") + token = response.header(header) token?.let { response.close() @@ -50,7 +59,7 @@ internal class RoavaInterceptor: Interceptor { private fun hasToken(response: Response?): Boolean { response?.let { - return !it.request().header("X-CSRF-TOKEN").isNullOrEmpty() + return !it.request().header(header).isNullOrEmpty() } return false @@ -58,7 +67,7 @@ internal class RoavaInterceptor: Interceptor { private fun retry(request: Request?, token: String): Request? { return request?.newBuilder() - ?.header("X-CSRF-TOKEN", token) + ?.header(header, token) ?.build() } } \ No newline at end of file From 480144d18771af4c4210555f4c76a3723b49eae7 Mon Sep 17 00:00:00 2001 From: StayBlue Date: Fri, 31 May 2024 18:58:10 -0700 Subject: [PATCH 03/18] Next release --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 736f0f8..82db051 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official org.gradle.caching=true -version = 0.0.2-SNAPSHOT \ No newline at end of file +version = 0.0.3-SNAPSHOT \ No newline at end of file From 6ddb488bebda0f67f576c991de0de38f1162572f Mon Sep 17 00:00:00 2001 From: StayBlue Date: Sat, 1 Jun 2024 23:11:31 -0700 Subject: [PATCH 04/18] Added response codes to exceptions to certain endpoints This will likely be expanded in the future to more than just these methods. --- .../kotlin/dev/roava/client/RoavaClient.kt | 2 +- src/main/kotlin/dev/roava/group/Group.kt | 22 ++++++++++++------- src/main/kotlin/dev/roava/user/User.kt | 21 +++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/dev/roava/client/RoavaClient.kt b/src/main/kotlin/dev/roava/client/RoavaClient.kt index 1457f7a..ab9e2ed 100644 --- a/src/main/kotlin/dev/roava/client/RoavaClient.kt +++ b/src/main/kotlin/dev/roava/client/RoavaClient.kt @@ -58,7 +58,7 @@ class RoavaClient { throw RuntimeException("Your cookie is not set properly! Please make sure that you include the entirety of the string, including the _|WARNING:-") } - request = dev.roava.client.RoavaRequest(cookie) + request = RoavaRequest(cookie) this.cookie = cookie try { diff --git a/src/main/kotlin/dev/roava/group/Group.kt b/src/main/kotlin/dev/roava/group/Group.kt index f83cc0b..1263cf8 100644 --- a/src/main/kotlin/dev/roava/group/Group.kt +++ b/src/main/kotlin/dev/roava/group/Group.kt @@ -30,6 +30,7 @@ import dev.roava.client.RoavaRequest import dev.roava.json.group.GroupData import dev.roava.json.group.RoleRequest import dev.roava.user.User +import retrofit2.HttpException /** * A class which represents a Group. @@ -234,16 +235,21 @@ class Group { roleNumber = getRole(roleNumber).id } - runCatching { + val result = runCatching { client.request.createRequest(GroupApi::class.java, "groups") .rankUser(id, userId, RoleRequest(roleNumber)) - .execute().isSuccessful.also { - if (!it) { - throw RuntimeException("Could not rank the provided user!") - } - } - }.onFailure { - throw RuntimeException("Could not rank user due to: ${it.message}") + .execute() + } + + result.onFailure { exception -> + if (exception is HttpException) { + val errorCode = exception.code() + val message = exception.message() + + throw RuntimeException("Ranking user with id $userId failed with message \"$message\" and response code $errorCode") + } else { + throw RuntimeException("An unknown error has occurred while ranking the user!") + } } } diff --git a/src/main/kotlin/dev/roava/user/User.kt b/src/main/kotlin/dev/roava/user/User.kt index abe198f..7edeb92 100644 --- a/src/main/kotlin/dev/roava/user/User.kt +++ b/src/main/kotlin/dev/roava/user/User.kt @@ -32,6 +32,7 @@ import dev.roava.client.RoavaRequest import dev.roava.group.Group import dev.roava.json.user.UserData import dev.roava.json.user.UserNameRequest +import retrofit2.HttpException /** * A class which represents a User which is not authenticated by the [dev.roava.client.RoavaClient]. @@ -154,17 +155,27 @@ class User { fun getGroups(): List { val groups = mutableListOf() - try { - val groupData = request.createRequest(GroupApi::class.java, "groups") + val result = runCatching { + request.createRequest(GroupApi::class.java, "groups") .getUserRoleInfo(id) .execute() - .body() + } + result.onFailure { exception -> + if (exception is HttpException) { + val errorCode = exception.code() + val message = exception.message() + + throw RuntimeException("Ranking user with id ${this.id} failed with message \"$message\" and response code $errorCode") + } else { + throw RuntimeException("An unknown error has occurred while fetching the user's groups!") + } + }.onSuccess { + val groupData = it.body() + for (group in groupData?.data!!) { groups.add(Group(group.groupData!!)) } - } catch(exception: Exception) { - throw RuntimeException("Could not fetch the user's groups!") } return groups.toList() From 17b547af27ca002f48cfacc8535ec4b8fb90cf54 Mon Sep 17 00:00:00 2001 From: desolationdev Date: Tue, 6 Aug 2024 00:23:07 -0400 Subject: [PATCH 05/18] Added Thumbnails! --- src/main/kotlin/dev/roava/api/ThumbnailApi.kt | 54 ++++++++++ .../dev/roava/json/user/ThumbnailData.kt | 33 +++++++ .../dev/roava/json/user/ThumbnailListData.kt | 33 +++++++ src/main/kotlin/dev/roava/user/User.kt | 99 ++++++++++++++++++- src/test/kotlin/dev/roava/user/UserTest.kt | 13 +++ 5 files changed, 228 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/dev/roava/api/ThumbnailApi.kt create mode 100644 src/main/kotlin/dev/roava/json/user/ThumbnailData.kt create mode 100644 src/main/kotlin/dev/roava/json/user/ThumbnailListData.kt diff --git a/src/main/kotlin/dev/roava/api/ThumbnailApi.kt b/src/main/kotlin/dev/roava/api/ThumbnailApi.kt new file mode 100644 index 0000000..08334c8 --- /dev/null +++ b/src/main/kotlin/dev/roava/api/ThumbnailApi.kt @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2024 RoavaDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.roava.api + +import dev.roava.json.user.ThumbnailListData +import retrofit2.Call +import retrofit2.http.GET +import retrofit2.http.Query + +interface ThumbnailApi { + @GET("/v1/users/avatar") + fun getAvatar( + @Query("userIds") userId: Long, + @Query("size") size: String, + @Query("format") format: String, + @Query("isCircular") circular: Boolean + ): Call + @GET("/v1/users/avatar-headshot") + fun getHeadShot( + @Query("userIds") userId: Long, + @Query("size") size: String, + @Query("format") format: String, + @Query("isCircular") circular: Boolean + ): Call + @GET("/v1/users/avatar-bust") + fun getBust( + @Query("userIds") userId: Long, + @Query("size") size: String, + @Query("format") format: String, + @Query("isCircular") circular: Boolean + ): Call +} diff --git a/src/main/kotlin/dev/roava/json/user/ThumbnailData.kt b/src/main/kotlin/dev/roava/json/user/ThumbnailData.kt new file mode 100644 index 0000000..14ee7f4 --- /dev/null +++ b/src/main/kotlin/dev/roava/json/user/ThumbnailData.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2024 RoavaDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.roava.json.user + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty +@JsonIgnoreProperties(ignoreUnknown = true) +data class ThumbnailData( + @JsonProperty("imageUrl") + val thumbnail: String? +) \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/json/user/ThumbnailListData.kt b/src/main/kotlin/dev/roava/json/user/ThumbnailListData.kt new file mode 100644 index 0000000..3f96014 --- /dev/null +++ b/src/main/kotlin/dev/roava/json/user/ThumbnailListData.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2024 RoavaDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.roava.json.user + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty +@JsonIgnoreProperties(ignoreUnknown = true) +data class ThumbnailListData ( + @JsonProperty("data") + val data: List? +) \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/user/User.kt b/src/main/kotlin/dev/roava/user/User.kt index 7edeb92..3c3ab80 100644 --- a/src/main/kotlin/dev/roava/user/User.kt +++ b/src/main/kotlin/dev/roava/user/User.kt @@ -24,15 +24,15 @@ package dev.roava.user -import dev.roava.api.FriendApi -import dev.roava.api.GroupApi -import dev.roava.api.InventoryApi -import dev.roava.api.UserApi +import com.fasterxml.jackson.databind.ObjectMapper +import dev.roava.api.* import dev.roava.client.RoavaRequest import dev.roava.group.Group +import dev.roava.json.user.ThumbnailListData import dev.roava.json.user.UserData import dev.roava.json.user.UserNameRequest import retrofit2.HttpException +import java.net.URI /** * A class which represents a User which is not authenticated by the [dev.roava.client.RoavaClient]. @@ -181,6 +181,97 @@ class User { return groups.toList() } + /** + * Method to get a User's Avatar + * + * Available Values: + * 30x30, 48x48, 60x60, 75x75, 100x100, 110x110, 140x140, 150x150, 150x200, 180x180, 250x250, 352x352, 420x420, 720x720 + * @throws[RuntimeException] + * @return[String] + */ + @Throws(RuntimeException::class) + fun getAvatar(size: String,isCircular: Boolean): String { + var thumbnail = "" + val result = runCatching { + request.createRequest(ThumbnailApi::class.java, "thumbnails") + .getAvatar(id,size,"Png",isCircular) + .execute() + } + result.onFailure { exception -> + if (exception is HttpException) { + val errorCode = exception.code() + val message = exception.message() + + throw RuntimeException("Grabbing thumbnail of user with id ${this.id} failed with message \"$message\" and response code $errorCode") + } else { + throw RuntimeException("an unknown error has occurred while fetching the user's thumbnail!\n${exception.message}") + } + }.onSuccess { + thumbnail = it.body()?.data?.get(0)?.thumbnail?: "" + } + return thumbnail + } + + /** + * Method to get a User's Headshot + * + * Available Values: + * 30x30, 48x48, 60x60, 75x75, 100x100, 110x110, 140x140, 150x150, 150x200, 180x180, 250x250, 352x352, 420x420, 720x720 + * @throws[RuntimeException] + * @return[String] + */ + @Throws(RuntimeException::class) + fun getHeadShot(size: String,isCircular: Boolean): String { + var thumbnail = "" + val result = runCatching { + request.createRequest(ThumbnailApi::class.java, "thumbnails") + .getHeadShot(id, size, "Png", isCircular) + .execute() + } + result.onFailure { exception -> + if (exception is HttpException) { + val errorCode = exception.code() + val message = exception.message() + + throw RuntimeException("Grabbing headshot of user with id ${this.id} failed with message \"$message\" and response code $errorCode") + } else { + throw RuntimeException("an unknown error has occurred while fetching the user's headshot!\n${exception.message}") + } + }.onSuccess { + thumbnail = it.body()?.data?.get(0)?.thumbnail ?: "" + } + return thumbnail + } + /** + * Method to get a User's Bust + * + * Available Values: + * 48x48, 50x50, 60x60, 75x75, 100x100, 150x150, 180x180, 352x352, 420x420 + * @throws[RuntimeException] + * @return[String] + */ + @Throws(RuntimeException::class) + fun getBust(size: String,isCircular: Boolean): String { + var thumbnail = "" + val result = runCatching { + request.createRequest(ThumbnailApi::class.java, "thumbnails") + .getBust(id, size, "Png", isCircular) + .execute() + } + result.onFailure { exception -> + if (exception is HttpException) { + val errorCode = exception.code() + val message = exception.message() + + throw RuntimeException("Grabbing bust of user with id ${this.id} failed with message \"$message\" and response code $errorCode") + } else { + throw RuntimeException("an unknown error has occurred while fetching the user's bust!\n${exception.message}") + } + }.onSuccess { + thumbnail = it.body()?.data?.get(0)?.thumbnail ?: "" + } + return thumbnail + } /** * Method to get if a User is in a group * diff --git a/src/test/kotlin/dev/roava/user/UserTest.kt b/src/test/kotlin/dev/roava/user/UserTest.kt index 90c6071..17ada75 100644 --- a/src/test/kotlin/dev/roava/user/UserTest.kt +++ b/src/test/kotlin/dev/roava/user/UserTest.kt @@ -27,6 +27,7 @@ package dev.roava.user import org.junit.jupiter.api.Test import org.junit.jupiter.api.Assertions.* +import kotlin.test.assertContains internal class UserTest { private val testUser = User(3838771115) @@ -91,4 +92,16 @@ internal class UserTest { fun testDescription() { assertEquals(testUser.description, "This is a test description") } + @Test + fun testAvatar() { + assertContains(testUser.getAvatar("30x30",true), "https://tr.rbxcdn.com/") + } + @Test + fun testHeadShot(){ + assertContains(testUser.getHeadShot("48x48", true), "https://tr.rbxcdn.com/") + } + @Test + fun testBust(){ + assertContains(testUser.getBust("48x48",true), "https://tr.rbxcdn.com/") + } } \ No newline at end of file From c40a1091d046cad2acf719118bdf30c39b884d45 Mon Sep 17 00:00:00 2001 From: desolationdev Date: Tue, 6 Aug 2024 00:27:32 -0400 Subject: [PATCH 06/18] Cleaning up imports --- src/main/kotlin/dev/roava/user/User.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/kotlin/dev/roava/user/User.kt b/src/main/kotlin/dev/roava/user/User.kt index 3c3ab80..63b6172 100644 --- a/src/main/kotlin/dev/roava/user/User.kt +++ b/src/main/kotlin/dev/roava/user/User.kt @@ -24,15 +24,12 @@ package dev.roava.user -import com.fasterxml.jackson.databind.ObjectMapper import dev.roava.api.* import dev.roava.client.RoavaRequest import dev.roava.group.Group -import dev.roava.json.user.ThumbnailListData import dev.roava.json.user.UserData import dev.roava.json.user.UserNameRequest import retrofit2.HttpException -import java.net.URI /** * A class which represents a User which is not authenticated by the [dev.roava.client.RoavaClient]. From 875e45f47790e1cbc9682cc00fc3de428958fe17 Mon Sep 17 00:00:00 2001 From: desolationdev Date: Thu, 8 Aug 2024 23:50:05 -0400 Subject: [PATCH 07/18] username history --- src/main/kotlin/dev/roava/api/UserApi.kt | 5 +++ .../roava/json/user/UserNameHistoryData.kt | 38 +++++++++++++++++++ src/main/kotlin/dev/roava/user/User.kt | 35 ++++++++++++++++- src/test/kotlin/dev/roava/user/UserTest.kt | 4 ++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/dev/roava/json/user/UserNameHistoryData.kt diff --git a/src/main/kotlin/dev/roava/api/UserApi.kt b/src/main/kotlin/dev/roava/api/UserApi.kt index 84c14d6..fa004c3 100644 --- a/src/main/kotlin/dev/roava/api/UserApi.kt +++ b/src/main/kotlin/dev/roava/api/UserApi.kt @@ -26,12 +26,14 @@ package dev.roava.api import dev.roava.json.user.UserData import dev.roava.json.user.UserListData +import dev.roava.json.user.UserNameHistoryData import dev.roava.json.user.UserNameRequest import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST import retrofit2.http.Path +import retrofit2.http.Query /** * UserApi (for internal use only) @@ -42,4 +44,7 @@ interface UserApi { @POST("/v1/usernames/users") fun getUsernameInformation(@Body data: UserNameRequest): Call + + @GET("/v1/users/{userId}/username-history") + fun getPastUsernames(@Path("userId") userId: Long, @Query("limit") limit: String): Call } \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/json/user/UserNameHistoryData.kt b/src/main/kotlin/dev/roava/json/user/UserNameHistoryData.kt new file mode 100644 index 0000000..ee2a6df --- /dev/null +++ b/src/main/kotlin/dev/roava/json/user/UserNameHistoryData.kt @@ -0,0 +1,38 @@ +/* + * MIT License + * + * Copyright (c) 2024 RoavaDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.roava.json.user + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty + +@JsonIgnoreProperties(ignoreUnknown = true) +data class UserNameHistoryData( + @JsonProperty("data") + val data: List +) +data class UserNameHistory( + @JsonProperty("name") + val name: String? +) \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/user/User.kt b/src/main/kotlin/dev/roava/user/User.kt index 63b6172..3a26f47 100644 --- a/src/main/kotlin/dev/roava/user/User.kt +++ b/src/main/kotlin/dev/roava/user/User.kt @@ -124,7 +124,7 @@ class User { */ @Throws(RuntimeException::class) fun getFriends(): List { - var friends = mutableListOf() + val friends = mutableListOf() try { val userData = request.createRequest(FriendApi::class.java, "friends") @@ -307,4 +307,37 @@ class User { }.getOrElse { throw RuntimeException("Could not fetch the user's items!") } + + /** + * Method to get a user's past 100 usernames + * + * @throws[RuntimeException] + * @return[List] + */ + @Throws(RuntimeException::class) + fun getPastUsers(): List { + val pastNames: MutableList = mutableListOf() + val result = runCatching { + request.createRequest(UserApi::class.java, "users") + .getPastUsernames(id, "100") + .execute() + } + result.onFailure { exception -> + if (exception is HttpException) { + val errorCode = exception.code() + val message = exception.message() + + throw RuntimeException("Grabbing past usernames of user with id ${this.id} failed with message \"$message\" and response code $errorCode") + } else { + throw RuntimeException("an unknown error has occurred while fetching the user's past names!\n${exception.message}") + } + } + result.onSuccess { + val data = it.body()?.data ?: throw RuntimeException("An unknown error has occurred") + for (i in data) { + pastNames += i.name ?: continue + } + } + return pastNames + } } \ No newline at end of file diff --git a/src/test/kotlin/dev/roava/user/UserTest.kt b/src/test/kotlin/dev/roava/user/UserTest.kt index 17ada75..5bb4027 100644 --- a/src/test/kotlin/dev/roava/user/UserTest.kt +++ b/src/test/kotlin/dev/roava/user/UserTest.kt @@ -104,4 +104,8 @@ internal class UserTest { fun testBust(){ assertContains(testUser.getBust("48x48",true), "https://tr.rbxcdn.com/") } + @Test + fun testPast(){ + println(testUser.getPastUsers()) + } } \ No newline at end of file From 2e9474d2e569f3ebbe063a144cdcab72124ce312 Mon Sep 17 00:00:00 2001 From: desolationdev Date: Thu, 8 Aug 2024 23:51:56 -0400 Subject: [PATCH 08/18] forgot i messed up the test lol --- src/test/kotlin/dev/roava/user/UserTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/dev/roava/user/UserTest.kt b/src/test/kotlin/dev/roava/user/UserTest.kt index 5bb4027..9730c71 100644 --- a/src/test/kotlin/dev/roava/user/UserTest.kt +++ b/src/test/kotlin/dev/roava/user/UserTest.kt @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.Assertions.* import kotlin.test.assertContains +import kotlin.test.assertIs internal class UserTest { private val testUser = User(3838771115) @@ -106,6 +107,6 @@ internal class UserTest { } @Test fun testPast(){ - println(testUser.getPastUsers()) + assertIs>(testUser.getPastUsers()) } } \ No newline at end of file From bfedc55bf6141deece254220f12992a85a134c1b Mon Sep 17 00:00:00 2001 From: desolationdev Date: Sat, 10 Aug 2024 19:54:21 -0400 Subject: [PATCH 09/18] Group Members by rank Tests pass --- .idea/misc.xml | 3 ++ src/main/kotlin/dev/roava/api/GroupApi.kt | 4 ++ src/main/kotlin/dev/roava/group/Group.kt | 44 +++++++++++++++++ .../dev/roava/json/group/GroupRankData.kt | 48 +++++++++++++++++++ src/test/kotlin/dev/roava/group/GroupTest.kt | 5 ++ 5 files changed, 104 insertions(+) create mode 100644 src/main/kotlin/dev/roava/json/group/GroupRankData.kt diff --git a/.idea/misc.xml b/.idea/misc.xml index 38167d7..2266f6b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ + + + diff --git a/src/main/kotlin/dev/roava/api/GroupApi.kt b/src/main/kotlin/dev/roava/api/GroupApi.kt index 46464a3..6fe4b82 100644 --- a/src/main/kotlin/dev/roava/api/GroupApi.kt +++ b/src/main/kotlin/dev/roava/api/GroupApi.kt @@ -25,6 +25,7 @@ package dev.roava.api import dev.roava.json.group.GroupData +import dev.roava.json.group.GroupRankData import dev.roava.json.group.RoleListData import dev.roava.json.group.RoleRequest import dev.roava.json.user.UserRolesData @@ -52,4 +53,7 @@ interface GroupApi { @DELETE("/v1/groups/{groupId}/users/{userId}") fun exileUser(@Path("groupId") groupId: Int, @Path("userId") userId: Long): Call + + @GET("v1/groups/{groupId}/roles/{roleSetId}/users") + fun getGroupRankMembers(@Path("groupId") groupId: Int, @Path("roleSetId") roleSetId: Int, @Query("limit") limit: Int, @Query("cursor") cursor: String? = null): Call } \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/group/Group.kt b/src/main/kotlin/dev/roava/group/Group.kt index 1263cf8..8e0bbfb 100644 --- a/src/main/kotlin/dev/roava/group/Group.kt +++ b/src/main/kotlin/dev/roava/group/Group.kt @@ -28,6 +28,7 @@ import dev.roava.api.GroupApi import dev.roava.client.RoavaClient import dev.roava.client.RoavaRequest import dev.roava.json.group.GroupData +import dev.roava.json.group.GroupRankListData import dev.roava.json.group.RoleRequest import dev.roava.user.User import retrofit2.HttpException @@ -283,4 +284,47 @@ class Group { fun exileUser(user: User) { exileUser(user.id) } + + /** + * Method to grab all group members with the provided roleset + * + * @return[GroupRankListData] + * @param[roleSetId] The roleSetId of the group rank. + * @throws[RuntimeException] + */ + @Throws(RuntimeException::class) + fun getGroupRankMembers(roleSetId: Int): List{ + val members: MutableList = mutableListOf() + var nextPageCursor: String? = null + fun makeRequest(){ + val result = runCatching { + request.createRequest(GroupApi::class.java, "groups") + .getGroupRankMembers(this.id,roleSetId, 100, nextPageCursor) + .execute() + } + result.onFailure { exception -> + if (exception is HttpException) { + val errorCode = exception.code() + val message = exception.message() + + throw RuntimeException("Grabbing members in the group with id ${this.id} & roleSetId of $roleSetId failed with message \"$message\" and response code $errorCode") + } else { + throw RuntimeException("an unknown error has occurred while fetching the members with that rank!\n${exception.message}") + } + } + result.onSuccess { + nextPageCursor = it.body()?.nextPageCursor + val data = it.body()?.data ?: throw RuntimeException("An unknown error has occurred") + for(i in data){ + members += GroupRankListData(i.hasVerifiedBadge,i.userId,i.username,i.displayName) + } + } + } + makeRequest() + while(nextPageCursor != null) { + makeRequest() + } + return members + } + } \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/json/group/GroupRankData.kt b/src/main/kotlin/dev/roava/json/group/GroupRankData.kt new file mode 100644 index 0000000..b2c1eb7 --- /dev/null +++ b/src/main/kotlin/dev/roava/json/group/GroupRankData.kt @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) 2024 RoavaDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.roava.json.group + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty + +@JsonIgnoreProperties(ignoreUnknown = true) +data class GroupRankData( + @JsonProperty("nextPageCursor") + val nextPageCursor: String?, + @JsonProperty("previousPageCursor") + val previousPageCursor: String?, + @JsonProperty("data") + val data: List +) +data class GroupRankListData( + @JsonProperty("hasVerifiedBadge") + val hasVerifiedBadge: Boolean?, + @JsonProperty("userId") + val userId: Long?, + @JsonProperty("username") + val username: String?, + @JsonProperty("displayName") + val displayName: String? +) \ No newline at end of file diff --git a/src/test/kotlin/dev/roava/group/GroupTest.kt b/src/test/kotlin/dev/roava/group/GroupTest.kt index e3a3c7a..ac9629e 100644 --- a/src/test/kotlin/dev/roava/group/GroupTest.kt +++ b/src/test/kotlin/dev/roava/group/GroupTest.kt @@ -119,4 +119,9 @@ internal class GroupTest { assertThrows(RuntimeException::class.java, executable) } + @Test + fun testGroupRankMembers(){ + val group = Group(16171236).getGroupRankMembers(90545787) + assertEquals(group.size, 279) + } } \ No newline at end of file From 1e95185dcb820c9f6847c9eba693fd8389bf61d6 Mon Sep 17 00:00:00 2001 From: desolationdev Date: Sat, 10 Aug 2024 20:01:32 -0400 Subject: [PATCH 10/18] Past Usernames --- src/main/kotlin/dev/roava/api/UserApi.kt | 2 +- .../kotlin/dev/roava/json/user/UserNameHistoryData.kt | 2 ++ src/main/kotlin/dev/roava/user/User.kt | 10 +++++++++- src/test/kotlin/dev/roava/user/UserTest.kt | 6 ++---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/dev/roava/api/UserApi.kt b/src/main/kotlin/dev/roava/api/UserApi.kt index fa004c3..03245c0 100644 --- a/src/main/kotlin/dev/roava/api/UserApi.kt +++ b/src/main/kotlin/dev/roava/api/UserApi.kt @@ -46,5 +46,5 @@ interface UserApi { fun getUsernameInformation(@Body data: UserNameRequest): Call @GET("/v1/users/{userId}/username-history") - fun getPastUsernames(@Path("userId") userId: Long, @Query("limit") limit: String): Call + fun getPastUsernames(@Path("userId") userId: Long, @Query("limit") limit: String, @Query("cursor") cursor: String? = null): Call } \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/json/user/UserNameHistoryData.kt b/src/main/kotlin/dev/roava/json/user/UserNameHistoryData.kt index ee2a6df..0689a23 100644 --- a/src/main/kotlin/dev/roava/json/user/UserNameHistoryData.kt +++ b/src/main/kotlin/dev/roava/json/user/UserNameHistoryData.kt @@ -29,6 +29,8 @@ import com.fasterxml.jackson.annotation.JsonProperty @JsonIgnoreProperties(ignoreUnknown = true) data class UserNameHistoryData( + @JsonProperty("nextPageCursor") + val nextPageCursor: String?, @JsonProperty("data") val data: List ) diff --git a/src/main/kotlin/dev/roava/user/User.kt b/src/main/kotlin/dev/roava/user/User.kt index 3a26f47..fd1a920 100644 --- a/src/main/kotlin/dev/roava/user/User.kt +++ b/src/main/kotlin/dev/roava/user/User.kt @@ -316,10 +316,12 @@ class User { */ @Throws(RuntimeException::class) fun getPastUsers(): List { + var cursor: String? = null val pastNames: MutableList = mutableListOf() + fun makeRequest(){ val result = runCatching { request.createRequest(UserApi::class.java, "users") - .getPastUsernames(id, "100") + .getPastUsernames(id, "100", cursor) .execute() } result.onFailure { exception -> @@ -333,11 +335,17 @@ class User { } } result.onSuccess { + cursor = it.body()?.nextPageCursor val data = it.body()?.data ?: throw RuntimeException("An unknown error has occurred") for (i in data) { pastNames += i.name ?: continue } } + } + makeRequest() + while(cursor != null){ + makeRequest() + } return pastNames } } \ No newline at end of file diff --git a/src/test/kotlin/dev/roava/user/UserTest.kt b/src/test/kotlin/dev/roava/user/UserTest.kt index 9730c71..06f6f7f 100644 --- a/src/test/kotlin/dev/roava/user/UserTest.kt +++ b/src/test/kotlin/dev/roava/user/UserTest.kt @@ -24,11 +24,9 @@ package dev.roava.user -import org.junit.jupiter.api.Test - import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test import kotlin.test.assertContains -import kotlin.test.assertIs internal class UserTest { private val testUser = User(3838771115) @@ -107,6 +105,6 @@ internal class UserTest { } @Test fun testPast(){ - assertIs>(testUser.getPastUsers()) + assertEquals(User(1157409).getPastUsers().size, 127) } } \ No newline at end of file From f79a07f5c47d5071950039d0bed8fdfdb7154310 Mon Sep 17 00:00:00 2001 From: desolationdev Date: Sat, 10 Aug 2024 20:35:46 -0400 Subject: [PATCH 11/18] Group Members , Test passing --- src/main/kotlin/dev/roava/api/GroupApi.kt | 8 +-- src/main/kotlin/dev/roava/group/Group.kt | 49 ++++++++++++- .../dev/roava/json/group/GroupMemberData.kt | 71 +++++++++++++++++++ src/test/kotlin/dev/roava/group/GroupTest.kt | 7 ++ 4 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/dev/roava/json/group/GroupMemberData.kt diff --git a/src/main/kotlin/dev/roava/api/GroupApi.kt b/src/main/kotlin/dev/roava/api/GroupApi.kt index 6fe4b82..a1233e9 100644 --- a/src/main/kotlin/dev/roava/api/GroupApi.kt +++ b/src/main/kotlin/dev/roava/api/GroupApi.kt @@ -24,10 +24,7 @@ package dev.roava.api -import dev.roava.json.group.GroupData -import dev.roava.json.group.GroupRankData -import dev.roava.json.group.RoleListData -import dev.roava.json.group.RoleRequest +import dev.roava.json.group.* import dev.roava.json.user.UserRolesData import retrofit2.Call import retrofit2.http.* @@ -56,4 +53,7 @@ interface GroupApi { @GET("v1/groups/{groupId}/roles/{roleSetId}/users") fun getGroupRankMembers(@Path("groupId") groupId: Int, @Path("roleSetId") roleSetId: Int, @Query("limit") limit: Int, @Query("cursor") cursor: String? = null): Call + + @GET("v1/groups/{groupId}/users") + fun getGroupMembers(@Path("groupId") groupId: Int, @Query("limit") limit: Int, @Query("cursor") cursor: String? = null): Call } \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/group/Group.kt b/src/main/kotlin/dev/roava/group/Group.kt index 8e0bbfb..9763648 100644 --- a/src/main/kotlin/dev/roava/group/Group.kt +++ b/src/main/kotlin/dev/roava/group/Group.kt @@ -27,9 +27,7 @@ package dev.roava.group import dev.roava.api.GroupApi import dev.roava.client.RoavaClient import dev.roava.client.RoavaRequest -import dev.roava.json.group.GroupData -import dev.roava.json.group.GroupRankListData -import dev.roava.json.group.RoleRequest +import dev.roava.json.group.* import dev.roava.user.User import retrofit2.HttpException @@ -326,5 +324,50 @@ class Group { } return members } + /** + * Method to grab all group members with the provided roleset + * + * @return[GroupRankListData] + * @param[roleSetId] The roleSetId of the group rank. + * @throws[RuntimeException] + */ + @Throws(RuntimeException::class) + fun getMembers(): Map{ + val members: MutableMap = mutableMapOf() + var nextPageCursor: String? = null + fun makeRequest(){ + val result = runCatching { + request.createRequest(GroupApi::class.java, "groups") + .getGroupMembers(this.id,100, nextPageCursor) + .execute() + } + result.onFailure { exception -> + if (exception is HttpException) { + val errorCode = exception.code() + val message = exception.message() + + throw RuntimeException("Grabbing members in the group with id ${this.id} failed with message \"$message\" and response code $errorCode") + } else { + throw RuntimeException("an unknown error has occurred while fetching the members!\n${exception.message}") + } + } + result.onSuccess { + nextPageCursor = it.body()?.nextPageCursor + val data = it.body()?.data ?: throw RuntimeException("An unknown error has occurred") + for(i in data){ + val u = i.user + val r = i.role + val userData = GroupMemberUserData(u.username,u.userId,u.displayName,u.hasVerifiedBadge,u.buildersClubMembershipType) + val roleData = GroupMemberRoleData(r.roleId,r.name,r.description,r.rank,r.memberCount) + members += userData to roleData + } + } + } + makeRequest() + while(nextPageCursor != null) { + makeRequest() + } + return members + } } \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/json/group/GroupMemberData.kt b/src/main/kotlin/dev/roava/json/group/GroupMemberData.kt new file mode 100644 index 0000000..16948fb --- /dev/null +++ b/src/main/kotlin/dev/roava/json/group/GroupMemberData.kt @@ -0,0 +1,71 @@ +/* + * MIT License + * + * Copyright (c) 2024 RoavaDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.roava.json.group + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty + +@JsonIgnoreProperties(ignoreUnknown = true) +data class GroupMemberData ( + @JsonProperty("nextPageCursor") + val nextPageCursor: String?, + @JsonProperty("previousPageCursor") + val previousCursor: String?, + @JsonProperty("data") + val data: List +) +@JsonIgnoreProperties(ignoreUnknown = true) +data class GroupMemberListData ( + @JsonProperty("user") + val user: GroupMemberUserData, + @JsonProperty("role") + val role: GroupMemberRoleData +) +@JsonIgnoreProperties(ignoreUnknown = true) +data class GroupMemberUserData ( + @JsonProperty("username") + val username: String?, + @JsonProperty("userId") + val userId: Long?, + @JsonProperty("displayName") + val displayName: String?, + @JsonProperty("hasVerifiedBadge") + val hasVerifiedBadge: Boolean?, + @JsonProperty("buildersClubMembershipType") + val buildersClubMembershipType: Long? +) +@JsonIgnoreProperties(ignoreUnknown = true) +data class GroupMemberRoleData ( + @JsonProperty("id") + val roleId: Long?, + @JsonProperty("name") + val name: String?, + @JsonProperty("description") + val description: String?, + @JsonProperty("rank") + val rank: Long?, + @JsonProperty("memberCount") + val memberCount: Long? +) \ No newline at end of file diff --git a/src/test/kotlin/dev/roava/group/GroupTest.kt b/src/test/kotlin/dev/roava/group/GroupTest.kt index ac9629e..f1db642 100644 --- a/src/test/kotlin/dev/roava/group/GroupTest.kt +++ b/src/test/kotlin/dev/roava/group/GroupTest.kt @@ -24,9 +24,12 @@ package dev.roava.group +import dev.roava.json.group.GroupMemberRoleData +import dev.roava.json.group.GroupMemberUserData import org.junit.jupiter.api.Test import org.junit.jupiter.api.Assertions.* +import kotlin.test.assertIs internal class GroupTest { private val testGroup = Group(15771240) @@ -124,4 +127,8 @@ internal class GroupTest { val group = Group(16171236).getGroupRankMembers(90545787) assertEquals(group.size, 279) } + @Test + fun testGroupMembers(){ + assertIs>(testGroup.getMembers()) + } } \ No newline at end of file From c5208685f96e931c31ff21855a3c58be7d621ee4 Mon Sep 17 00:00:00 2001 From: desolationdev Date: Sat, 10 Aug 2024 20:41:04 -0400 Subject: [PATCH 12/18] forgot to edit this --- src/main/kotlin/dev/roava/group/Group.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/dev/roava/group/Group.kt b/src/main/kotlin/dev/roava/group/Group.kt index 9763648..1080795 100644 --- a/src/main/kotlin/dev/roava/group/Group.kt +++ b/src/main/kotlin/dev/roava/group/Group.kt @@ -325,10 +325,9 @@ class Group { return members } /** - * Method to grab all group members with the provided roleset + * Method to grab all group members * - * @return[GroupRankListData] - * @param[roleSetId] The roleSetId of the group rank. + * @return[Map] * @throws[RuntimeException] */ @Throws(RuntimeException::class) From cf47ec913c6542d574d582bd310bfbec9305653e Mon Sep 17 00:00:00 2001 From: desolationdev Date: Sat, 10 Aug 2024 20:43:15 -0400 Subject: [PATCH 13/18] less code --- src/main/kotlin/dev/roava/group/Group.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/kotlin/dev/roava/group/Group.kt b/src/main/kotlin/dev/roava/group/Group.kt index 1080795..1a5557c 100644 --- a/src/main/kotlin/dev/roava/group/Group.kt +++ b/src/main/kotlin/dev/roava/group/Group.kt @@ -354,11 +354,7 @@ class Group { nextPageCursor = it.body()?.nextPageCursor val data = it.body()?.data ?: throw RuntimeException("An unknown error has occurred") for(i in data){ - val u = i.user - val r = i.role - val userData = GroupMemberUserData(u.username,u.userId,u.displayName,u.hasVerifiedBadge,u.buildersClubMembershipType) - val roleData = GroupMemberRoleData(r.roleId,r.name,r.description,r.rank,r.memberCount) - members += userData to roleData + members += i.user to i.role } } } From 2063108ccc7efb4c8f125a841f281a38b18db73d Mon Sep 17 00:00:00 2001 From: desolationdev Date: Sat, 10 Aug 2024 23:37:26 -0400 Subject: [PATCH 14/18] fixed test --- src/test/kotlin/dev/roava/group/GroupTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/dev/roava/group/GroupTest.kt b/src/test/kotlin/dev/roava/group/GroupTest.kt index f1db642..88fd066 100644 --- a/src/test/kotlin/dev/roava/group/GroupTest.kt +++ b/src/test/kotlin/dev/roava/group/GroupTest.kt @@ -24,6 +24,7 @@ package dev.roava.group +import dev.roava.json.group.GroupMemberListData import dev.roava.json.group.GroupMemberRoleData import dev.roava.json.group.GroupMemberUserData import org.junit.jupiter.api.Test @@ -125,7 +126,7 @@ internal class GroupTest { @Test fun testGroupRankMembers(){ val group = Group(16171236).getGroupRankMembers(90545787) - assertEquals(group.size, 279) + assertIs>(group) } @Test fun testGroupMembers(){ From 5177b3cd4d2f4ddce96ee0a77fba9fa05ec2c4fe Mon Sep 17 00:00:00 2001 From: desolationdev Date: Sat, 10 Aug 2024 23:37:57 -0400 Subject: [PATCH 15/18] fixed test --- src/test/kotlin/dev/roava/group/GroupTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/dev/roava/group/GroupTest.kt b/src/test/kotlin/dev/roava/group/GroupTest.kt index 88fd066..fb1492c 100644 --- a/src/test/kotlin/dev/roava/group/GroupTest.kt +++ b/src/test/kotlin/dev/roava/group/GroupTest.kt @@ -125,7 +125,7 @@ internal class GroupTest { } @Test fun testGroupRankMembers(){ - val group = Group(16171236).getGroupRankMembers(90545787) + val group = testGroup.getGroupRankMembers(88561132) assertIs>(group) } @Test From e2bef1e59d247c5da8ed63be59c02cb6feab552e Mon Sep 17 00:00:00 2001 From: desolationdev Date: Tue, 27 Aug 2024 21:30:53 -0400 Subject: [PATCH 16/18] Work In Progress --- src/main/kotlin/dev/roava/api/GroupApi.kt | 3 +- src/main/kotlin/dev/roava/group/Group.kt | 24 +++++--- .../dev/roava/json/group/GroupMemberData.kt | 9 --- src/main/kotlin/dev/roava/util/Pagination.kt | 59 +++++++++++++++++++ src/test/kotlin/dev/roava/group/GroupTest.kt | 4 +- 5 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 src/main/kotlin/dev/roava/util/Pagination.kt diff --git a/src/main/kotlin/dev/roava/api/GroupApi.kt b/src/main/kotlin/dev/roava/api/GroupApi.kt index a1233e9..7d2a1f2 100644 --- a/src/main/kotlin/dev/roava/api/GroupApi.kt +++ b/src/main/kotlin/dev/roava/api/GroupApi.kt @@ -26,6 +26,7 @@ package dev.roava.api import dev.roava.json.group.* import dev.roava.json.user.UserRolesData +import dev.roava.util.Pagination import retrofit2.Call import retrofit2.http.* @@ -55,5 +56,5 @@ interface GroupApi { fun getGroupRankMembers(@Path("groupId") groupId: Int, @Path("roleSetId") roleSetId: Int, @Query("limit") limit: Int, @Query("cursor") cursor: String? = null): Call @GET("v1/groups/{groupId}/users") - fun getGroupMembers(@Path("groupId") groupId: Int, @Query("limit") limit: Int, @Query("cursor") cursor: String? = null): Call + fun getGroupMembers(@Path("groupId") groupId: Int, @Query("limit") limit: Int, @Query("cursor") cursor: String? = null): Call> } \ No newline at end of file diff --git a/src/main/kotlin/dev/roava/group/Group.kt b/src/main/kotlin/dev/roava/group/Group.kt index 1a5557c..b7b8a21 100644 --- a/src/main/kotlin/dev/roava/group/Group.kt +++ b/src/main/kotlin/dev/roava/group/Group.kt @@ -29,6 +29,8 @@ import dev.roava.client.RoavaClient import dev.roava.client.RoavaRequest import dev.roava.json.group.* import dev.roava.user.User +import dev.roava.util.Pagination +import retrofit2.Call import retrofit2.HttpException /** @@ -336,9 +338,15 @@ class Group { var nextPageCursor: String? = null fun makeRequest(){ val result = runCatching { - request.createRequest(GroupApi::class.java, "groups") - .getGroupMembers(this.id,100, nextPageCursor) - .execute() +// request.createRequest(GroupApi::class.java, "groups") +// .getGroupMembers(this.id,100, nextPageCursor) +// .execute() + + val request_ = request.createRequest(GroupApi::class.java, "groups")::getGroupMembers + + + request_(this.id,100,nextPageCursor).execute() + } result.onFailure { exception -> if (exception is HttpException) { @@ -351,11 +359,11 @@ class Group { } } result.onSuccess { - nextPageCursor = it.body()?.nextPageCursor - val data = it.body()?.data ?: throw RuntimeException("An unknown error has occurred") - for(i in data){ - members += i.user to i.role - } +// nextPageCursor = it. +// val data = it.body()?.data ?: throw RuntimeException("An unknown error has occurred") +// for(i in data){ +// members += i.user to i.role +// } } } makeRequest() diff --git a/src/main/kotlin/dev/roava/json/group/GroupMemberData.kt b/src/main/kotlin/dev/roava/json/group/GroupMemberData.kt index 16948fb..78f5b88 100644 --- a/src/main/kotlin/dev/roava/json/group/GroupMemberData.kt +++ b/src/main/kotlin/dev/roava/json/group/GroupMemberData.kt @@ -29,15 +29,6 @@ import com.fasterxml.jackson.annotation.JsonProperty @JsonIgnoreProperties(ignoreUnknown = true) data class GroupMemberData ( - @JsonProperty("nextPageCursor") - val nextPageCursor: String?, - @JsonProperty("previousPageCursor") - val previousCursor: String?, - @JsonProperty("data") - val data: List -) -@JsonIgnoreProperties(ignoreUnknown = true) -data class GroupMemberListData ( @JsonProperty("user") val user: GroupMemberUserData, @JsonProperty("role") diff --git a/src/main/kotlin/dev/roava/util/Pagination.kt b/src/main/kotlin/dev/roava/util/Pagination.kt new file mode 100644 index 0000000..a43489c --- /dev/null +++ b/src/main/kotlin/dev/roava/util/Pagination.kt @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) 2024 RoavaDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.roava.util + +import com.fasterxml.jackson.annotation.JsonProperty +import dev.roava.client.RoavaClient +import dev.roava.client.RoavaRequest +import kotlin.reflect.KFunction + +// T would be a data class +class Pagination( + private val url: String, + private val client: RoavaClient, + + @JsonProperty("nextPageCursor") + private val nextCursor: String?, + + @JsonProperty("previousPageCursor") + private val previousCursor: String?, + + @JsonProperty("data") + private val data: List? // this is where we actually get what we are after +) { + // this function might or might not be necessary + private fun paginate(function: () -> Any): Pagination { + // return a new pagination object where you take the current URL with the cursor and return a new pagination object + function + } + + fun next(): Pagination? { + return this.nextCursor?.let { this.paginate(it) } + } + + fun previous(): Pagination? { + return this.previousCursor?.let { this.paginate(it) }; + } +} \ No newline at end of file diff --git a/src/test/kotlin/dev/roava/group/GroupTest.kt b/src/test/kotlin/dev/roava/group/GroupTest.kt index fb1492c..a7d30d6 100644 --- a/src/test/kotlin/dev/roava/group/GroupTest.kt +++ b/src/test/kotlin/dev/roava/group/GroupTest.kt @@ -24,7 +24,7 @@ package dev.roava.group -import dev.roava.json.group.GroupMemberListData +import dev.roava.json.group.GroupMemberData import dev.roava.json.group.GroupMemberRoleData import dev.roava.json.group.GroupMemberUserData import org.junit.jupiter.api.Test @@ -126,7 +126,7 @@ internal class GroupTest { @Test fun testGroupRankMembers(){ val group = testGroup.getGroupRankMembers(88561132) - assertIs>(group) + assertIs>(group) } @Test fun testGroupMembers(){ From 0b075997877930f919dfac3d82e643b0258242fd Mon Sep 17 00:00:00 2001 From: desolationdev Date: Tue, 27 Aug 2024 21:35:49 -0400 Subject: [PATCH 17/18] fixed version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 82db051..7c1de97 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official org.gradle.caching=true -version = 0.0.3-SNAPSHOT \ No newline at end of file +version = 0.0.5-SNAPSHOT \ No newline at end of file From fba271a19698e2d828b6e5870b65ad591ea8badf Mon Sep 17 00:00:00 2001 From: desolationdev Date: Sun, 29 Sep 2024 22:09:06 -0400 Subject: [PATCH 18/18] wip --- src/main/kotlin/dev/roava/group/Group.kt | 3 +-- src/main/kotlin/dev/roava/util/Pagination.kt | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/dev/roava/group/Group.kt b/src/main/kotlin/dev/roava/group/Group.kt index b7b8a21..b9745d4 100644 --- a/src/main/kotlin/dev/roava/group/Group.kt +++ b/src/main/kotlin/dev/roava/group/Group.kt @@ -343,8 +343,7 @@ class Group { // .execute() val request_ = request.createRequest(GroupApi::class.java, "groups")::getGroupMembers - - + Pagination.next() request_(this.id,100,nextPageCursor).execute() } diff --git a/src/main/kotlin/dev/roava/util/Pagination.kt b/src/main/kotlin/dev/roava/util/Pagination.kt index a43489c..afe67b5 100644 --- a/src/main/kotlin/dev/roava/util/Pagination.kt +++ b/src/main/kotlin/dev/roava/util/Pagination.kt @@ -27,6 +27,7 @@ package dev.roava.util import com.fasterxml.jackson.annotation.JsonProperty import dev.roava.client.RoavaClient import dev.roava.client.RoavaRequest +import retrofit2.Call import kotlin.reflect.KFunction // T would be a data class @@ -46,7 +47,7 @@ class Pagination( // this function might or might not be necessary private fun paginate(function: () -> Any): Pagination { // return a new pagination object where you take the current URL with the cursor and return a new pagination object - function + return function.execute() } fun next(): Pagination? {