module BoardGameGem
Constants
- API_ROOT
- MAX_ATTEMPTS
- VERSION
Public Class Methods
get_collection(username, options = {})
click to toggle source
# File lib/boardgamegem.rb, line 27 def BoardGameGem.get_collection(username, options = {}) options[:username] = username collection_xml = BoardGameGem.request_xml("collection", options) if collection_xml.css("error").length > 0 return nil else return BGGCollection.new(collection_xml) end end
get_family(id, options = {})
click to toggle source
# File lib/boardgamegem.rb, line 15 def BoardGameGem.get_family(id, options = {}) options[:id] = id family = BGGFamily.new(BoardGameGem.request_xml("family", options)) return family.id == 0 ? nil : family end
get_item(id, statistics = false, options = {})
click to toggle source
# File lib/boardgamegem.rb, line 8 def BoardGameGem.get_item(id, statistics = false, options = {}) options[:id] = id options[:stats] = statistics ? 1 : 0 item = BGGItem.new(BoardGameGem.request_xml("thing", options)) return item.id == 0 ? nil : item end
get_user(username, options = {})
click to toggle source
# File lib/boardgamegem.rb, line 21 def BoardGameGem.get_user(username, options = {}) options[:name] = username user = BGGUser.new(BoardGameGem.request_xml("user", options)) return user.id == 0 ? nil : user end
search(query, options = {})
click to toggle source
# File lib/boardgamegem.rb, line 37 def BoardGameGem.search(query, options = {}) options[:query] = query xml = BoardGameGem.request_xml("search", options) return { :total => xml.at_css("items")["total"].to_i, :items => xml.css("item").map { |x| BGGSearchResult.new(x) } } end
Private Class Methods
hash_to_uri(hash)
click to toggle source
# File lib/boardgamegem.rb, line 64 def BoardGameGem.hash_to_uri(hash) return hash.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&") end
request_xml(method, hash, attempt = 0)
click to toggle source
# File lib/boardgamegem.rb, line 48 def BoardGameGem.request_xml(method, hash, attempt = 0) params = BoardGameGem.hash_to_uri(hash) open("#{API_ROOT}/#{method}?#{params}") do |file| if file.status == 202 if attempt < MAX_ATTEMPTS sleep 0.05 BoardGameGem.request_xml(method, hash, attempt + 1) else return nil end else Nokogiri::XML(file.read) end end end