Giter VIP home page Giter VIP logo

bgg-xml-api-client's Introduction

BGG XML API Client

It's a simple library providing just a single function that returns requested BGG data as a JavaScript object. It uses ofetch under the hood.

Example usage:

import { bggXmlApiClient } from 'bgg-xml-api-client'

const response = await bggXmlApiClient.get('user', { name: 'Qrzy88' })

console.log(response.id) // displays: 1381959

bggXmlApiClient takes 2 parameters:

  • BGG API resource name
  • resource parameters as object - for better DX the parameters are typed, but the type is a union of types given to the wrappers listed below

Wrappers

There are also wrappers available for certain resources that accept params (already typed) as the only argument:

  • getBggCollection(params)
  • getBggFamily(params)
  • getBggForum(params)
  • getBggForumlist(params)
  • getBggGeeklist(params)
  • getBggGuild(params)
  • getBggHot(params)
  • getBggPlays(params)
  • getBggSearch(params)
  • getBggThing(params)
  • getBggThread(params)
  • getBggUser(params)

Client options

Both main client as well as wrappers accept one more parameter that can override default options:

interface ClientOptions {
  maxRetries: number // default 10
  retryInterval: number // default 5000[ms] (5s)
  timeout: number // default 10000[ms] (10s)
}

One can use it to control the retry flow when collections API replies with 202 status code meaning the request is still processing and one should retry later for actual results.

For example, in order to increase number of retries on 202 response to 20 made in an interval of 3s:

import { bggXmlApiClient } from 'bgg-xml-api-client'

const response = await bggXmlApiClient.get('collection', { username: 'Qrzy88' }, { maxRetries: 20, retryInterval: 3000 })

or to reduce the timeout to 5s when fetching user:

import { getBggUser } from 'bgg-xml-api-client'

const response = await getBggUser({ name: 'Qrzy88' }, { timeout: 5000 })

bgg-xml-api-client's People

Contributors

dependabot[bot] avatar qrzy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

przyczepka-team

bgg-xml-api-client's Issues

Error Handling for Collections Method

How to we handle errors statuses for getBggCollection() method? This is what happens from their documentation.

Note that you should check the response status code... if it's 202 (vs. 200) then it indicates BGG has queued your request and you need to keep retrying (hopefully w/some delay between tries) until the status is not 202.

I added a try catch error but i get no statuses

The error message i get 'Max reties reach!'

Get All Logged P

Is there a way to get all plays there were logged between 2 dates?

Base URL for v2 needs to omit "www"

Recently using this package has started throwing errors for username & collection requests as a result of using an outdated domain.

Suggested fix is to omit the "www" in the domain for BGG_API_V2_BASE_URL in bgg-xml-api-client/src/helpers/getBaseUrlForResource.ts. The new line should be:

export const BGG_API_V2_BASE_URL = 'https://boardgamegeek.com/xmlapi2/';

For more information, see this related thread on BGG.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.