bgg 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,84 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Bgg::Search do
5
+ describe 'class method' do
6
+ describe 'query' do
7
+ it 'throws an ArgumentError when an empty string is passed in' do
8
+ expect{ Bgg::Search.query('') }.to raise_error(ArgumentError)
9
+ end
10
+
11
+ it 'throws an ArgumentError when a non-string is passed in' do
12
+ expect{ Bgg::Search.query(Object.new) }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ it 'returns an empty array when a search has no results' do
16
+ response_file = 'sample_data/search?query=yyyyyyy'
17
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/search'
18
+
19
+ stub_request(:any, request_url).
20
+ with(query: {query: 'yyyyyyy'}).
21
+ to_return(body: File.open(response_file), status: 200)
22
+
23
+ search_results = Bgg::Search.query('yyyyyyy')
24
+
25
+ expect( search_results ).to be_instance_of(Array)
26
+ expect( search_results.size ).to eq(0)
27
+ end
28
+
29
+ it 'creates an object for a collection that exists' do
30
+ response_file = 'sample_data/search?query=Burgun'
31
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/search'
32
+
33
+ stub_request(:any, request_url).
34
+ with(query: {query: 'Burgun'}).
35
+ to_return(body: File.open(response_file), status: 200)
36
+
37
+ search_results = Bgg::Search.query('Burgun')
38
+
39
+ expect( search_results ).to be_instance_of(Array)
40
+ expect( search_results.size ).to eq(11)
41
+
42
+ expect( search_results.first ).to be_instance_of(Bgg::Search::Result)
43
+ expect( search_results.first.name ).to eq('The Castles of Burgundy')
44
+ end
45
+ end
46
+
47
+ describe 'exact_query' do
48
+ it 'throws an ArgumentError when an empty string is passed in' do
49
+ expect{ Bgg::Search.exact_query('') }.to raise_error(ArgumentError)
50
+ end
51
+
52
+ it 'throws an ArgumentError when a non-string is passed in' do
53
+ expect{ Bgg::Search.exact_query(Object.new) }.to raise_error(ArgumentError)
54
+ end
55
+
56
+ it 'returns nil when a search has no results' do
57
+ response_file = 'sample_data/search?query=Burgun&exact=1'
58
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/search'
59
+
60
+ stub_request(:any, request_url).
61
+ with(query: {query: 'Burgun', exact: 1}).
62
+ to_return(body: File.open(response_file), status: 200)
63
+
64
+ search_results = Bgg::Search.exact_query('Burgun')
65
+
66
+ expect( search_results ).to eq(nil)
67
+ end
68
+
69
+ it 'returns a single result for a result that exists' do
70
+ response_file = 'sample_data/search?query=The+Castles+of+Burgundy&exact=1'
71
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/search'
72
+
73
+ stub_request(:any, request_url).
74
+ with(query: {query: 'The Castles of Burgundy', exact: 1}).
75
+ to_return(body: File.open(response_file), status: 200)
76
+
77
+ search_result = Bgg::Search.exact_query('The Castles of Burgundy')
78
+
79
+ expect( search_result ).to be_instance_of(Bgg::Search::Result)
80
+ expect( search_result.name ).to eq('The Castles of Burgundy')
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bgg::User do
4
+ describe 'class method' do
5
+ describe 'find_by_id' do
6
+ it 'throws an ArgumentError when a non-integer is passed in' do
7
+ expect{ Bgg::User.find_by_id('string instead') }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'throws an ArgumentError when a non-positive integer is passed in' do
11
+ expect{ Bgg::User.find_by_id(0) }.to raise_error(ArgumentError)
12
+ expect{ Bgg::User.find_by_id(-1) }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ it 'creates an object for a user who exists' do
16
+ response_file = 'sample_data/user?name=texasjdl'
17
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/user'
18
+
19
+ stub_request(:any, request_url).with(query: {id: 39488}).to_return(body: File.open(response_file), status: 200)
20
+ texasjdl = Bgg::User.find_by_id(39488)
21
+
22
+ expect( texasjdl ).to be_a_kind_of(Bgg::User)
23
+ expect( texasjdl.name ).to eq('texasjdl')
24
+ end
25
+
26
+ it 'throws an ArgumentError for a user who does not exist' do
27
+ response_file = 'sample_data/user?name=yyyyyyy'
28
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/user'
29
+
30
+ stub_request(:any, request_url).with(query: {id: 39488}).to_return(body: File.open(response_file), status: 200)
31
+
32
+ expect{ Bgg::User.find_by_id(39488) }.to raise_error(ArgumentError, 'User does not exist')
33
+ end
34
+ end
35
+
36
+ describe 'find_by_name' do
37
+ it 'creates an object for a user who exists' do
38
+ response_file = 'sample_data/user?name=texasjdl'
39
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/user'
40
+
41
+ stub_request(:any, request_url).with(query: {name: 'texasjdl'}).to_return(body: File.open(response_file), status: 200)
42
+ texasjdl = Bgg::User.find_by_name('texasjdl')
43
+
44
+ expect( texasjdl ).to be_a_kind_of(Object)
45
+ expect( texasjdl.name ).to eq('texasjdl')
46
+ end
47
+
48
+ it 'throws an ArgumentError for a user who does not exist' do
49
+ response_file = 'sample_data/user?name=yyyyyyy'
50
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/user'
51
+
52
+ stub_request(:any, request_url).with(query: {name: 'yyyyyyy'}).to_return(body: File.open(response_file), status: 200)
53
+
54
+ expect{ Bgg::User.find_by_name('yyyyyyy') }.to raise_error(ArgumentError, 'User does not exist')
55
+ end
56
+ end
57
+
58
+ describe 'instance method' do
59
+ let(:response_file) { 'sample_data/user?name=texasjdl' }
60
+ let(:request_url) { 'http://www.boardgamegeek.com/xmlapi2/user' }
61
+ let(:texasjdl) { Bgg::User.find_by_id(39488) }
62
+
63
+ before do
64
+ stub_request(:any, request_url).
65
+ with(query: {id: 39488}).
66
+ to_return(body: File.open(response_file), status: 200)
67
+ end
68
+
69
+ describe '.play_count' do
70
+ it 'returns the number of plays when the user has plays' do
71
+ stub_request(:any, 'http://www.boardgamegeek.com/xmlapi2/plays').
72
+ with(query: {username: 'texasjdl', page: 1}).
73
+ to_return(body: File.open('sample_data/plays?username=texasjdl&page=1'), status: 200)
74
+
75
+ expect( texasjdl.play_count ).to eq(299)
76
+ end
77
+ end
78
+
79
+ describe 'collection' do
80
+ it 'returns the collection object representing the collection for the user' do
81
+ stub_request(:any, 'http://www.boardgamegeek.com/xmlapi2/collection').
82
+ with(query: {username: 'texasjdl'}).
83
+ to_return(body: File.open('sample_data/collection?username=texasjdl'), status: 200)
84
+
85
+ collection = texasjdl.collection
86
+
87
+ expect( collection ).to be_instance_of(Bgg::Collection)
88
+ expect( collection.owned.first ).to be_instance_of(Bgg::Collection::Item)
89
+ expect( collection.size ).to eq(604)
90
+ end
91
+ end
92
+
93
+ describe '.plays' do
94
+ it 'returns a Bgg::PlaysIterator' do
95
+ [1,2,3].each do |i|
96
+ stub_request(:any, 'http://www.boardgamegeek.com/xmlapi2/plays').
97
+ with(query: {username: 'texasjdl', page: i}).
98
+ to_return(body: File.open("sample_data/plays?username=texasjdl&page=#{i}"), status: 200)
99
+ end
100
+
101
+ plays = texasjdl.plays
102
+ first_play = plays.first
103
+
104
+ expect( plays ).to be_an_instance_of(Bgg::Plays::Iterator)
105
+ expect( first_play ).to be_an_instance_of(Bgg::Play)
106
+ expect( first_play.game_name ).to eq('Fauna')
107
+ expect( first_play.players.size ).to eq(5)
108
+ expect( first_play.players.first.name ).to eq('Ted')
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,29 @@
1
+ if ENV['COVERAGE'] == 'yes'
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
6
+ require 'webmock/rspec'
7
+ require 'rspec'
8
+ require 'bgg'
9
+ require 'codeclimate-test-reporter'
10
+
11
+ CodeClimate::TestReporter.start
12
+
13
+ # This file was generated by the `rspec --init` command. Conventionally, all
14
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
15
+ # Require this file using `require "spec_helper"` to ensure that it is only
16
+ # loaded once.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ config.treat_symbols_as_metadata_keys_with_true_values = true
21
+ config.run_all_when_everything_filtered = true
22
+ config.filter_run :focus
23
+
24
+ # Run specs in random order to surface order dependencies. If you find an
25
+ # order dependency and want to debug it, you can fix the order by providing
26
+ # the seed, which is printed after each run.
27
+ # --seed 1234
28
+ config.order = 'random'
29
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bgg
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremiah Lee
8
+ - Brett Hardin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: xml-simple
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 1.0.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: jeweler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rdoc
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: simplecov
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: webmock
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: codeclimate-test-reporter
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rake
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rspec
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ description: Object-oriented interface for interacting with Boardgamegeek API
155
+ email: jeremiah.lee@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files:
159
+ - LICENSE.txt
160
+ - README.md
161
+ files:
162
+ - ".document"
163
+ - ".rspec"
164
+ - ".travis.yml"
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - VERSION
171
+ - bgg.gemspec
172
+ - lib/bgg.rb
173
+ - lib/bgg/collection.rb
174
+ - lib/bgg/collection_item.rb
175
+ - lib/bgg/game.rb
176
+ - lib/bgg/play.rb
177
+ - lib/bgg/plays.rb
178
+ - lib/bgg/plays_iterator.rb
179
+ - lib/bgg/search.rb
180
+ - lib/bgg/search_result.rb
181
+ - lib/bgg/user.rb
182
+ - sample_data/collection?username=texasjdl
183
+ - sample_data/collection?username=texasjdl&own=1&excludesubtype=boardgameexpansion
184
+ - sample_data/collection?username=yyyyyyy
185
+ - sample_data/hot?type=boardgame
186
+ - sample_data/plays?pages=9999999999999&username=ryanmacg
187
+ - sample_data/plays?username=beetss&page=1
188
+ - sample_data/plays?username=ryanmacg
189
+ - sample_data/plays?username=texasjdl&id=84876
190
+ - sample_data/plays?username=texasjdl&id=84876&type=thing
191
+ - sample_data/plays?username=texasjdl&page=1
192
+ - sample_data/plays?username=texasjdl&page=2
193
+ - sample_data/plays?username=texasjdl&page=3
194
+ - sample_data/plays?username=yyyyyyy&page=1
195
+ - sample_data/search?query=Burgun
196
+ - sample_data/search?query=Burgun&exact=1
197
+ - sample_data/search?query=Burgund&type=boardgame
198
+ - sample_data/search?query=The+Castles+of+Burgundy&exact=1
199
+ - sample_data/search?query=yyyyyyy
200
+ - sample_data/thing?id=10000000&type=boardgame
201
+ - sample_data/thing?id=29773&type=boardgame
202
+ - sample_data/thing?id=70512&type=boardgame
203
+ - sample_data/thing?id=84876&type=boardgame
204
+ - sample_data/user?name=texasjdl
205
+ - sample_data/user?name=yyyyyyy
206
+ - spec/bgg_api_spec.rb
207
+ - spec/bgg_collection_item_spec.rb
208
+ - spec/bgg_collection_spec.rb
209
+ - spec/bgg_game_spec.rb
210
+ - spec/bgg_play_spec.rb
211
+ - spec/bgg_plays_iterator_spec.rb
212
+ - spec/bgg_plays_spec.rb
213
+ - spec/bgg_search_result_spec.rb
214
+ - spec/bgg_search_spec.rb
215
+ - spec/bgg_user_spec.rb
216
+ - spec/spec_helper.rb
217
+ homepage: http://github.com/jemaihlee/bgg
218
+ licenses:
219
+ - MIT
220
+ metadata: {}
221
+ post_install_message:
222
+ rdoc_options: []
223
+ require_paths:
224
+ - lib
225
+ required_ruby_version: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ required_rubygems_version: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - ">="
233
+ - !ruby/object:Gem::Version
234
+ version: '0'
235
+ requirements: []
236
+ rubyforge_project:
237
+ rubygems_version: 2.2.2
238
+ signing_key:
239
+ specification_version: 4
240
+ summary: object-oriented boardgamegeek api gem
241
+ test_files: []