bgg 1.0.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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +20 -0
  6. data/Gemfile.lock +54 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +73 -0
  9. data/Rakefile +38 -0
  10. data/VERSION +1 -0
  11. data/bgg.gemspec +122 -0
  12. data/lib/bgg.rb +53 -0
  13. data/lib/bgg/collection.rb +58 -0
  14. data/lib/bgg/collection_item.rb +69 -0
  15. data/lib/bgg/game.rb +57 -0
  16. data/lib/bgg/play.rb +64 -0
  17. data/lib/bgg/plays.rb +26 -0
  18. data/lib/bgg/plays_iterator.rb +64 -0
  19. data/lib/bgg/search.rb +34 -0
  20. data/lib/bgg/search_result.rb +18 -0
  21. data/lib/bgg/user.rb +60 -0
  22. data/sample_data/collection?username=texasjdl +5224 -0
  23. data/sample_data/collection?username=texasjdl&own=1&excludesubtype=boardgameexpansion +2606 -0
  24. data/sample_data/collection?username=yyyyyyy +3 -0
  25. data/sample_data/hot?type=boardgame +253 -0
  26. data/sample_data/plays?pages=9999999999999&username=ryanmacg +2 -0
  27. data/sample_data/plays?username=beetss&page=1 +3 -0
  28. data/sample_data/plays?username=ryanmacg +504 -0
  29. data/sample_data/plays?username=texasjdl&id=84876 +192 -0
  30. data/sample_data/plays?username=texasjdl&id=84876&type=thing +199 -0
  31. data/sample_data/plays?username=texasjdl&page=1 +717 -0
  32. data/sample_data/plays?username=texasjdl&page=2 +709 -0
  33. data/sample_data/plays?username=texasjdl&page=3 +707 -0
  34. data/sample_data/plays?username=yyyyyyy&page=1 +667 -0
  35. data/sample_data/search?query=Burgun +47 -0
  36. data/sample_data/search?query=Burgun&exact=1 +3 -0
  37. data/sample_data/search?query=Burgund&type=boardgame +12 -0
  38. data/sample_data/search?query=The+Castles+of+Burgundy&exact=1 +7 -0
  39. data/sample_data/search?query=yyyyyyy +3 -0
  40. data/sample_data/thing?id=10000000&type=boardgame +3 -0
  41. data/sample_data/thing?id=29773&type=boardgame +90 -0
  42. data/sample_data/thing?id=70512&type=boardgame +82 -0
  43. data/sample_data/thing?id=84876&type=boardgame +82 -0
  44. data/sample_data/user?name=texasjdl +17 -0
  45. data/sample_data/user?name=yyyyyyy +17 -0
  46. data/spec/bgg_api_spec.rb +113 -0
  47. data/spec/bgg_collection_item_spec.rb +259 -0
  48. data/spec/bgg_collection_spec.rb +83 -0
  49. data/spec/bgg_game_spec.rb +232 -0
  50. data/spec/bgg_play_spec.rb +166 -0
  51. data/spec/bgg_plays_iterator_spec.rb +156 -0
  52. data/spec/bgg_plays_spec.rb +60 -0
  53. data/spec/bgg_search_result_spec.rb +73 -0
  54. data/spec/bgg_search_spec.rb +84 -0
  55. data/spec/bgg_user_spec.rb +113 -0
  56. data/spec/spec_helper.rb +29 -0
  57. metadata +241 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: caa780dfe0e92277f11577072e0f35275922d554
