Giter Club home page Giter Club logo

bgg's Introduction

bgg gem Build Status Code Climate

An object-oriented API for interacting with the boardgamegeek XML Version 2 API.

This is based on a fork of earlier work I had done on bgg-api, along with Brett and a few other contributors.

Versions supported

Please note that this code uses Ruby 1.9 hash syntax and thus does not support versions earlier than that.

Installing the Gem

Do the following to install the bgg gem Ruby Gem.

Add the following to your Gemfile:

gem "bgg"

Then run bundle install from the command line:

bundle install

Using the Gem

Require the gem at the top of any file you want to use.

require 'bgg'

You can either use the low level basic api and then parse the XML document in a way that suits your needs, or you can use the specialized methods

There are object types and subtypes for many of the APIs documented at BGG_XML_API2, but not all of them are implemented. Everything around a user and their game collection should work, as well as generalized searching for board games.

Requesting Data

BggApi is the root entry point to the different api calls.

BggApi.collection 'username' # Default call 
BggApi.collection('username', { brief: 1 }) # Adding params based on api documentation

Working with Results

Each api method has it's own data structure, although there is some common themes.

There is a possibilty that there may be data for one item and not another if the original bgg record is missing it. For instance a user has not rated an item in their collection. In these cases we return nil.

Another possible reason to get nil is if you pull a data item from the result set when there is a needed request param. For example, to get the user_rating for a collection item you need to specify stats: 1, or all_fields.

Enumerated Objects

Most results return an enumerated root object (Although not all). The child object will always inherit from Bgg::Result::Item.

my_collection.count
my_collection.first.user_rating  # Returns a collection item object
my_collection.played # Returns array of played items

XML always available

Sometimes it is easier to pull out what you want specifically then to try and get only what the objects provide. So if you need it the XML is always available at any level. Since we are using Nokogiri this will enable it's methods and return values to you.

my_collection.xml.xpath('items/item/stats/@minplayers') # All items minimum number of players
my_collection.first.xml.xpath('stats/ranks/rank/@value') # All rankings for an item

Contributing to bgg

  • Fork the project
  • Start a feature/bugfix branch
  • Test whatever you are committing. Ensure this test is a specification of the behavior of the functionality, not just an error case or success case.
  • Commit and push until you are happy with your contribution
  • Submit a pull request. Squash commits that should be squashed (it is not necessary for you to have just one commit to your pull request, but have each commit be a logical piece of work.)

Copyright

Copyright (c) 2014 Jeremiah Lee, Brett Hardin, and Marcello Missiroli. See LICENSE.txt for further details.

bgg's People

Contributors

jemiahlee avatar strathmeyer avatar bhardin avatar piffy avatar ryanmacg avatar drueck avatar anithri avatar

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.