board-game-gem 0.1.9

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cd6fbd052092a5463c4c7c91188932cd82cb2230
4
+ data.tar.gz: c9fcdcbd2c4defaab4fde61d1fb4d65f5ca34c9d
5
+ SHA512:
6
+ metadata.gz: 3fda4f280f60c4c5c3d41afc0f78b8280f5aad1f857055b5ffd5e6716666099720317ec570c5cabbb430fe57850f4052e5e00fe6139975e766fbdb5261dab726
7
+ data.tar.gz: da2ff5cebe7e8480886c9b0c3f7e8173c476bef4e6b0f4abbb06d94d1eed2de0ad02dae8a07d6a3f06ea266d829b84d00f407b798f752858c91a635634fa3b71
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jakeroussel@mac.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in boardgamegem.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jake Roussel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,100 @@
1
+ # BoardGameGem
2
+ BoardGameGem provides a Ruby interface to the [BoardGameGeek XML API](http://www.boardgamegeek.com/xmlapi2) (version 2). It's designed to work with the Rails cache to reduce the number of requests when working with Rails.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'boardgamegem'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install boardgamegem
19
+
20
+ ## Usage
21
+
22
+ Requests to retrieve data can be made using any of the methods in the BoardGameGem module. Arguments in brackets are optional.
23
+
24
+ The `options` argument is a hash which allows any other parameter. For example, if you wished to limit a collection by subtype, you could pass the hash `{ subtype: "boardgame" }` as `options`.
25
+
26
+ ---
27
+
28
+ `get_item(id, [statistics], [options])`: Retreive a specific item from BGG by ID. Within the BGG API, this is called a 'thing' rather than an 'item'. If an item with that ID is not found, `nil` is returned.
29
+
30
+ If `statistics` is true, averages, weights, and rankings will be retrieved as well. By default, `statistics` is false.
31
+
32
+ `get_item` returns a `BGGItem` object, which has the following attributes:
33
+ `:id, :type, :thumbnail, :name, :description, :year_published, :min_players, :max_players,
34
+ :playing_time, :min_playing_time, :max_playing_time, :statistics`.
35
+
36
+ `:statistics` is a hash, with the following keys: `:user_ratings, :average, :bayes, :ranks, :stddev, :median, :owned, :trading, :wanted, :wishing, :num_comments, :num_weights, :average_weight`. Within this, `:ranks` is an array, containing hashes with the following keys: `:type, :name, :friendly_name, :value, :bayes`.
37
+
38
+ ---
39
+
40
+ `get_family(id, [options])`: Retrieves information on a data family. Returns a `BGGFamily` object, which has the following attributes: `:id, :thumbnail, :image, :name, :alternate_names, :description`. Within this, `:alternate_names` is an array of strings. If a family with that ID is not found, `nil` is returned.
41
+
42
+ ---
43
+
44
+ `get_user(username, [options])`: Retreives information on a specific user by name. If a user with that name does not exist, `nil` is returned.
45
+
46
+ `get_user` returns a `BGGUser` object, which has the following attributes: `:id, :name, :avatar, :year_registered, :last_login, :state, :trade_rating`
47
+
48
+ #### Methods
49
+ `get_collection`: Returns this user's collection, as if `BoardGameGem.get_collection` was called using this user's name.
50
+
51
+ ---
52
+
53
+ `get_collection(username, [options])`: Returns a user's collection by username. Returns a `BGGCollection` object, which has two attributes: `:count`, the number of items in the collection, and `:items`, an array consisting of many `BGGCollectionItem` objects.
54
+
55
+ The BGG API queues requests to retrieve a user's collection, returning a 202 status code and a 'please wait' message. When BoardGameGem makes a request and sees a 202 code, it waits a short time before issuing the request again. After 10 tries, BoardGameGem will give up and return `nil`. **You should not make multiple `get_collection` requests to handle queueing yourself.**
56
+
57
+ #### Methods
58
+ `get_owned`: Returns itmes in this collection that are flagged as 'owned'.
59
+
60
+ `get_previously_owned`: Returns items in this collection that are flagged as 'previously owned'.
61
+
62
+ `get_wants`: Returns items in this collection that are flagged as 'want'.
63
+
64
+ `get_want_to_play`: Returns items in this collection that are flagged as 'want to play'.
65
+
66
+ `get_want_to_buy`: Returns items in this collection that are flagged as 'want to buy'.
67
+
68
+ `get_wishlist`: Returns items in this collection that are on the collection owner's wishlist.
69
+
70
+ `get_preordered`: Returns items in this collection that are flagged as 'preordered'.
71
+
72
+ #### BGGCollectionItem
73
+
74
+ The BGG API returns a subset of an item's data when including it in a collection request. As a result, a `BGGCollectionItem` contains the following attributes: `:id, :type, :name, :year_published, :image, :thumbnail, :num_players, :status, :num_plays`. Within this, `:status` is a hash containing the following keys: `:own, :prev_owned, :for_trade, :want, :want_to_play, :want_to_buy, :wishlist, :preordered:, :last_modified`.
75
+
76
+ `BGGCollectionItem` contains one other method, `to_item([statistics])`, which returns the `BGGItem` version of this object.
77
+
78
+ ---
79
+
80
+ `search(query, [options])`: Performs a search request, returning any items which are like the query. Returns a hash with the keys `:total`, the number of items found in the search, and `:items`, an array of `BGGSearchResult` objects.
81
+
82
+ #### BGGSearchResult
83
+
84
+ Much like `BGGCollectionItem`, `BGGSearchResult` is a subset of `BGGItem`, and contains the following attributes: `:id, :type, :name, :year_published`.
85
+
86
+ A `BGGItem` version of this object can be requested with `to_item([statistics])`.
87
+
88
+ ### But the BGG API has more than just this!
89
+
90
+ I made this gem to help make requests for another one of my projects, [Math Trade Manager](http://www.github.com/acceptableice/math-trade-manager), and thus haven't finished implementing the other BGG API features that Math Trade Manager didn't require. If you need something specific for your application, log an issue, message me on Twitter ([@AcceptableIce](http://www.twitter.com/acceptableice)), or email me at [jakeroussel@mac.com](mailto:jakeroussel@mac.com). This is my first gem, so there are probably some issues. Let me know!
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/acceptableice/boardgamegem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
95
+
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
100
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "boardgamegem"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'boardgamegem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "board-game-gem"
8
+ spec.version = BoardGameGem::VERSION
9
+ spec.authors = ["Jake Roussel"]
10
+ spec.email = ["jakeroussel@mac.com"]
11
+
12
+ spec.summary = %q{Provides a Ruby interface to the BoardGameGeek API}
13
+ spec.homepage = "http://www.github.com/acceptableice/boardgamegem"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "bundler"
30
+
31
+ spec.add_dependency "nokogiri"
32
+ end
@@ -0,0 +1,57 @@
1
+ module BoardGameGem
2
+ class BGGBase
3
+ protected
4
+
5
+ def get_value(xml, path, key = nil)
6
+ item = xml.at_css(path)
7
+ if item.nil?
8
+ return nil
9
+ end
10
+ if key.nil?
11
+ return item.content
12
+ else
13
+ return item[key]
14
+ end
15
+ end
16
+
17
+ def get_values(xml, path, key = nil)
18
+ results = []
19
+ xml.css(path).each do |item|
20
+ if key.nil?
21
+ results.push(item.content)
22
+ else
23
+ results.push(item[key])
24
+ end
25
+ end
26
+ return results
27
+ end
28
+
29
+ def get_boolean(xml, path, key = nil)
30
+ return get_integer(xml, path, key) == 1 rescue nil
31
+ end
32
+
33
+ def get_integer(xml, path, key = nil)
34
+ return get_value(xml, path, key).to_i rescue nil
35
+ end
36
+
37
+ def get_integers(xml, path, key = nil)
38
+ return get_values(xml, path, key).map {|x| x.to_i } rescue nil
39
+ end
40
+
41
+ def get_string(xml, path, key = nil)
42
+ return get_value(xml, path, key).to_s rescue nil
43
+ end
44
+
45
+ def get_strings(xml, path, key = nil)
46
+ return get_values(xml, path, key).map {|x| x.to_s } rescue nil
47
+ end
48
+
49
+ def get_float(xml, path, key = nil)
50
+ return get_value(xml, path, key).to_f rescue nil
51
+ end
52
+
53
+ def get_datetime(xml, path, key)
54
+ return DateTime.strptime(get_string(xml, path, key), '%F %T')
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,47 @@
1
+ module BoardGameGem
2
+ class BGGCollection < BGGBase
3
+
4
+ attr_reader :count, :items
5
+
6
+ def initialize(xml)
7
+ @count = get_integer(xml, "items", "totalitems")
8
+ @items = []
9
+ xml.css("item").each do |item|
10
+ @items.push(BGGCollectionItem.new(item))
11
+ end
12
+ end
13
+
14
+ def get_owned
15
+ return filter_by(:own)
16
+ end
17
+
18
+ def get_previously_owned
19
+ return filter_by(:prev_owned)
20
+ end
21
+
22
+ def get_wants
23
+ return filter_by(:want)
24
+ end
25
+
26
+ def get_want_to_play
27
+ return filter_by(:want_to_play)
28
+ end
29
+
30
+ def get_want_to_buy
31
+ return filter_by(:want_to_buy)
32
+ end
33
+
34
+ def get_wishlist
35
+ return filter_by(:wishlist)
36
+ end
37
+
38
+ def get_preordered
39
+ return filter_by(:preordered)
40
+ end
41
+ private
42
+
43
+ def filter_by(key)
44
+ return @items.select { |x| x.status[key] }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ module BoardGameGem
2
+ class BGGCollectionItem < BGGBase
3
+
4
+ attr_reader :id, :type, :name, :year_published, :image, :thumbnail, :num_players, :status, :num_plays
5
+
6
+ def initialize(xml)
7
+ @id = xml["objectid"].to_i
8
+ @type = xml["subtype"]
9
+ @name = get_string(xml, "name")
10
+ @year_published = get_string(xml, "yearpublished")
11
+ @image = get_string(xml, "image")
12
+ @thumbnail = get_string(xml, "thumbnail")
13
+ @num_players = get_string(xml, "numplayers")
14
+ @status = {
15
+ :own => get_boolean(xml, "status", "own"),
16
+ :prev_owned => get_boolean(xml, "status", "prevowned"),
17
+ :for_trade => get_boolean(xml, "status", "fortrade"),
18
+ :want => get_boolean(xml, "status", "want"),
19
+ :want_to_play => get_boolean(xml, "status", "wanttoplay"),
20
+ :want_to_buy => get_boolean(xml, "status", "wanttobuy"),
21
+ :wishlist => get_boolean(xml, "status", "wishlist"),
22
+ :wishlist_priority => get_integer(xml, "status", "wishlistpriority"),
23
+ :preordered => get_boolean(xml, "status", "preordered"),
24
+ :last_modified => get_datetime(xml, "status", "lastmodified")
25
+ }
26
+ @num_plays = get_integer(xml, "numplays")
27
+ end
28
+
29
+ def to_item(statistics = false)
30
+ return BoardGameGem.get_item(@id, statistics)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module BoardGameGem
2
+ class BGGFamily < BGGBase
3
+
4
+ attr_reader :id, :thumbnail, :image, :name, :alternate_names, :description
5
+
6
+ def initialize(xml)
7
+ @id = get_integer(xml, "item", "id")
8
+ @thumbnail = get_string(xml, "thumbnail")
9
+ @image = get_string(xml, "image")
10
+ @name = get_string(xml, "name[type='primary']", "value")
11
+ @alternate_names = get_strings(xml, "name[type='alternate']", "value")
12
+ @description = get_string(xml, "description")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,70 @@
1
+ module BoardGameGem
2
+ class BGGItem < BGGBase
3
+
4
+ attr_reader :id, :type, :thumbnail, :name, :description, :year_published, :min_players, :max_players,
5
+ :playing_time, :min_playing_time, :max_playing_time, :statistics
6
+
7
+ def initialize(xml)
8
+ if !xml.nil?
9
+ @id = get_integer(xml, "item", "id")
10
+ @type = get_string(xml, "item", "type")
11
+ @image = get_string(xml, "image")
12
+ @thumbnail = get_string(xml, "thumbnail")
13
+ @name = get_string(xml, "name[type='primary']", "value")
14
+ @alternate_names = get_strings(xml, "name[type='alternate']", "value")
15
+ @description = get_string(xml, "description")
16
+ @year_published = get_integer(xml, "yearpublished", "value")
17
+ @min_players = get_integer(xml, "minplayers", "value")
18
+ @max_players = get_integer(xml, "maxplayers", "value")
19
+ @playing_time = get_integer(xml, "playingtime", "value")
20
+ @min_playing_time = get_integer(xml, "minplaytime", "value")
21
+ @max_playing_time = get_integer(xml, "maxplaytime", "value")
22
+ @statistics = nil
23
+ if !xml.at_css("statistics").nil?
24
+ @statistics = {}
25
+ @statistics[:user_ratings] = get_integer(xml, "usersrated", "value")
26
+ @statistics[:average] = get_float(xml, "average", "value")
27
+ @statistics[:bayes] = get_float(xml, "bayesaverage", "value")
28
+ @statistics[:ranks] = []
29
+ xml.css("rank").each do |rank|
30
+ rank_data = {}
31
+ rank_data[:type] = rank["type"]
32
+ rank_data[:name] = rank["name"]
33
+ rank_data[:friendly_name] = rank["friendlyname"]
34
+ rank_data[:value] = rank["value"].to_i
35
+ rank_data[:bayes] = rank["bayesaverage"].to_f
36
+ @statistics[:ranks].push(rank_data)
37
+ end
38
+ @statistics[:stddev] = get_float(xml, "stddev", "value")
39
+ @statistics[:median] = get_float(xml, "median", "value")
40
+ @statistics[:owned] = get_integer(xml, "owned", "value")
41
+ @statistics[:trading] = get_integer(xml, "trading", "value")
42
+ @statistics[:wanting] = get_integer(xml, "wanting", "value")
43
+ @statistics[:wishing] = get_integer(xml, "wishing", "value")
44
+ @statistics[:num_comments] = get_integer(xml, "numcomments", "value")
45
+ @statistics[:num_weights] = get_integer(xml, "numweights", "value")
46
+ @statistics[:average_weight] = get_integer(xml, "averageweight", "value")
47
+ else
48
+ @id = 0
49
+ @type = ""
50
+ @image = ""
51
+ @thumbnail = ""
52
+ @name = ""
53
+ @alternate_names = []
54
+ @description = ""
55
+ @year_published = -1
56
+ @min_players = -1
57
+ @max_players = -1
58
+ @playing_time = -1
59
+ @min_playing_time = -1
60
+ @max_playing_time = -1
61
+ @statistics = nil
62
+ end
63
+ end
64
+ end
65
+
66
+ def get_user_collection_data(username)
67
+ return BoardGameGem.get_collection(username, id: @id)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,17 @@
1
+ module BoardGameGem
2
+ class BGGSearchResult < BGGBase
3
+
4
+ attr_reader :id, :type, :name, :year_published
5
+
6
+ def initialize(xml)
7
+ @id = xml["id"].to_i
8
+ @type = xml["type"]
9
+ @name = get_string(xml, "name", "value")
10
+ @year_published = get_string(xml, "yearpublished", "value")
11
+ end
12
+
13
+ def to_item(statistics = false)
14
+ return BoardGameGem.get_item(@id, statistics)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module BoardGameGem
2
+ class BGGUser < BGGBase
3
+
4
+ attr_reader :id, :name, :avatar, :year_registered, :last_login, :state, :trade_rating
5
+
6
+ def initialize(xml)
7
+ @id = get_integer(xml, "user", "id")
8
+ @name = get_string(xml, "user", "name")
9
+ @avatar = get_string(xml, "avatarlink", "value")
10
+ @year_registered = get_integer(xml, "yearregistered", "value")
11
+ @last_login = get_string(xml, "lastlogin", "value")
12
+ @state = get_string(xml, "stateorprovince", "value")
13
+ @trade_rating = get_integer(xml, "traderating", "value")
14
+ end
15
+
16
+ def get_collection
17
+ return BoardGameGem.get_collection(@name)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,75 @@
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_family(id, options = {})
16
+ options[:id] = id
17
+ family = BGGFamily.new(BoardGameGem.request_xml("family", options))
18
+ return family.id == 0 ? nil : family
19
+ end
20
+
21
+ def BoardGameGem.get_user(username, options = {})
22
+ options[:name] = username
23
+ user = BGGUser.new(BoardGameGem.request_xml("user", options))
24
+ return user.id == 0 ? nil : user
25
+ end
26
+
27
+ def BoardGameGem.get_collection(username, options = {})
28
+ options[:username] = username
29
+ collection_xml = BoardGameGem.request_xml("collection", options)
30
+ if collection_xml.css("error").length > 0
31
+ return nil
32
+ else
33
+ return BGGCollection.new(collection_xml)
34
+ end
35
+ end
36
+
37
+ def BoardGameGem.search(query, options = {})
38
+ options[:query] = query
39
+ xml = BoardGameGem.request_xml("search", options)
40
+ return {
41
+ :total => xml.at_css("items")["total"].to_i,
42
+ :items => xml.css("item").map { |x| BGGSearchResult.new(x) }
43
+ }
44
+ end
45
+
46
+ private
47
+
48
+ def BoardGameGem.request_xml(method, hash, attempt = 0)
49
+ params = BoardGameGem.hash_to_uri(hash)
50
+ open("#{API_ROOT}/#{method}?#{params}") do |file|
51
+ if file.status == 202
52
+ if attempt < MAX_ATTEMPTS
53
+ sleep 0.05
54
+ BoardGameGem.request_xml(method, hash, attempt + 1)
55
+ else
56
+ return nil
57
+ end
58
+ else
59
+ Nokogiri::XML(file.read)
60
+ end
61
+ end
62
+ end
63
+
64
+ def BoardGameGem.hash_to_uri(hash)
65
+ return hash.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
66
+ end
67
+ end
68
+
69
+ require 'bgg_base'
70
+ require 'bgg_item'
71
+ require 'bgg_family'
72
+ require 'bgg_user'
73
+ require 'bgg_collection'
74
+ require 'bgg_collection_item'
75
+ require 'bgg_search_result'
@@ -0,0 +1,3 @@
1
+ module BoardGameGem
2
+ VERSION = "0.1.9"
3
+ end
data/test.rb ADDED
@@ -0,0 +1,3 @@
1
+ require_relative 'lib/BoardGameGem'
2
+
3
+ p BoardGameGem.search("suburb")
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: board-game-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.9
5
+ platform: ruby
6
+ authors:
7
+ - Jake Roussel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - jakeroussel@mac.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - boardgamegem.gemspec
71
+ - lib/bgg_base.rb
72
+ - lib/bgg_collection.rb
73
+ - lib/bgg_collection_item.rb
74
+ - lib/bgg_family.rb
75
+ - lib/bgg_item.rb
76
+ - lib/bgg_search_result.rb
77
+ - lib/bgg_user.rb
78
+ - lib/boardgamegem.rb
79
+ - lib/boardgamegem/version.rb
80
+ - test.rb
81
+ homepage: http://www.github.com/acceptableice/boardgamegem
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Provides a Ruby interface to the BoardGameGeek API
105
+ test_files: []