Module: BoardGameGem
- Defined in:
- lib/bgg_base.rb,
lib/bgg_item.rb,
lib/bgg_user.rb,
lib/bgg_family.rb,
lib/bgg_collection.rb,
lib/board-game-gem.rb,
lib/bgg_search_result.rb,
lib/bgg_collection_item.rb,
lib/boardgamegem/version.rb
Defined Under Namespace
Classes: BGGBase, BGGCollection, BGGCollectionItem, BGGFamily, BGGItem, BGGSearchResult, BGGUser
Constant Summary
collapse
- API_1_ROOT =
"https://www.boardgamegeek.com/xmlapi"
- API_2_ROOT =
"https://www.boardgamegeek.com/xmlapi2"
- MAX_ATTEMPTS =
10
- VERSION =
"0.4.2"
Class Method Summary
collapse
-
.get_collection(username, options = {}) ⇒ Object
-
.get_family(id, options = {}) ⇒ Object
-
.get_item(id, statistics = false, api = 2, options = {}) ⇒ Object
-
.get_items(ids, statistics = false, api = 2, options = {}) ⇒ Object
-
.get_user(username, options = {}) ⇒ Object
-
.search(query, options = {}) ⇒ Object
Class Method Details
.get_collection(username, options = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/board-game-gem.rb', line 49
def self.get_collection(username, options = {})
options[:username] = username
collection_xml = BoardGameGem.request_xml("collection", options)
if collection_xml.css("error").length > 0
nil
else
BGGCollection.new(collection_xml)
end
end
|
.get_family(id, options = {}) ⇒ Object
37
38
39
40
41
|
# File 'lib/board-game-gem.rb', line 37
def self.get_family(id, options = {})
options[:id] = id
family = BGGFamily.new(BoardGameGem.request_xml("family", options))
family.id == 0 ? nil : family
end
|
.get_item(id, statistics = false, api = 2, options = {}) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/board-game-gem.rb', line 9
def self.get_item(id, statistics = false, api = 2, options = {})
options[:id] = id
options[:stats] = statistics ? 1 : 0
item = BGGItem.new(BoardGameGem.request_xml(api == 2 ? "thing" : "boardgame", options, api), api)
item.id == 0 ? nil : item
end
|
.get_items(ids, statistics = false, api = 2, options = {}) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/board-game-gem.rb', line 16
def self.get_items(ids, statistics = false, api = 2, options = {})
options[:id] = ids.join(",")
options[:stats] = statistics ? 1 : 0
item_list = []
if api == 2
path = "thing"
element = "item"
else
path = "boardgame"
element = "boardgame"
end
item_xml = BoardGameGem.request_xml(path, options, api)
item_xml.css(element).wrap("<item_data></item_data>")
item_xml.css("item_data").each do |item_data|
item_list.push(BGGItem.new(item_data, api))
end
item_list
end
|
.get_user(username, options = {}) ⇒ Object
43
44
45
46
47
|
# File 'lib/board-game-gem.rb', line 43
def self.get_user(username, options = {})
options[:name] = username
user = BGGUser.new(BoardGameGem.request_xml("user", options))
user.id == 0 ? nil : user
end
|
.search(query, options = {}) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/board-game-gem.rb', line 59
def self.search(query, options = {})
options[:query] = query
xml = BoardGameGem.request_xml("search", options)
{
:total => xml.at_css("items")["total"].to_i,
:items => xml.css("item").map { |x| BGGSearchResult.new(x) }
}
end
|