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,259 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Bgg::Collection::Item do
5
+ let(:item_data) { {'objecttype'=>'thing',
6
+ 'objectid'=>'70512',
7
+ 'subtype'=>'boardgame',
8
+ 'collid'=>'11455824',
9
+ 'name'=>[{'sortindex'=>'1', 'content'=>'Luna'}],
10
+ 'yearpublished'=>['2010'],
11
+ 'image'=>['http://cf.geekdo-images.com/images/pic802342.jpg'],
12
+ 'thumbnail'=>['http://cf.geekdo-images.com/images/pic802342_t.jpg'],
13
+ 'status'=>[{'own'=>'1', 'prevowned'=>'0', 'fortrade'=>'0', 'want'=>'0', 'wanttoplay'=>'0', 'wanttobuy'=>'0', "wishlist"=>'0', 'preordered'=>'0', 'lastmodified'=>'2007-02-18 21:20:51'}], 'numplays'=>['7'], 'comment'=>['Never played.']} }
14
+
15
+ let(:item) { Bgg::Collection::Item.new(item_data) }
16
+
17
+ describe '.id' do
18
+ it 'exists' do
19
+ expect( item ).to respond_to(:id)
20
+ end
21
+
22
+ it 'returns correct value' do
23
+ expect( item.id ).to eq(70512)
24
+ end
25
+ end
26
+
27
+ describe '.name' do
28
+ it 'exists' do
29
+ expect( item ).to respond_to(:name)
30
+ end
31
+
32
+ it 'returns the correct value' do
33
+ expect( item.name ).to eq('Luna')
34
+ end
35
+ end
36
+
37
+ describe '.collection_id' do
38
+ it 'exists' do
39
+ expect( item ).to respond_to(:collection_id)
40
+ end
41
+
42
+ it 'returns the correct value' do
43
+ expect( item.collection_id ).to eq(11455824)
44
+ end
45
+ end
46
+
47
+ describe '.owned?' do
48
+ it 'exists' do
49
+ expect( item ).to respond_to(:owned?)
50
+ end
51
+
52
+ it 'returns true when own == 1' do
53
+ item_data['status'][0]['own'] = '1'
54
+ expect( item.owned? ).to eq(true)
55
+ end
56
+
57
+ it 'returns true when want == 0' do
58
+ item_data['status'][0]['own'] = '0'
59
+ expect( item.owned? ).to eq(false)
60
+ end
61
+ end
62
+
63
+ describe '.wanted?' do
64
+ it 'exists' do
65
+ expect( item ).to respond_to(:wanted?)
66
+ end
67
+
68
+ it 'returns true when want == 0' do
69
+ item_data['status'][0]['want'] = '0'
70
+ expect( item.wanted? ).to eq(false)
71
+ end
72
+
73
+ it 'returns true when want == 1' do
74
+ item_data['status'][0]['want'] = '1'
75
+ expect( item.wanted? ).to eq(true)
76
+ end
77
+ end
78
+
79
+ describe '.for_trade?' do
80
+ it 'exists' do
81
+ expect( item ).to respond_to(:for_trade?)
82
+ end
83
+
84
+ it 'returns false when fortrade == 0' do
85
+ item_data['status'][0]['fortrade'] = '0'
86
+ expect( item.for_trade? ).to eq(false)
87
+ end
88
+
89
+ it 'returns true when fortrade == 1' do
90
+ item_data['status'][0]['fortrade'] = '1'
91
+ expect( item.for_trade? ).to eq(true)
92
+ end
93
+ end
94
+
95
+ describe '.played?' do
96
+ it 'exists' do
97
+ expect( item ).to respond_to(:played?)
98
+ end
99
+
100
+ it 'returns true when play_count > 0' do
101
+ item_data['numplays'][0] = '7'
102
+ expect( item.played? ).to eq(true)
103
+ end
104
+
105
+ it 'returns false when play_count == 0' do
106
+ item_data['numplays'][0] = '0'
107
+ expect( item.played? ).to eq(false)
108
+ end
109
+ end
110
+
111
+ describe '.want_to_buy?' do
112
+ it 'exists' do
113
+ expect( item ).to respond_to(:want_to_buy?)
114
+ end
115
+
116
+ it 'returns true when wanttobuy == 1' do
117
+ item_data['status'][0]['wanttobuy'] = '1'
118
+ expect( item.want_to_buy? ).to eq(true)
119
+ end
120
+
121
+ it 'returns false when wanttobuy == 0' do
122
+ item_data['status'][0]['wanttobuy'] = '0'
123
+ expect( item.want_to_buy? ).to eq(false)
124
+ end
125
+ end
126
+
127
+ describe '.preordered?' do
128
+ it 'exists' do
129
+ expect( item ).to respond_to(:preordered?)
130
+ end
131
+
132
+ it 'returns true when preordered == 1' do
133
+ item_data['status'][0]['preordered'] = '1'
134
+ expect( item.preordered? ).to eq(true)
135
+ end
136
+
137
+ it 'returns false when preordered == 0' do
138
+ item_data['status'][0]['preordered'] = '0'
139
+ expect( item.preordered? ).to eq(false)
140
+ end
141
+ end
142
+
143
+ describe '.want_to_play?' do
144
+ it 'exists' do
145
+ expect( item ).to respond_to(:want_to_play?)
146
+ end
147
+
148
+ it 'returns true when wanttoplay == 1' do
149
+ item_data['status'][0]['wanttoplay'] = '1'
150
+ expect( item.want_to_play? ).to eq(true)
151
+ end
152
+
153
+ it 'returns false when wanttoplay == 0' do
154
+ item_data['status'][0]['wanttoplay'] = '0'
155
+ expect( item.want_to_play? ).to eq(false)
156
+ end
157
+ end
158
+
159
+ describe '.published?' do
160
+ it 'exists' do
161
+ expect( item ).to respond_to(:published?)
162
+ end
163
+
164
+ it 'returns true when yearpublished exists' do
165
+ expect( item.published? ).to eq(true)
166
+ end
167
+
168
+ it 'returns false when yearpublished does not exist' do
169
+ item_data.delete('yearpublished')
170
+ expect( item.published? ).to eq(false)
171
+ end
172
+ end
173
+
174
+ describe '.type' do
175
+ it 'exists' do
176
+ expect( item ).to respond_to(:type)
177
+ end
178
+
179
+ it 'returns boardgame when it is a boardgame' do
180
+ expect( item.type ).to eq('boardgame')
181
+ end
182
+ end
183
+
184
+ describe '.play_count' do
185
+ it 'exists' do
186
+ expect( item ).to respond_to(:play_count)
187
+ end
188
+
189
+ it 'returns the correct value' do
190
+ expect( item.play_count ).to eq(7)
191
+ end
192
+ end
193
+
194
+ describe '.year_published' do
195
+ it 'exists' do
196
+ expect( item ).to respond_to(:year_published)
197
+ end
198
+
199
+ it 'returns the correct value' do
200
+ expect( item.year_published ).to eq(2010)
201
+ end
202
+
203
+ it 'returns 0 if it is not published' do
204
+ item_data.delete('yearpublished')
205
+ expect( item.year_published ).to eq(0)
206
+ end
207
+ end
208
+
209
+ describe '.thumbnail' do
210
+ it 'exists' do
211
+ expect( item ).to respond_to(:thumbnail)
212
+ end
213
+
214
+ it 'returns the correct value' do
215
+ expect( item.thumbnail ).to eq('http://cf.geekdo-images.com/images/pic802342_t.jpg')
216
+ end
217
+ end
218
+
219
+ describe '.image' do
220
+ it 'exists' do
221
+ expect( item ).to respond_to(:image)
222
+ end
223
+
224
+ it 'returns the correct value' do
225
+ expect( item.image ).to eq('http://cf.geekdo-images.com/images/pic802342.jpg')
226
+ end
227
+ end
228
+
229
+ describe '.comment' do
230
+ it 'exists' do
231
+ expect( item ).to respond_to(:comment)
232
+ end
233
+
234
+ it 'returns the correct value' do
235
+ expect( item.comment ).to eq('Never played.')
236
+ end
237
+ end
238
+
239
+ describe '.game' do
240
+ it 'exists' do
241
+ expect( item ).to respond_to(:game)
242
+ end
243
+
244
+ it 'returns a Bgg::Game object corresponding to the entry' do
245
+ response_file = 'sample_data/thing?id=70512&type=boardgame'
246
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/thing'
247
+
248
+ stub_request(:any, request_url).
249
+ with(query: {id: 70512, type: 'boardgame'}).
250
+ to_return(body: File.open(response_file), status: 200)
251
+
252
+ game = item.game
253
+
254
+ expect( game ).to be_instance_of(Bgg::Game)
255
+ expect( game.name ).to eq('Luna')
256
+ expect( game.designers ).to eq(['Stefan Feld'])
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,83 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Bgg::Collection do
5
+ describe 'find_by_username' do
6
+ it 'throws an ArgumentError when a number is passed in' do
7
+ expect{ Bgg::Collection.find_by_username(38383) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'throws an ArgumentError when an empty string is passed in' do
11
+ expect{ Bgg::Collection.find_by_username('') }.to raise_error(ArgumentError)
12
+ end
13
+
14
+ it 'throws an ArgumentError when a string of only numbers is passed in' do
15
+ expect{ Bgg::Collection.find_by_username('38383') }.to raise_error(ArgumentError)
16
+ end
17
+
18
+ it 'throws an ArgumentError when a non-existent user is passed in' do
19
+ response_file = 'sample_data/collection?username=yyyyyyy'
20
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/collection'
21
+
22
+ stub_request(:any, request_url).
23
+ with(query: {username: 'yyyyyyy'}).
24
+ to_return(body: File.open(response_file), status: 200)
25
+
26
+ expect{ Bgg::Collection.find_by_username('yyyyyyy')}.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it 'creates an object for a collection that exists' do
30
+ response_file = 'sample_data/collection?username=texasjdl'
31
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/collection'
32
+
33
+ stub_request(:any, request_url).
34
+ with(query: {username: 'texasjdl'}).
35
+ to_return(body: File.open(response_file), status: 200)
36
+
37
+ collection = Bgg::Collection.find_by_username('texasjdl')
38
+
39
+ expect( collection ).to be_a_kind_of(Bgg::Collection)
40
+ expect( collection.owned.first ).to be_instance_of(Bgg::Collection::Item)
41
+ expect( collection.owned.first.name ).to eq('& Cetera')
42
+ end
43
+ end
44
+
45
+ describe 'instance' do
46
+ let(:collection) { Bgg::Collection.find_by_username('texasjdl') }
47
+
48
+ before do
49
+ response_file = 'sample_data/collection?username=texasjdl'
50
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/collection'
51
+
52
+ stub_request(:any, request_url).
53
+ with(query: {username: 'texasjdl'}).
54
+ to_return(body: File.open(response_file), status: 200)
55
+ end
56
+
57
+ it 'has boardgames' do
58
+ expect( collection.boardgames ).to be_instance_of(Array)
59
+ expect( collection.boardgames.first ).to be_instance_of(Bgg::Collection::Item)
60
+ expect( collection.boardgames.count).to eq(604)
61
+ end
62
+
63
+ it 'has boardgame_expansions' do
64
+ expect( collection.boardgame_expansions ).to be_instance_of(Array)
65
+ expect( collection.boardgame_expansions.first ).to be_instance_of(Bgg::Collection::Item)
66
+ expect( collection.boardgame_expansions.count).to eq(37)
67
+ end
68
+
69
+ it 'has played' do
70
+ expect( collection.played ).to be_instance_of(Array)
71
+ expect( collection.played.first ).to be_instance_of(Bgg::Collection::Item)
72
+ expect( collection.played.count).to eq(365)
73
+ end
74
+
75
+ it 'has size' do
76
+ expect( collection.size ).to eq(604)
77
+ end
78
+
79
+ it 'has count' do
80
+ expect( collection.count ).to eq(604)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,232 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Bgg::Game do
5
+ describe 'class method' do
6
+ describe 'find_by_id' do
7
+ it 'throws an ArgumentError when a non-integer is passed in' do
8
+ expect{ Bgg::Game.find_by_id('string instead') }.to raise_error(ArgumentError, 'invalid value for Integer(): "string instead"')
9
+ end
10
+
11
+ it 'throws an ArgumentError when a non-positive integer is passed in' do
12
+ expect{ Bgg::Game.find_by_id(0) }.to raise_error(ArgumentError, 'game_id must be greater than 0!')
13
+ expect{ Bgg::Game.find_by_id(-1) }.to raise_error(ArgumentError, 'game_id must be greater than 0!')
14
+ end
15
+
16
+ it 'creates an object for a game that exists' do
17
+ response_file = 'sample_data/thing?id=84876&type=boardgame'
18
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/thing'
19
+
20
+ stub_request(:any, request_url).with(query: {id: 84876, type: 'boardgame'}).to_return(body: File.open(response_file), status: 200)
21
+ burgund = Bgg::Game.find_by_id(84876)
22
+
23
+ expect( burgund ).to be_a_kind_of(Object)
24
+ expect( burgund.name ).to eq('The Castles of Burgundy')
25
+ expect( burgund.names ).to match_array(['The Castles of Burgundy', 'Les Châteaux de Bourgogne', 'Die Burgen von Burgund'])
26
+ end
27
+
28
+ it 'throws an ArgumentError for a game that does not exist' do
29
+ response_file = 'sample_data/thing?id=10000000&type=boardgame'
30
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/thing'
31
+
32
+ stub_request(:any, request_url).with(query: {id: 10000000, type: 'boardgame'}).to_return(body: File.open(response_file), status: 200)
33
+
34
+ expect{ Bgg::Game.find_by_id(10000000) }.to raise_error(ArgumentError, 'Game does not exist')
35
+ end
36
+ end
37
+ end
38
+
39
+ describe 'instance' do
40
+ let(:burgund) { Bgg::Game.find_by_id(84876) }
41
+
42
+ before do
43
+ response_file = 'sample_data/thing?id=84876&type=boardgame'
44
+ request_url = 'http://www.boardgamegeek.com/xmlapi2/thing'
45
+
46
+ stub_request(:any, request_url).
47
+ with(query: {id: 84876, type: 'boardgame'}).
48
+ to_return(body: File.open(response_file), status: 200)
49
+ end
50
+
51
+ describe '.id' do
52
+ it 'exists' do
53
+ expect( burgund ).to respond_to(:id)
54
+ end
55
+
56
+ it 'returns the BGG Thing id' do
57
+ expect( burgund.id ).to eq(84876)
58
+ end
59
+ end
60
+
61
+ describe '.name' do
62
+ it 'exists' do
63
+ expect( burgund ).to respond_to(:name)
64
+ end
65
+
66
+ it 'returns the primary name' do
67
+ expect( burgund.name ).to eq('The Castles of Burgundy')
68
+ end
69
+ end
70
+
71
+ describe '.names' do
72
+ it 'exists' do
73
+ expect( burgund ).to respond_to(:names)
74
+ end
75
+
76
+ it 'returns a list of all names -- primary and alternates' do
77
+ expect( burgund.names ).to match_array(['The Castles of Burgundy', 'Les Châteaux de Bourgogne', 'Die Burgen von Burgund'])
78
+ end
79
+ end
80
+
81
+ describe '.alternate_names' do
82
+ it 'exists' do
83
+ expect( burgund ).to respond_to(:alternate_names)
84
+ end
85
+
86
+ it 'returns a list of the alternate/foreign names -- without the primary name' do
87
+ expect( burgund.alternate_names ).to match_array(['Les Châteaux de Bourgogne', 'Die Burgen von Burgund'])
88
+ end
89
+ end
90
+
91
+ describe '.artists' do
92
+ it 'exists' do
93
+ expect( burgund ).to respond_to(:artists)
94
+ end
95
+
96
+ it 'returns a list of the game artists' do
97
+ expect( burgund.artists ).to match_array(['Harald Lieske', 'Julien Delval'])
98
+ end
99
+ end
100
+
101
+ describe '.description' do
102
+ it 'exists' do
103
+ expect( burgund ).to respond_to(:description)
104
+ end
105
+
106
+ it 'returns the text description of the game' do
107
+ expect( burgund.description ).to match(/The game is set in the Burgundy region of High Medieval France\./)
108
+ expect( burgund.description.length ).to eq(1049)
109
+ end
110
+ end
111
+
112
+ describe '.designers' do
113
+ it 'exists' do
114
+ expect( burgund ).to respond_to(:designers)
115
+ end
116
+
117
+ it 'returns a list of the designers' do
118
+ expect( burgund.designers ).to match_array(['Stefan Feld'])
119
+ end
120
+ end
121
+
122
+ describe '.image' do
123
+ it 'exists' do
124
+ expect( burgund ).to respond_to(:image)
125
+ end
126
+
127
+ it 'returns a URL to an image for the game' do
128
+ expect( burgund.image ).to eq('http://cf.geekdo-images.com/images/pic1176894.jpg')
129
+ end
130
+ end
131
+
132
+ describe '.min_players' do
133
+ it 'exists' do
134
+ expect( burgund ).to respond_to(:min_players)
135
+ end
136
+
137
+ it 'returns the minimum number of players' do
138
+ expect( burgund.min_players ).to eq(2)
139
+ end
140
+ end
141
+
142
+ describe '.max_players' do
143
+ it 'exists' do
144
+ expect( burgund ).to respond_to(:max_players)
145
+ end
146
+
147
+ it 'returns the maximum number of players' do
148
+ expect( burgund.max_players ).to eq(4)
149
+ end
150
+ end
151
+
152
+ describe '.minimum_recommended_age' do
153
+ it 'exists' do
154
+ expect( burgund ).to respond_to(:recommended_minimum_age)
155
+ end
156
+
157
+ it 'returns the recommended minimum age' do
158
+ expect( burgund.recommended_minimum_age ).to eq(12)
159
+ end
160
+ end
161
+
162
+ describe '.playing_time' do
163
+ it 'exists' do
164
+ expect( burgund ).to respond_to(:playing_time)
165
+ end
166
+
167
+ it 'has playing_time' do
168
+ expect( burgund.playing_time ).to eq(90)
169
+ end
170
+ end
171
+
172
+ describe '.publishers' do
173
+ it 'exists' do
174
+ expect( burgund ).to respond_to(:publishers)
175
+ end
176
+
177
+ it 'returns a list of publisher names' do
178
+ expect( burgund.publishers ).to match_array(['Ravensburger', 'alea'])
179
+ end
180
+ end
181
+
182
+ describe '.thumbnail' do
183
+ it 'exists' do
184
+ expect( burgund ).to respond_to(:thumbnail)
185
+ end
186
+
187
+ it 'returns a URL to a thumbnail' do
188
+ expect( burgund.thumbnail ).to eq('http://cf.geekdo-images.com/images/pic1176894_t.jpg')
189
+ end
190
+ end
191
+
192
+ describe '.year_published' do
193
+ it 'exists' do
194
+ expect( burgund ).to respond_to(:year_published)
195
+ end
196
+
197
+ it 'returns the only year published' do
198
+ expect( burgund.year_published ).to eq(2011)
199
+ end
200
+ end
201
+
202
+ describe '.mechanics' do
203
+ it 'exists' do
204
+ expect( burgund ).to respond_to(:mechanics)
205
+ end
206
+
207
+ it 'returns the mechanisms used in the game' do
208
+ expect( burgund.mechanics ).to match_array(['Dice Rolling', 'Set Collection', 'Tile Placement'])
209
+ end
210
+ end
211
+
212
+ describe '.categories' do
213
+ it 'exists' do
214
+ expect( burgund ).to respond_to(:categories)
215
+ end
216
+
217
+ it 'returns the minimum number of players' do
218
+ expect( burgund.categories ).to match_array(['Dice', 'Medieval', 'Territory Building'])
219
+ end
220
+ end
221
+
222
+ describe '.families' do
223
+ it 'exists' do
224
+ expect( burgund ).to respond_to(:families)
225
+ end
226
+
227
+ it 'returns the minimum number of players' do
228
+ expect( burgund.families ).to match_array(['Alea Big Box', 'Country: France'])
229
+ end
230
+ end
231
+ end
232
+ end