Last active
January 2, 2016 12:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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