Skip to content

fzerorubigd/gobgg

Repository files navigation

Boardgamegeek API Client for Golang

Go Report Card codecov Go Reference

Basics

Create a new client using the NewBGGClient also you can use the Login function to set the cookies, some API (like posting plays) needs the login cookies.

You can set the http.Client, or http.Cookie or using different domain (do you need to?)

bgg := gobgg.NewBGGClient(gobgg.SetClient(client))
// Setting the cookies (not a requirement if you want to only use public API)
if err := bgg.Login("user", "password"); err != nil {
	log.Fatalf("Login failed with error: %q", err)	
}

Collection API

Getting the collection in boardgamegeek is a little tricky, so the library will retry with a backoff to get the collection. You can control the timeout using the context passed to the function or it will retry forever.

collection, err := bgg.GetCollection(ctx, "fzerorubigd", gobgg.SetCollectionTypes(gobgg.CollectionTypeOwn))

Things API

You can get the things detail (I just use the board game related API so far) it always comes with the statistics (why it should be a flag!)

I decided to follow the same pattern for all the functions even when it is not required.

things , err := bgg.GetThings(ctx, gobgg.GetThingIDs(1, 2, 3))

Plays API

Getting a play is like this:

// For users
plays, err := bgg.Plays(ctx, gobgg.SetUserName("fzerorubigd"))
// For a game
plays, err := bgg.Plays(ctx, gobgg.SetGameID(1))

Posting Plays

Posting play is an experimental API that is not using any documented API end point, for this you need to call Login first.

Person API

For getting the person image you can use the -undocumented- person API PersonImage

Rate Limiting

Boardgamegeek does rate limit on all the api calls. Its a good idea to add a rate limiter to your client. it is already supported and I recommend the

import (
	"fmt"
	"time"

	"go.uber.org/ratelimit"
	"github.com/fzerorubigd/gobgg"
)

rl := ratelimit.New(10, Per(60*time.Second)) // creates a 10 per minutes rate limiter.
client := gobgg.NewBGGClient(gobgg.SetLimiter(rl))