|  | 
| 24 | 24 | 
 | 
| 25 | 25 | package dev.roava.user | 
| 26 | 26 | 
 | 
| 27 |  | -import dev.roava.api.FriendApi | 
| 28 |  | -import dev.roava.api.GroupApi | 
| 29 |  | -import dev.roava.api.InventoryApi | 
| 30 |  | -import dev.roava.api.UserApi | 
|  | 27 | +import com.fasterxml.jackson.databind.ObjectMapper | 
|  | 28 | +import dev.roava.api.* | 
| 31 | 29 | import dev.roava.client.RoavaRequest | 
| 32 | 30 | import dev.roava.group.Group | 
|  | 31 | +import dev.roava.json.user.ThumbnailListData | 
| 33 | 32 | import dev.roava.json.user.UserData | 
| 34 | 33 | import dev.roava.json.user.UserNameRequest | 
| 35 | 34 | import retrofit2.HttpException | 
|  | 35 | +import java.net.URI | 
| 36 | 36 | 
 | 
| 37 | 37 | /** | 
| 38 | 38 |  * A class which represents a User which is not authenticated by the [dev.roava.client.RoavaClient]. | 
| @@ -181,6 +181,97 @@ class User { | 
| 181 | 181 |         return groups.toList() | 
| 182 | 182 |     } | 
| 183 | 183 | 
 | 
|  | 184 | +        /** | 
|  | 185 | +     * Method to get a User's Avatar | 
|  | 186 | +     * | 
|  | 187 | +     * Available Values: | 
|  | 188 | +     * 30x30, 48x48, 60x60, 75x75, 100x100, 110x110, 140x140, 150x150, 150x200, 180x180, 250x250, 352x352, 420x420, 720x720 | 
|  | 189 | +     * @throws[RuntimeException] | 
|  | 190 | +     * @return[String] | 
|  | 191 | +     */ | 
|  | 192 | +    @Throws(RuntimeException::class) | 
|  | 193 | +    fun getAvatar(size: String,isCircular: Boolean): String { | 
|  | 194 | +        var thumbnail = "" | 
|  | 195 | +        val result = runCatching { | 
|  | 196 | +            request.createRequest(ThumbnailApi::class.java, "thumbnails") | 
|  | 197 | +                .getAvatar(id,size,"Png",isCircular) | 
|  | 198 | +                .execute() | 
|  | 199 | +        } | 
|  | 200 | +        result.onFailure { exception -> | 
|  | 201 | +            if (exception is HttpException) { | 
|  | 202 | +                val errorCode = exception.code() | 
|  | 203 | +                val message = exception.message() | 
|  | 204 | + | 
|  | 205 | +                throw RuntimeException("Grabbing thumbnail of user with id ${this.id} failed with message \"$message\" and response code $errorCode") | 
|  | 206 | +            } else { | 
|  | 207 | +                throw RuntimeException("an unknown error has occurred while fetching the user's thumbnail!\n${exception.message}") | 
|  | 208 | +            } | 
|  | 209 | +        }.onSuccess { | 
|  | 210 | +            thumbnail = it.body()?.data?.get(0)?.thumbnail?: "" | 
|  | 211 | +        } | 
|  | 212 | +        return thumbnail | 
|  | 213 | +    } | 
|  | 214 | + | 
|  | 215 | +    /** | 
|  | 216 | +     * Method to get a User's Headshot | 
|  | 217 | +     * | 
|  | 218 | +     * Available Values: | 
|  | 219 | +     * 30x30, 48x48, 60x60, 75x75, 100x100, 110x110, 140x140, 150x150, 150x200, 180x180, 250x250, 352x352, 420x420, 720x720 | 
|  | 220 | +     * @throws[RuntimeException] | 
|  | 221 | +     * @return[String] | 
|  | 222 | +     */ | 
|  | 223 | +    @Throws(RuntimeException::class) | 
|  | 224 | +    fun getHeadShot(size: String,isCircular: Boolean): String { | 
|  | 225 | +        var thumbnail = "" | 
|  | 226 | +        val result = runCatching { | 
|  | 227 | +            request.createRequest(ThumbnailApi::class.java, "thumbnails") | 
|  | 228 | +                .getHeadShot(id, size, "Png", isCircular) | 
|  | 229 | +                .execute() | 
|  | 230 | +        } | 
|  | 231 | +        result.onFailure { exception -> | 
|  | 232 | +            if (exception is HttpException) { | 
|  | 233 | +                val errorCode = exception.code() | 
|  | 234 | +                val message = exception.message() | 
|  | 235 | + | 
|  | 236 | +                throw RuntimeException("Grabbing headshot of user with id ${this.id} failed with message \"$message\" and response code $errorCode") | 
|  | 237 | +            } else { | 
|  | 238 | +                throw RuntimeException("an unknown error has occurred while fetching the user's headshot!\n${exception.message}") | 
|  | 239 | +            } | 
|  | 240 | +        }.onSuccess { | 
|  | 241 | +            thumbnail = it.body()?.data?.get(0)?.thumbnail ?: "" | 
|  | 242 | +        } | 
|  | 243 | +        return thumbnail | 
|  | 244 | +    } | 
|  | 245 | +    /** | 
|  | 246 | +     * Method to get a User's Bust | 
|  | 247 | +     * | 
|  | 248 | +     * Available Values: | 
|  | 249 | +     * 48x48, 50x50, 60x60, 75x75, 100x100, 150x150, 180x180, 352x352, 420x420 | 
|  | 250 | +     * @throws[RuntimeException] | 
|  | 251 | +     * @return[String] | 
|  | 252 | +     */ | 
|  | 253 | +    @Throws(RuntimeException::class) | 
|  | 254 | +    fun getBust(size: String,isCircular: Boolean): String { | 
|  | 255 | +        var thumbnail = "" | 
|  | 256 | +        val result = runCatching { | 
|  | 257 | +            request.createRequest(ThumbnailApi::class.java, "thumbnails") | 
|  | 258 | +                .getBust(id, size, "Png", isCircular) | 
|  | 259 | +                .execute() | 
|  | 260 | +        } | 
|  | 261 | +        result.onFailure { exception -> | 
|  | 262 | +            if (exception is HttpException) { | 
|  | 263 | +                val errorCode = exception.code() | 
|  | 264 | +                val message = exception.message() | 
|  | 265 | + | 
|  | 266 | +                throw RuntimeException("Grabbing bust of user with id ${this.id} failed with message \"$message\" and response code $errorCode") | 
|  | 267 | +            } else { | 
|  | 268 | +                throw RuntimeException("an unknown error has occurred while fetching the user's bust!\n${exception.message}") | 
|  | 269 | +            } | 
|  | 270 | +        }.onSuccess { | 
|  | 271 | +            thumbnail = it.body()?.data?.get(0)?.thumbnail ?: "" | 
|  | 272 | +        } | 
|  | 273 | +        return thumbnail | 
|  | 274 | +    } | 
| 184 | 275 |     /** | 
| 185 | 276 |      * Method to get if a User is in a group | 
| 186 | 277 |      * | 
|  | 
0 commit comments