Skip to content

Instantly share code, notes, and snippets.

@RyanMacG
Last active January 2, 2016 12:59
Show Gist options
  • Save RyanMacG/8307150 to your computer and use it in GitHub Desktop.
Save RyanMacG/8307150 to your computer and use it in GitHub Desktop.
Example usage of bgg-api for getting an array of game names from a user's boardgamegeek collection
class ExampleBggApiUsage
require 'pry-debugger'
require 'bgg-api'
bgg = BggApi.new
puts "What user's collection do you want to find?"
username = gets
username = username.chomp
collection = bgg.collection({username: username})
if collection["totalitems"].to_i == 0
puts "sorry that user doesn't have any games"
else
list = collection["item"].to_a
game_names = Array.new
list.each do |game|
game_names << Hash[:name, game["name"][0]["content"]]
end
puts game_names.count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment