board-game-gem 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe7d3b49e0307be5567f3a8d7d40ab84af813b99
4
- data.tar.gz: 56e11dc805614ce149332622cdc867b4fd85ce2b
3
+ metadata.gz: c54b7bdc4e183d7a538f221865486300d632b96e
4
+ data.tar.gz: d513eb5f5b27f344c6edf3f2dc3d1699fbe0fecb
5
5
  SHA512:
6
- metadata.gz: 58355b13b57ac1ca8206fbd5eb427fc05d986998078421cd4d6b957abefb885fea6f314f5729fd3966f418a52a9e612968b143b461ca0cf4a1b29d0830fd0e7f
7
- data.tar.gz: 50d7a4c3a146ec73f443f6ae84c0fbb461f1a37ecf1eb085d9d38c32e1429f06069f7361ee64b387991c7958bdf989fb1d5fd55e41807940e995e60484746514
6
+ metadata.gz: f03363bed0eaa102647fc21ffb0220a957d25ac8ae3b16bf83c892ab8c01c3e0713be1ac6e8687a3e66b99d4048652f00e5a98c6680bdb7c9e626c1e5b1b7b80
7
+ data.tar.gz: d50d3d41bd68164dd10d51acdc81f596e11391bcd6c8b9e09a431e92c8fc98fbd0aa48da4a3448176c768d94975a1508625573bc91b67bc0edfcb4fb417dba1b
@@ -0,0 +1,88 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module BoardGameGem
5
+ API_ROOT = "http://www.boardgamegeek.com/xmlapi2"
6
+ MAX_ATTEMPTS = 10
7
+
8
+ def BoardGameGem.get_item(id, statistics = false, options = {})
9
+ options[:id] = id
10
+ options[:stats] = statistics ? 1 : 0
11
+ item = BGGItem.new(BoardGameGem.request_xml("thing", options))
12
+ return item.id == 0 ? nil : item
13
+ end
14
+
15
+ def BoardGameGem.get_items(ids, statistics = false, options = {})
16
+ options[:id] = ids.join(",")
17
+ options[:stats] = statistics ? 1 : 0
18
+ item_xml = BoardGameGem.request_xml("thing", options)
19
+ item_list = []
20
+ item_xml.css("item").wrap("<item_data></item_data>")
21
+ item_xml.css("item_data").each do |item_data|
22
+ item = BGGItem.new(item_data)
23
+ item_list.push(item)
24
+ end
25
+ item_list
26
+ end
27
+
28
+ def BoardGameGem.get_family(id, options = {})
29
+ options[:id] = id
30
+ family = BGGFamily.new(BoardGameGem.request_xml("family", options))
31
+ return family.id == 0 ? nil : family
32
+ end
33
+
34
+ def BoardGameGem.get_user(username, options = {})
35
+ options[:name] = username
36
+ user = BGGUser.new(BoardGameGem.request_xml("user", options))
37
+ return user.id == 0 ? nil : user
38
+ end
39
+
40
+ def BoardGameGem.get_collection(username, options = {})
41
+ options[:username] = username
42
+ collection_xml = BoardGameGem.request_xml("collection", options)
43
+ if collection_xml.css("error").length > 0
44
+ return nil
45
+ else
46
+ return BGGCollection.new(collection_xml)
47
+ end
48
+ end
49
+
50
+ def BoardGameGem.search(query, options = {})
51
+ options[:query] = query
52
+ xml = BoardGameGem.request_xml("search", options)
53
+ return {
54
+ :total => xml.at_css("items")["total"].to_i,
55
+ :items => xml.css("item").map { |x| BGGSearchResult.new(x) }
56
+ }
57
+ end
58
+
59
+ private
60
+
61
+ def BoardGameGem.request_xml(method, hash, attempt = 0)
62
+ params = BoardGameGem.hash_to_uri(hash)
63
+ open("#{API_ROOT}/#{method}?#{params}") do |file|
64
+ if file.status[0] != "200"
65
+ if attempt < MAX_ATTEMPTS
66
+ sleep 0.05
67
+ BoardGameGem.request_xml(method, hash, attempt + 1)
68
+ else
69
+ return nil
70
+ end
71
+ else
72
+ Nokogiri::XML(file.read)
73
+ end
74
+ end
75
+ end
76
+
77
+ def BoardGameGem.hash_to_uri(hash)
78
+ return hash.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
79
+ end
80
+ end
81
+
82
+ require 'bgg_base'
83
+ require 'bgg_item'
84
+ require 'bgg_family'
85
+ require 'bgg_user'
86
+ require 'bgg_collection'
87
+ require 'bgg_collection_item'
88
+ require 'bgg_search_result'
@@ -1,3 +1,3 @@
1
1
  module BoardGameGem
2
- VERSION = "0.1.10"
2
+ VERSION = "0.2.0"
3
3
  end
data/test.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  require_relative 'lib/BoardGameGem'
2
2
 
3
- p BoardGameGem.search("suburb")
3
+ p BoardGameGem.get_items([1,2,3])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: board-game-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Roussel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -76,6 +76,7 @@ files:
76
76
  - lib/bgg_search_result.rb
77
77
  - lib/bgg_user.rb
78
78
  - lib/board-game-gem.rb
79
+ - lib/boardgamegem.rb
79
80
  - lib/boardgamegem/version.rb
80
81
  - test.rb
81
82
  homepage: http://www.github.com/acceptableice/boardgamegem