Skip to content

Commit

Permalink
Merge pull request #28 from Bram--/dev
Browse files Browse the repository at this point in the history
Move @jsonproperties into data class ctors & make responses @serializable.
  • Loading branch information
Bram-- committed Mar 23, 2024
2 parents c040e72 + 62b710a commit 62a8dc9
Show file tree
Hide file tree
Showing 38 changed files with 447 additions and 113 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using it is as simple as adding a single line to Gradle.
##### Gradle

```kotlin
implementation("org.audux.bgg:bggclient:0.6.0")
implementation("org.audux.bgg:bggclient:0.8.0")
```

##### Maven
Expand All @@ -35,7 +35,7 @@ implementation("org.audux.bgg:bggclient:0.6.0")
<dependency>
<groupId>org.audux.bgg</groupId>
<artifactId>bggclient</artifactId>
<version>0.6.0</version>
<version>0.8.0</version>
</dependency>
```

Expand Down
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
`maven-publish`
signing
alias(libs.plugins.com.gradleup.nmcp)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ktfmt.gradle)
alias(libs.plugins.org.jetbrains.dokka)
alias(libs.plugins.org.jetbrains.kotlin.jvm)
Expand All @@ -22,7 +23,7 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "org.audux.bgg"
artifactId = "bggclient"
version = "0.6.0"
version = "0.8.0"

pom {
name = "Unofficial JVM BGG client"
Expand Down Expand Up @@ -100,6 +101,7 @@ dependencies {
// Testing dependencies.
testApi(libs.ktor.client.mock)

testImplementation(libs.kotlin.serialization.json)
testImplementation(libs.junit5.jupiter)
testImplementation(libs.junit5.params)
testImplementation(libs.truth)
Expand Down
2 changes: 1 addition & 1 deletion examples/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")
implementation("io.coil-kt:coil-compose:2.5.0")
implementation("org.audux.bgg:bggclient:0.6.0")
implementation("org.audux.bgg:bggclient:0.8.0")

testImplementation("junit:junit:4.13.2")

Expand Down
2 changes: 1 addition & 1 deletion examples/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}

dependencies {
implementation("org.audux.bgg:bggclient:0.6.0")
implementation("org.audux.bgg:bggclient:0.8.0")

testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
Expand Down
2 changes: 1 addition & 1 deletion examples/paginate/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ application {
}

dependencies {
implementation("org.audux.bgg:bggclient:0.6.0")
implementation("org.audux.bgg:bggclient:0.8.0")

testImplementation("org.jetbrains.kotlin:kotlin-test")
}
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ktor = "2.3.8"
org-jetbrains-dokka = "1.9.10"
org-jetbrains-kotlin-jvm = "1.9.22"
org-jetbrains-kotlin-jdk8 = "1.8.0"
serialization = "1.6.3"
serialization = "1.5.0"
slf4j = "2.0.12"
truth = "1.4.1"

Expand All @@ -24,6 +24,7 @@ junit5-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref
kermit = { module = "co.touchlab:kermit", version.ref = "kermit" }
kotlin-coroutines-jdk8 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8", version.ref = "org-jetbrains-kotlin-jdk8" }
kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" }
kotlin-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-jvm", version.ref = "serialization" }
ktor-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }
Expand All @@ -35,4 +36,5 @@ org-jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "org
ktfmt-gradle = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt-gradle" }
com-gradleup-nmcp = { id = "com.gradleup.nmcp", version.ref = "com-gradleup-nmcp" }
org-jetbrains-dokka = { id = "org.jetbrains.dokka", version.ref = "org-jetbrains-dokka" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "org-jetbrains-kotlin-jvm" }

14 changes: 14 additions & 0 deletions src/main/kotlin/org/audux/bgg/common/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ package org.audux.bgg.common
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import kotlinx.serialization.Serializable
import org.audux.bgg.response.WrappedDoubleDeserializer
import org.audux.bgg.response.WrappedIntDeserializer

/**
* The different kind/type of things the API may return such as a board game or expansion etc.
* [See docs for more info](https://boardgamegeek.com/wiki/page/BGG_XML_API2#Thing_Items).
*/
@Serializable
enum class ThingType(val param: String) {
UNKNOWN(""), // Used whenever the type is empty or not recognized.
BOARD_GAME("boardgame"),
Expand All @@ -47,6 +49,7 @@ enum class ThingType(val param: String) {
*
* Note: About half of these types actually do _not_ return any list.
*/
@Serializable
enum class HotListType(val param: String) {
UNKNOWN(""), // Used whenever the type is empty or not recognized.
BOARD_GAME("boardgame"),
Expand All @@ -60,6 +63,7 @@ enum class HotListType(val param: String) {
}

/** Different sub types returned in the [org.audux.bgg.request.plays] request/ response */
@Serializable
enum class SubType(val param: String) {
UNKNOWN(""), // Used whenever the type is empty or not recognized.
BOARD_GAME("boardgame"),
Expand All @@ -81,6 +85,7 @@ enum class SubType(val param: String) {
* The different kind/type of families the API may return such as a board game or rpgs.
* [See docs for more info](https://boardgamegeek.com/wiki/page/BGG_XML_API2#Family_Items).
*/
@Serializable
enum class FamilyType(val param: String) {
UNKNOWN(""), // Used whenever the type is empty or not recognized.
RPG("rpg"),
Expand All @@ -96,6 +101,7 @@ enum class FamilyType(val param: String) {
* Used to map the id in the forumlist request to either a family ot thing.
* [See docs for more info](https://boardgamegeek.com/wiki/page/BGG_XML_API2#Forum_Lists).
*/
@Serializable
enum class ForumListType(val param: String) {
UNKNOWN(""), // Used whenever the type is empty or not recognized.
THING("thing"),
Expand All @@ -107,6 +113,7 @@ enum class ForumListType(val param: String) {
}

/** Used to show what type of thing it is when played, either a thing or a family(?) */
@Serializable
enum class PlayThingType(val param: String) {
UNKNOWN(""), // Used whenever the type is empty or not recognized.
THING("thing"),
Expand All @@ -121,6 +128,7 @@ enum class PlayThingType(val param: String) {
* Used to either include or exclude certain items in a request, see
* [org.audux.bgg.request.collection] and [org.audux.bgg.request.user].
*/
@Serializable
enum class Inclusion {
INCLUDE,
EXCLUDE;
Expand All @@ -129,13 +137,15 @@ enum class Inclusion {
}

/** Different domains used for the users' hot- and top-10. */
@Serializable
enum class Domain(val param: String, val address: String) {
BOARD_GAME_GEEK("boardgame", "https://boardgamegeek.com"),
RPG_GEEK("rpg", "https://rpggeek.com"),
VIDEO_GAME_GEEK("videogame", "https://videogamegeek.com"),
}

/** Encapsulates the name of a Thing either primary or alternate name. */
@Serializable
data class Name(
/** The actual name. */
@JacksonXmlProperty(isAttribute = true) val value: String,
Expand All @@ -151,6 +161,7 @@ data class Name(
)

/** Wrapper for [Ratings]. */
@Serializable
data class Statistics(
/** Unused attribute? */
@JacksonXmlProperty(isAttribute = true) val page: Int?,
Expand All @@ -163,6 +174,7 @@ data class Statistics(
* Contains rating aggregated and other statistics like average rating, standard deviation, number
* of comments.
*/
@Serializable
data class Ratings(
/** A user rating if available. */
@JacksonXmlProperty(isAttribute = true) val value: String? = null,
Expand Down Expand Up @@ -211,6 +223,7 @@ data class Ratings(
)

/** Represents a rank in a single ranking (Consisting of type & name). */
@Serializable
data class Rank(
/** Unique of the ranking type - ID and type+name should always be a coupled. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand Down Expand Up @@ -248,6 +261,7 @@ data class Rank(
*
* And so on.
*/
@Serializable
data class Link(
/**
* The id for the link, most of these cannot be retrieved via the API although a 'family'-API
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import java.time.LocalDateTime
import kotlinx.serialization.Serializable
import org.audux.bgg.common.Ratings
import org.audux.bgg.common.ThingType

/**
* Response wrapper for the user's Collection. These contain lists of items like board games wrapped
* in [CollectionItem].
*/
@Serializable
@JsonRootName("items")
data class Collection(
/** Terms of use of the BGG API. */
Expand All @@ -43,6 +45,7 @@ data class Collection(

/** An item in the collection e.g. a board game, rpg etc. */
@JsonIgnoreProperties("objecttype")
@Serializable
data class CollectionItem(
@JacksonXmlProperty(isAttribute = true, localName = "collid") val collectionId: Int,
@JacksonXmlProperty(isAttribute = true) val objectId: Int,
Expand Down Expand Up @@ -84,6 +87,7 @@ data class CollectionItem(
)

/** The status of collection item e.g. whether the user owns it, wants it etc. */
@Serializable
data class Status(
/** Whether item is currently owned. */
@JsonDeserialize(using = NumberToBooleanDeserializer::class)
Expand Down Expand Up @@ -131,10 +135,12 @@ data class Status(
/** Whether item is currently owned. */
@JacksonXmlProperty(isAttribute = true)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Serializable(with = LocalDateTimeSerializer::class)
val lastModified: LocalDateTime? = null,
)

/** Statistics for a collection item. */
@Serializable
data class CollectionStatistics(
/** Minimum number of players. */
@JacksonXmlProperty(localName = "minplayers") val minimumPlayers: Int?,
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/Family.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package org.audux.bgg.response
import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import kotlinx.serialization.Serializable
import org.audux.bgg.common.FamilyType
import org.audux.bgg.common.Link
import org.audux.bgg.common.Name

/** Response wrapper for Family items, e.g. games having a related theme or gameplay. */
@JsonRootName("items")
@Serializable
data class Family(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -31,6 +33,7 @@ data class Family(
)

/** The actual Family item e.g. a `boardgamefamily`, rpg etc. */
@Serializable
data class FamilyItem(
/** Unique ID that can be used to look up more information using the thing endpoint. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/Forum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import java.time.LocalDateTime
import kotlinx.serialization.Serializable

/**
* Encapsulates a forum containing a list of thread summaries - these can be retrieve using in
* [org.audux.bgg.request.thread] endpoint.
*/
@JsonRootName("forum")
@Serializable
data class Forum(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -51,6 +53,7 @@ data class Forum(
/** The date and time a post was last made. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateTimeSerializer::class)
val lastPostDate: LocalDateTime?,

/** The list of threads in this forum. */
Expand All @@ -60,6 +63,7 @@ data class Forum(
/**
* Summary of a thread in the forum, contains some stats and aggregated data but no articles/posts.
*/
@Serializable
data class ThreadSummary(
/** Unique ID that can be used to look up more information using the thread endpoint. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand All @@ -80,10 +84,12 @@ data class ThreadSummary(
/** The date and time this thread was created. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateTimeSerializer::class)
val postDate: LocalDateTime?,

/** The date and time a post was last made in this thread. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateTimeSerializer::class)
val lastPostDate: LocalDateTime?,
)
4 changes: 4 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/ForumList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import java.time.LocalDateTime
import kotlinx.serialization.Serializable
import org.audux.bgg.common.ForumListType

/** Response wrapper for a list of forums for the given id/thing pair. */
@JsonRootName("forums")
@Serializable
data class ForumList(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -42,6 +44,7 @@ data class ForumList(
* Encapsulates the summary of a forum - these can be retrieve using the
* [org.audux.bgg.request.forum] endpoint.
*/
@Serializable
data class ForumSummary(
/** Unique ID that can be used to look up more information using the forum endpoint. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand Down Expand Up @@ -73,5 +76,6 @@ data class ForumSummary(
/** The date and time a post was last made. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateTimeSerializer::class)
val lastPostDate: LocalDateTime?,
)
Loading

0 comments on commit 62a8dc9

Please sign in to comment.