Added API authorization for Boardgame Geek

This commit is contained in:
ltctceplrm 2025-11-17 13:38:39 +01:00
parent 3b4dace1aa
commit 51f7df2d40
3 changed files with 27 additions and 2 deletions

View file

@ -16,7 +16,7 @@ export class BoardGameGeekAPI extends APIModel {
this.plugin = plugin;
this.apiName = 'BoardGameGeekAPI';
this.apiDescription = 'A free API for BoardGameGeek things.';
this.apiUrl = 'https://api.geekdo.com/xmlapi';
this.apiUrl = 'https://boardgamegeek.com/xmlapi/';
this.types = [MediaType.BoardGame];
}
@ -26,6 +26,9 @@ export class BoardGameGeekAPI extends APIModel {
const searchUrl = `${this.apiUrl}/search?search=${encodeURIComponent(title)}`;
const fetchData = await requestUrl({
url: searchUrl,
headers: {
Authorization: `Bearer ${this.plugin.settings.BoardgameGeekKey}`,
},
});
if (fetchData.status !== 200) {
@ -64,8 +67,15 @@ export class BoardGameGeekAPI extends APIModel {
const searchUrl = `${this.apiUrl}/boardgame/${encodeURIComponent(id)}?stats=1`;
const fetchData = await requestUrl({
url: searchUrl,
headers: {
Authorization: `Bearer ${this.plugin.settings.BoardgameGeekKey}`,
},
});
if (fetchData.status === 401) {
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
}
if (fetchData.status !== 200) {
throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`);
}

View file

@ -16,6 +16,7 @@ export interface MediaDbPluginSettings {
MobyGamesKey: string;
GiantBombKey: string;
ComicVineKey: string;
BoardgameGeekKey: string;
sfwFilter: boolean;
templates: boolean;
customDateFormat: string;
@ -79,6 +80,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
MobyGamesKey: '',
GiantBombKey: '',
ComicVineKey: '',
BoardgameGeekKey: '',
sfwFilter: true,
templates: true,
customDateFormat: 'L',
@ -222,6 +224,17 @@ export class MediaDbSettingTab extends PluginSettingTab {
void this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Boardgame Geek Key')
.setDesc('API key for "www.boardgamegeek.com".')
.addText(cb => {
cb.setPlaceholder('API key')
.setValue(this.plugin.settings.BoardgameGeekKey)
.onChange(data => {
this.plugin.settings.BoardgameGeekKey = data;
void this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('SFW filter')