Skip to content

Commit

Permalink
Clean up file names, and add loats of documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram-- committed Mar 11, 2024
1 parent aa1da60 commit 4cb857e
Show file tree
Hide file tree
Showing 39 changed files with 1,010 additions and 500 deletions.
160 changes: 160 additions & 0 deletions MODULE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Module BggClient

BggClient is a API client for the Board Game Geek XML APIs. These APIs work for all geek domains,
meaning Board games, video games and RPGs can be retrieved. It works on both the JVM and Android (
24+). Before using the BGG APIs please refer to
the [Terms of Use](https://boardgamegeek.com/wiki/page/XML_API_Terms_of_Use#) for the APIs. Finally

If you're looking for all Board game IDs and some basic information please refer to
[this page](https://boardgamegeek.com/data_dumps/bg_ranks) that contains CSV with all boardgames
instead.

## APIs overview

See [org.audux.bgg.BggClient] for an overview of the APIs

## Examples

Below are few short example more complicated examples can be found in
the [examples folder](https://github.com/Bram--/bggclient/tree/main/examples).

### Simple board game request in Kotlin

Below is a code snippet that calls the `things` XML2 API retrieving info about "Nucleum" including
comments left on the game.

```kotlin
runBlocking {
val response = BggClient.things(ids = arrayOf(396790), comments = true).call()

print(response.data?.things!![0].name) // Prints "Nucleum"
}
```

This returns all information about a `Thing` - in this case a board game including any comments
users have left on the thing. Comments are paginated and would only return the last 100.
See [org.audux.bgg.BggClient.things] for the full API. The actual response is `Response<Thing>`
which is a wrapper that holds the response data or holds an error instead. Depending on what is
requested (e.g. are comments included in the request?) the object is (partially)
filled: [org.audux.bgg.response.Thing]

_Note that `call()` needs to be called in a suspense function._

### Simple board game request in Java

Using the library in Java is the same as in Kotlin, however it uses a `CompletableFuture` so the
request and response can be used in Java.

```java
java.util.concurrent.CompletableFuture<Response<Things>>future=
BggClient.things(
/* ids= */ new Integer[]{396790},
/* types= */ new ThingType[]{},
/* stats= */ false,
/* versions= */ false,
/* videos= */ false,
/* marketplace= */ false,
/* comments= */ true,
/* ratingComments= */ false)
.callAsync();

// Blocking get - for example purposes only.
Response<Things> response=future.get(2_000,MILLISECONDS);
```

The same as the Kotlin example above; this returns all information about a `Thing` - in this case a
board game including any comments
users have left on the thing. Comments are paginated and would only return the last 100. See
[org.audux.bgg.BggClient.things] for the full API. The actual response is `Response<Thing>` which is
a wrapper that holds the response data or holds an error instead. Depending on what is requested (
e.g. are comments included in the request?) the object is (partially)
filled: [org.audux.bgg.response.Thing]

### Async request

Instead of using a suspend function you can also do a request inline by giving a callback. The
request and response parsing will then be handled using `Dispatchers.IO` and `Dispatchers.DEFAULT`.
The same as the `things` request above but using callAsync() it looks as follows:

```kotlin
BggClient.things(ids = arrayOf(396790), comments = true).callAsync { response ->
print(response.data?.things!![0].name) // Prints "Nucleum"
}
```

### Pagination

Pagination is completely taken care off by the library, a more in-depth example can be found in the
examples folder. Pagination starts with the initial request i.e. when a `page` parameter is given
that's the start page and the end page can be configured using the `toPage` param. If no `page` and
no `toPage` params are given the library will attempt to paginate all pages.

```kotlin
var response = BggClient.things(ids = arrayOf(396790), comments = true).paginate().call()

// Prints "Loads of comments 524"
println("Loads of comments! ${response.data?.things!![0].comments?.comments}")
```

The above codes results in 6 requests to BGG, first, the initial request and then 5 parallel
requests to retrieve the resulting pages/comments.

##### Paginated requests:

Not all requests can be paginates (as most of them are not actually paginated in the API nor
need they be). However the following requests can be paginated:

* `forum` - Aggregate/paginates over the `threads` in a forum. Only 50 per request can be
retrieved which means that large forums could result in a lot of requests.
* `guilds` - Aggregate/paginates over the `guildMembers`. Only 25 members can be returned
per request.
* `plays` - Aggregates/paginates over the list of `plays` for the given user (id). Only 100 plays
per request are retrieved.
* `things` - Aggregates/paginates over the list of `comments` or `ratingcomments`. The pageSize can
be set but has a default and maximum size of 100 comments per request.
* `user` - Aggregates/paginates over the list of `buddies` and `guilds`. The default page size is
1000 so it's unlikely pagination actually happens when called.

### Sitemaps

Sitemaps are a quick to get IDs of Board games, RPGs, etc. The `sitemapIndex` endpoint contains all
sitemaps for the given domain e.g. `boardgamegeek.com/sitemapindex` has a list of several sitemaps (
UrlSets) that contains links to ALL board game pages.
You can request the index by calling `BggClient#sitemapIndex`, but using the `diffuse` function will
actually for off requests to the contained sitemaps and collect the URLs by 'type'.

```kotlin
val response =
BggClient.sitemapIndex(Domain.BOARD_GAME_GEEK)
.diffuse(SitemapLocationType.BOARD_GAMES, SitemapLocationType.BOARD_GAME_EXPANSIONS)
.call()

println(response.data)
```

Data contains a (multi) map of types and URLs (`Map<SitemapLocationType, List<SiteMapUrl>>`):

* [BOARD_GAMES] => ["https://boardgamegeek.com/boardgame/2/dragonmaster", ...]
* [BOARD_GAME_EXPANSIONS] => ["https://boardgamegeek.com/boardgameexpansion/1573/banzai", ...)

### Custom configuration

`BggClientConfiguration` allows the client to be configured differently. This allows the user to
increase the maximum number of retries, the maximum number of concurrent requests and how the
exponential delay is calculated.

```kotlin
BggClient.configure {
maxConcurrentRequests = 5
maxRetries = 100
}
```

### Logging

Running into errors/faulty responses? Turn on the internal logging for the library to see the
internal workings.

```kotlin
BggClient.setLoggerSeverity(Severity.Verbose)
```
19 changes: 19 additions & 0 deletions PACKAGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Package org.audux.bgg
Core package containing the [BggClient] used for all interactions with this library.

# Package org.audux.bgg.common
Enums and classes shared between several requests and responses.

# Package org.audux.bgg.request
Contains all code to build requests to BGG. [Request] is the main request object returned when
calling most APIs, however requests that support pagination might return a specific
[PaginatedRequest] instead.

# Package org.audux.bgg.response
Mostly data classes that wrap the XML response from the BGG APIs. [Response] wraps all data classes
in order to catch erroneous responses. The [Response] object has [Response.data] which contains the
parsed (successful) response and [Response.error] is set when the response could not be parsed. The
latter may happen, for example, when the API returns HTML or an errors like `Guild not found` etc.

See the [org.audux.bgg.BggClient] for all the requests and associated response data classes.

65 changes: 26 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![GitHub License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http:https://www.apache.org/licenses/LICENSE-2.0) [![Build](https://github.com/Bram--/bggclient/actions/workflows/ci.yml/badge.svg)](https://github.com/Bram--/bggclient/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/Bram--/bggclient/graph/badge.svg?token=FJDN8I5FR1)](https://codecov.io/gh/Bram--/bggclient) [![Maven Central](https://img.shields.io/maven-central/v/org.audux.bgg/bggclient.svg)](https://central.sonatype.com/artifact/org.audux.bgg/bggclient)
# Module Board Game Geek Client/BGGClient

# Board Game Geek Client/BGGClient
[![GitHub License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http:https://www.apache.org/licenses/LICENSE-2.0) [![Build](https://github.com/Bram--/bggclient/actions/workflows/ci.yml/badge.svg)](https://github.com/Bram--/bggclient/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/Bram--/bggclient/graph/badge.svg?token=FJDN8I5FR1)](https://codecov.io/gh/Bram--/bggclient) [![Maven Central](https://img.shields.io/maven-central/v/org.audux.bgg/bggclient.svg)](https://central.sonatype.com/artifact/org.audux.bgg/bggclient)

BggClient is a API client for the Board Game Geek XML APIs. These APIs work for all geek domains,
meaning Board games, video games and RPGs can be retrieved. It works on both the JVM and Android (
Expand All @@ -13,51 +13,36 @@ instead.

## APIs overview

A short summary of all available APIs/Endpoints available.


| API | Description |
|----|----|
| [BggClient#collection](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20collection) | Request details about a user's collection. Returns a (partial) [Collection](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Collection.kt) |
| [BggClient#familyItems](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20familyItems) | Family thing endpoint that retrieve details about the given family ID and associated `Link` objects. Returns a [Family](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Family.kt) |
| [BggClient#forumList](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20forumList) | Retrieves the list of available forums for the given id / type combination. e.g. Retrieve all the available forums for `id=342942, type=thing` i.e. Ark nova. Returns a [ForumList](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/ForumList.kt) |
| [BggClient#forum](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20forum) | Retrieves the list of threads for the given forum id. Returns a [Forum](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Forum.kt) |
| [BggClient#geekList](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20geekList) | Retrieves a specific geek list by its ID, returning its items and optionally comments left on the GeekList. Returns a [GeekList](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/GeekList.kt) |
| [BggClient#guilds](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20guilds) | Retrieve information about the given guild (id) like name, description, members etc. Returns a [Guild](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Guild.kt) |
| [BggClient#hotItems](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20hotItems) | Hotness endpoint that retrieve the list of most 50 hot/active items on the site filtered by type. Returns a [HotList](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Hot.kt) |
| [BggClient#plays](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20plays) | Request a list of plays (max 100 at the time) for the given user. Returns a [Plays](https://github.com/Bram--/bggclient/blob/ main/src/main/kotlin/org/audux/bgg/response/Plays.kt) |
| [BggClient#search](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20search) | Search endpoint that allows searching by name for things on BGG. Returns [SearchResults](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Search.kt) |
| [BggClient#sitemapIndex](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20sitemapIndex) | Requests the Sitemap index for the given Domain. Call `org.audux.bgg.request.DiffusingSitemap.diffuse` to request specific sitemaps. Returns a [SitemapIndex](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/SitemapIndex.kt) or a list of [Sitemap](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Sitemap.kt) objects if diffuse is called. |
| [BggClient#things](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20things) | Request a Thing or list of things. Multiple things can be requested by passing in several IDs. At least one ID is required to make this request. Sending along `types` might result in an empty as the API filters based on the `ThingType`. Returns [Things](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Things.kt) |
| [BggClient#thread](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20thread) | Retrieves the list of articles/posts for the given thread. Returns a [Thread](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Thread.kt) |
| [BggClient#user](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20user) | User endpoint that retrieves a specific user by their `name`. Returns a [User](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/User.kt) |

A short summary of all available APIs/Endpoints is available
in [the documentation](https://bram--.github.io/bggclient/).

## Usage

The library is published on [MavenCentral as bggclient](https://central.sonatype.com/artifact/org.audux.bgg/bggclient) so using it is as simple as adding a single line to Gradle.
The library is published
on [MavenCentral as bggclient](https://central.sonatype.com/artifact/org.audux.bgg/bggclient) so
using it is as simple as adding a single line to Gradle.

##### Gradle

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

##### Maven

```xml

<dependency>
<groupId>org.audux.bgg</groupId>
<artifactId>bggclient</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
</dependency>
```


## Examples

Below are few short example more complicated examples can be found in
the [examples folder](https://github.com/Bram--/bggclient/tree/main/examples).
the [examples folder](/Bram--/bggclient/tree/main/examples).

### Simple board game request in Kotlin

Expand All @@ -74,19 +59,19 @@ runBlocking {

This returns all information about a `Thing` - in this case a board game including any comments
users have left on the thing. Comments are paginated and would only return the last 100.
See [BggClient#things](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20things)
See [BggClient#things](/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20things)
for the full API. The actual response is `Response<Thing>` which is a wrapper that holds the
response data or holds an
error instead. Depending on what is requested (e.g. are comments included in the request?) the
object is (partially)
filled: [Thing object](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Things.kt)
filled: [Thing object](/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Things.kt)

_Note that `call()` needs to be called in a suspense function._

### Simple board game request in Java

Using the library in Java is the same as in Kotlin, however it uses a `CompletableFuture` so the
resquest and response can be used in Java.
request and response can be used in Java.

```java
java.util.concurrent.CompletableFuture<Response<Things>>future=
Expand All @@ -102,18 +87,18 @@ java.util.concurrent.CompletableFuture<Response<Things>>future=
.callAsync();

// Blocking get - for example purposes only.
Response<Things> response=future.get(2_000,MILLISECONDS);
Response<Things> response=future.get(2_000,MILLISECONDS);
```

The same as the Kotlin example above; this returns all information about a `Thing` - in this case a
board game including any comments
users have left on the thing. Comments are paginated and would only return the last 100. See
[BggClient#things](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20things)
[BggClient#things](/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/BggClient.kt#:~:text=fun%20things)
for the full API. The actual response is `Response<Thing>` which is a wrapper that holds the
response data or holds an
error instead. Depending on what is requested (e.g. are comments included in the request?) the
object is (partially) filled:
[Thing object](https://github.com/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Things.kt)
[Thing object](/Bram--/bggclient/blob/main/src/main/kotlin/org/audux/bgg/response/Things.kt)

### Async request

Expand Down Expand Up @@ -183,20 +168,22 @@ Data contains a (multi) map of types and URLs (`Map<SitemapLocationType, List<Si
* [BOARD_GAME_EXPANSIONS] => ["https://boardgamegeek.com/boardgameexpansion/1573/banzai", ...)

### Custom configuration
`BggClientConfiguration` allows the client to be configured differently. This allows the user to
increase the maximum number of retries, the maximum number of concurrent requests and how the
exponential delay is calculated.

`BggClientConfiguration` allows the client to be configured differently. This allows the user to
increase the maximum number of retries, the maximum number of concurrent requests and how the
exponential delay is calculated.

```kotlin
BggClient.configure {
maxConcurrentRequests = 5
maxRetries = 100
maxConcurrentRequests = 5
maxRetries = 100
}
```

### Logging
Running into errors/faulty responses? Turn on the internal logging for the library to see the
internal workings.

Running into errors/faulty responses? Turn on the internal logging for the library to see the
internal workings.

```kotlin
BggClient.setLoggerSeverity(Severity.Verbose)
Expand Down
24 changes: 23 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.dokka.gradle.DokkaTask
import java.net.URL

plugins {
jacoco
`java-library`
Expand All @@ -19,7 +22,7 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "org.audux.bgg"
artifactId = "bggclient"
version = "0.5.1"
version = "0.6.0"

pom {
name = "Unofficial JVM BGG client"
Expand Down Expand Up @@ -124,3 +127,22 @@ tasks {
}
}
}

tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets {
named("main") {
moduleName.set("BggClient")
includes.from(project.files(), "MODULE.md", "PACKAGES.md")
noStdlibLink.set(true)
noJdkLink.set(true)
noAndroidSdkLink.set(true)

sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(
URL("https://github.com/Bram--/bggclient/tree/main")
)
}
}
}
}
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.5.1")
implementation("org.audux.bgg:bggclient:0.6.0")

testImplementation("junit:junit:4.13.2")

Expand Down
Loading

0 comments on commit 4cb857e

Please sign in to comment.