4
+ data.tar.gz: 942ae33daffac8ff1f1e9c1065047da0b7645da9
5
+ SHA512:
6
+ metadata.gz: 1b218000c4ba5631437409596a676a807c390312b255a54c625bdc4a6d08729cdf34416af897fb7b69d2dbdeff55477a2ffc7892863620a956dc685cb67ba2ce
7
+ data.tar.gz: 23aed87b53e5c245a2f6b7672abdc1cf4ba4c5b9a4f26009345206fc7afb1df641832e82ab6f2e00ef8c3951591b280529d6cc6f8eb161f9f57d17e22074672d
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format d
@@ -0,0 +1,6 @@
1
+ language: "ruby"
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ before_script: 'bundle'
6
+ script: 'CODECLIMATE_REPO_TOKEN=187555d2e125f5add7c7150d4e529f7f872510808a16aaad4a62e5cc1c1eb53c bundle exec rake'
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'http://rubygems.org'
2
+ gem 'httparty'
3
+ gem 'xml-simple'
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem 'bundler', '>= 1.0.0'
9
+ gem 'jeweler'
10
+ gem 'rdoc'
11
+ gem 'simplecov'
12
+ gem 'webmock'
13
+ end
14
+
15
+ group :test, :development do
16
+ gem 'codeclimate-test-reporter'
17
+ gem 'rake'
18
+ gem 'rspec'
19
+ end
20
+
@@ -0,0 +1,54 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.2)
5
+ codeclimate-test-reporter (0.3.0)
6
+ simplecov (>= 0.7.1, < 1.0.0)
7
+ crack (0.3.1)
8
+ diff-lcs (1.1.3)
9
+ git (1.2.5)
10
+ httparty (0.8.3)
11
+ multi_json (~> 1.0)
12
+ multi_xml
13
+ jeweler (1.8.4)
14
+ bundler (~> 1.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ rdoc
18
+ json (1.7.6)
19
+ multi_json (1.3.2)
20
+ multi_xml (0.4.4)
21
+ rake (10.0.3)
22
+ rdoc (3.12)
23
+ json (~> 1.4)
24
+ rspec (2.11.0)
25
+ rspec-core (~> 2.11.0)
26
+ rspec-expectations (~> 2.11.0)
27
+ rspec-mocks (~> 2.11.0)
28
+ rspec-core (2.11.1)
29
+ rspec-expectations (2.11.2)
30
+ diff-lcs (~> 1.1.3)
31
+ rspec-mocks (2.11.2)
32
+ simplecov (0.7.1)
33
+ multi_json (~> 1.0)
34
+ simplecov-html (~> 0.7.1)
35
+ simplecov-html (0.7.1)
36
+ webmock (1.8.9)
37
+ addressable (>= 2.2.7)
38
+ crack (>= 0.1.7)
39
+ xml-simple (1.1.1)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (>= 1.0.0)
46
+ codeclimate-test-reporter
47
+ httparty
48
+ jeweler
49
+ rake
50
+ rdoc
51
+ rspec
52
+ simplecov
53
+ webmock
54
+ xml-simple
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Jeremiah Lee, Brett Hardin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ bgg gem [![Build Status](https://travis-ci.org/jemiahlee/bgg.svg)](https://travis-ci.org/jemiahlee/bgg) [![Code Climate](https://codeclimate.com/github/jemiahlee/bgg.png)](https://codeclimate.com/github/jemiahlee/bgg)
2
+ ===========
3
+
4
+ An object-oriented API for interacting with the [boardgamegeek](http://boardgamegeek.com) [XML Version 2 API](http://boardgamegeek.com/wiki/page/BGG_XML_API2).
5
+
6
+ This is based on a fork of earlier work I had done on
7
+ [bgg-api](http://github.com/bhardin/bgg-api), along with Brett and a few
8
+ other contributors.
9
+
10
+ ## Versions supported
11
+
12
+ Please note that this code uses Ruby 1.9 hash syntax and thus does not
13
+ support versions earlier than that.
14
+
15
+ ## Installing the Gem
16
+
17
+ Do the following to install the [bgg gem](http://rubygems.org/gems/bgg) Ruby Gem.
18
+
19
+ Add the following to your `Gemfile`:
20
+
21
+ ```ruby
22
+ gem "bgg"
23
+ ```
24
+
25
+ Then run `bundle install` from the command line:
26
+
27
+ bundle install
28
+
29
+ ## Using the Gem
30
+
31
+ Require the gem at the top of any file you want to use.
32
+
33
+ require 'bgg'
34
+
35
+ You can either use the low level basic api and then parse the XML document in a way that suits your needs,
36
+ or you can use the specialized methods
37
+
38
+ There are object types and subtypes for many of the APIs documented at
39
+ [BGG_XML_API2](http://boardgamegeek.com/wiki/page/BGG_XML_API2), but not all of them are implemented.
40
+ Everything around a user and their game collection should work, as well
41
+ as generalized searching for board games.
42
+
43
+ ### Example
44
+
45
+ Most of the documentation right now is in the specs. I will work on
46
+ beefing this section up shortly.
47
+
48
+ ```ruby
49
+ texasjdl = Bgg::User.find_by_id(39488)
50
+ texasjdl.collection.played.each do |item|
51
+ puts "#{item.name} is #{item.owned? ? '' : 'not'} owned."
52
+ end
53
+ ```
54
+
55
+
56
+ Contributing to bgg
57
+ -----------------------
58
+
59
+ * Fork the project
60
+ * Start a feature/bugfix branch
61
+ * Test whatever you are committing. Ensure this test is a specification
62
+ of the behavior of the functionality, not just an error case or
63
+ success case.
64
+ * Commit and push until you are happy with your contribution
65
+ * Submit a pull request. Squash commits that should be squashed (it is
66
+ not necessary for you to have just one commit to your pull request,
67
+ but have each commit be a logical piece of work.)
68
+
69
+ Copyright
70
+ ---------
71
+
72
+ Copyright (c) 2014 [Jeremiah Lee](https://github.com/jemiahlee), [Brett Hardin](http://bretthard.in), and [Marcello Missiroli](https://github.com/piffy). See LICENSE.txt for further details.
73
+
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require 'jeweler'
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rdoc/task'
9
+ require 'rspec/core/rake_task'
10
+
11
+ task default: :spec
12
+
13
+ Jeweler::Tasks.new do |gem|
14
+ gem.name = 'bgg'
15
+ gem.homepage = 'http://github.com/jemaihlee/bgg'
16
+ gem.license = 'MIT'
17
+ gem.summary = 'object-oriented boardgamegeek api gem'
18
+ gem.description = 'Object-oriented interface for interacting with Boardgamegeek API'
19
+ gem.email = 'jeremiah.lee@gmail.com'
20
+ gem.authors = ['Jeremiah Lee', 'Brett Hardin']
21
+ end
22
+ Jeweler::RubygemsDotOrgTasks.new
23
+
24
+ RSpec::Core::RakeTask.new(:spec)
25
+
26
+ task :coverage do
27
+ ENV['COVERAGE'] = 'yes'
28
+ Rake::Task['spec'].execute
29
+ end
30
+
31
+ Rake::RDocTask.new do |rdoc|
32
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
33
+
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = "bgg #{version}"
36
+ rdoc.rdoc_files.include('README*')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,122 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: bgg 1.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "bgg"
9
+ s.version = "1.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Jeremiah Lee", "Brett Hardin"]
14
+ s.date = "2014-05-07"
15
+ s.description = "Object-oriented interface for interacting with Boardgamegeek API"
16
+ s.email = "jeremiah.lee@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".travis.yml",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "LICENSE.txt",
28
+ "README.md",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "bgg.gemspec",
32
+ "lib/bgg.rb",
33
+ "lib/bgg/collection.rb",
34
+ "lib/bgg/collection_item.rb",
35
+ "lib/bgg/game.rb",
36
+ "lib/bgg/play.rb",
37
+ "lib/bgg/plays.rb",
38
+ "lib/bgg/plays_iterator.rb",
39
+ "lib/bgg/search.rb",
40
+ "lib/bgg/search_result.rb",
41
+ "lib/bgg/user.rb",
42
+ "sample_data/collection?username=texasjdl",
43
+ "sample_data/collection?username=texasjdl&own=1&excludesubtype=boardgameexpansion",
44
+ "sample_data/collection?username=yyyyyyy",
45
+ "sample_data/hot?type=boardgame",
46
+ "sample_data/plays?pages=9999999999999&username=ryanmacg",
47
+ "sample_data/plays?username=beetss&page=1",
48
+ "sample_data/plays?username=ryanmacg",
49
+ "sample_data/plays?username=texasjdl&id=84876",
50
+ "sample_data/plays?username=texasjdl&id=84876&type=thing",
51
+ "sample_data/plays?username=texasjdl&page=1",
52
+ "sample_data/plays?username=texasjdl&page=2",
53
+ "sample_data/plays?username=texasjdl&page=3",
54
+ "sample_data/plays?username=yyyyyyy&page=1",
55
+ "sample_data/search?query=Burgun",
56
+ "sample_data/search?query=Burgun&exact=1",
57
+ "sample_data/search?query=Burgund&type=boardgame",
58
+ "sample_data/search?query=The+Castles+of+Burgundy&exact=1",
59
+ "sample_data/search?query=yyyyyyy",
60
+ "sample_data/thing?id=10000000&type=boardgame",
61
+ "sample_data/thing?id=29773&type=boardgame",
62
+ "sample_data/thing?id=70512&type=boardgame",
63
+ "sample_data/thing?id=84876&type=boardgame",
64
+ "sample_data/user?name=texasjdl",
65
+ "sample_data/user?name=yyyyyyy",
66
+ "spec/bgg_api_spec.rb",
67
+ "spec/bgg_collection_item_spec.rb",
68
+ "spec/bgg_collection_spec.rb",
69
+ "spec/bgg_game_spec.rb",
70
+ "spec/bgg_play_spec.rb",
71
+ "spec/bgg_plays_iterator_spec.rb",
72
+ "spec/bgg_plays_spec.rb",
73
+ "spec/bgg_search_result_spec.rb",
74
+ "spec/bgg_search_spec.rb",
75
+ "spec/bgg_user_spec.rb",
76
+ "spec/spec_helper.rb"
77
+ ]
78
+ s.homepage = "http://github.com/jemaihlee/bgg"
79
+ s.licenses = ["MIT"]
80
+ s.rubygems_version = "2.2.2"
81
+ s.summary = "object-oriented boardgamegeek api gem"
82
+
83
+ if s.respond_to? :specification_version then
84
+ s.specification_version = 4
85
+
86
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
87
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
88
+ s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
89
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
90
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
91
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
92
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
93
+ s.add_development_dependency(%q<webmock>, [">= 0"])
94
+ s.add_development_dependency(%q<codeclimate-test-reporter>, [">= 0"])
95
+ s.add_development_dependency(%q<rake>, [">= 0"])
96
+ s.add_development_dependency(%q<rspec>, [">= 0"])
97
+ else
98
+ s.add_dependency(%q<httparty>, [">= 0"])
99
+ s.add_dependency(%q<xml-simple>, [">= 0"])
100
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
101
+ s.add_dependency(%q<jeweler>, [">= 0"])
102
+ s.add_dependency(%q<rdoc>, [">= 0"])
103
+ s.add_dependency(%q<simplecov>, [">= 0"])
104
+ s.add_dependency(%q<webmock>, [">= 0"])
105
+ s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
106
+ s.add_dependency(%q<rake>, [">= 0"])
107
+ s.add_dependency(%q<rspec>, [">= 0"])
108
+ end
109
+ else
110
+ s.add_dependency(%q<httparty>, [">= 0"])
111
+ s.add_dependency(%q<xml-simple>, [">= 0"])
112
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
113
+ s.add_dependency(%q<jeweler>, [">= 0"])
114
+ s.add_dependency(%q<rdoc>, [">= 0"])
115
+ s.add_dependency(%q<simplecov>, [">= 0"])
116
+ s.add_dependency(%q<webmock>, [">= 0"])
117
+ s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
118
+ s.add_dependency(%q<rake>, [">= 0"])
119
+ s.add_dependency(%q<rspec>, [">= 0"])
120
+ end
121
+ end
122
+
@@ -0,0 +1,53 @@
1
+ require 'httparty'
2
+ require 'xmlsimple'
3
+
4
+ # http://boardgamegeek.com/wiki/page/BGG_XML_API2#
5
+
6
+ class BggApi
7
+ include HTTParty
8
+
9
+ METHODS = [
10
+ :collection,
11
+ :family,
12
+ :forum,
13
+ :forumlist,
14
+ :guild,
15
+ :hot,
16
+ :plays,
17
+ :search,
18
+ :thing,
19
+ :thread,
20
+ :user,
21
+ ].freeze
22
+
23
+ BASE_URI = 'http://www.boardgamegeek.com/xmlapi2'
24
+ OLD_URI = 'http://www.boardgamegeek.com/xmlapi'
25
+
26
+ METHODS.each do |method|
27
+ define_singleton_method(method) do |params|
28
+ params ||= {}
29
+
30
+ url = BASE_URI + '/' + method.to_s
31
+ response = self.get(url, :query => params)
32
+
33
+ if response.code == 200
34
+ xml_data = response.body
35
+ XmlSimple.xml_in(xml_data)
36
+ else
37
+ raise "Received a #{response.code} at #{url} with #{params}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ require 'bgg/collection'
45
+ require 'bgg/collection_item'
46
+ require 'bgg/game'
47
+ require 'bgg/play'
48
+ require 'bgg/plays'
49
+ require 'bgg/plays_iterator'
50
+ require 'bgg/search'
51
+ require 'bgg/search_result'
52
+ require 'bgg/user'
53
+
@@ -0,0 +1,58 @@
1
+ module Bgg
2
+ class Collection
3
+ def self.find_by_username(username)
4
+ if username =~ /^\d*$/
5
+ # this is a sorta hokey restriction because there is probably nothing requiring
6
+ # users to have non-numeric usernames. I'm not sure that I've seen one though.
7
+ raise ArgumentError.new('username must not be empty or only digits!')
8
+ end
9
+
10
+ if username.is_a?(Integer)
11
+ raise ArgumentError.new('username must not be an Integer!')
12
+ end
13
+
14
+ collection_data = BggApi.collection({username: username})
15
+
16
+ unless collection_data.has_key?('item')
17
+ raise ArgumentError.new('User does not exist')
18
+ end
19
+
20
+ Bgg::Collection.new(collection_data)
21
+ end
22
+ end
23
+
24
+ class Collection
25
+ def initialize(collection_data)
26
+ @items = []
27
+
28
+ collection_data['item'].each do |item|
29
+ bgg_item = Bgg::Collection::Item.new(item)
30
+ @items.push(bgg_item)
31
+ end
32
+ end
33
+
34
+ def size
35
+ @items.size
36
+ end
37
+
38
+ def count
39
+ self.size
40
+ end
41
+
42
+ def owned
43
+ @items.select{ |item| item.owned? }
44
+ end
45
+
46
+ def boardgames
47
+ @items.select{ |item| item.type == 'boardgame' }
48
+ end
49
+
50
+ def boardgame_expansions
51
+ @items.select{ |item| item.name =~ /expansion/i }
52
+ end
53
+
54
+ def played
55
+ @items.select{ |item| item.played? }
56
+ end
57
+ end
58
+ end