discogs-wrapper 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 (41) hide show
  1. data/README.markdown +81 -0
  2. data/Rakefile +27 -0
  3. data/discogs.gemspec +19 -0
  4. data/lib/discogs.rb +20 -0
  5. data/lib/wrapper/resource.rb +79 -0
  6. data/lib/wrapper/resource_mappings.rb +84 -0
  7. data/lib/wrapper/resources/artist.rb +37 -0
  8. data/lib/wrapper/resources/artist_release.rb +17 -0
  9. data/lib/wrapper/resources/format.rb +11 -0
  10. data/lib/wrapper/resources/generic_list.rb +29 -0
  11. data/lib/wrapper/resources/image.rb +11 -0
  12. data/lib/wrapper/resources/label.rb +16 -0
  13. data/lib/wrapper/resources/label_release.rb +17 -0
  14. data/lib/wrapper/resources/release.rb +22 -0
  15. data/lib/wrapper/resources/release_artist.rb +18 -0
  16. data/lib/wrapper/resources/release_label.rb +10 -0
  17. data/lib/wrapper/resources/search.rb +61 -0
  18. data/lib/wrapper/resources/search_result.rb +16 -0
  19. data/lib/wrapper/resources/track.rb +15 -0
  20. data/lib/wrapper/wrapper.rb +105 -0
  21. data/spec/resource_spec.rb +27 -0
  22. data/spec/resources/artist_release_spec.rb +59 -0
  23. data/spec/resources/artist_spec.rb +15 -0
  24. data/spec/resources/format_spec.rb +41 -0
  25. data/spec/resources/generic_list_spec.rb +66 -0
  26. data/spec/resources/image_spec.rb +43 -0
  27. data/spec/resources/label_release_spec.rb +55 -0
  28. data/spec/resources/label_spec.rb +15 -0
  29. data/spec/resources/release_artist_spec.rb +43 -0
  30. data/spec/resources/release_label_spec.rb +31 -0
  31. data/spec/resources/release_spec.rb +15 -0
  32. data/spec/resources/search_result_spec.rb +47 -0
  33. data/spec/resources/search_spec.rb +15 -0
  34. data/spec/resources/track_spec.rb +56 -0
  35. data/spec/spec_helper.rb +36 -0
  36. data/spec/wrapper_methods/get_artist_spec.rb +109 -0
  37. data/spec/wrapper_methods/get_label_spec.rb +89 -0
  38. data/spec/wrapper_methods/get_release_spec.rb +123 -0
  39. data/spec/wrapper_methods/search_spec.rb +330 -0
  40. data/spec/wrapper_spec.rb +162 -0
  41. metadata +126 -0
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_user_agent")
7
+ @artist_name = "Root"
8
+ end
9
+
10
+ describe "when asking for label information" do
11
+
12
+ before do
13
+ @http_request = mock(Net::HTTP)
14
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_label_xml)
15
+ @http_response_as_file = mock(StringIO, :read => valid_label_xml)
16
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
+ @http_request.should_receive(:start).and_return(@http_response)
18
+ Net::HTTP.should_receive(:new).and_return(@http_request)
19
+
20
+ @label = @wrapper.get_label(@label_name)
21
+ end
22
+
23
+ describe "when calling simple label attributes" do
24
+
25
+ it "should have a name attribute" do
26
+ @label.name.should == "Sombre Records"
27
+ end
28
+
29
+ it "should have a contact info attribute" do
30
+ @label.contactinfo.should == "Unknown, Germany"
31
+ end
32
+
33
+ it "should have a profile attribute" do
34
+ @label.profile.should == "Released some OK LPs"
35
+ end
36
+
37
+ it "should have a parent label attribute" do
38
+ @label.parentlabel.should == "SuperSombre"
39
+ end
40
+
41
+ it "should have one or more URLs" do
42
+ @label.urls.should be_instance_of(Array)
43
+ @label.urls[0].should == "http://www.sombrerecords.com"
44
+ @label.urls[1].should == "http://www.discogs.com/label/Sombre+Records"
45
+ end
46
+
47
+ end
48
+
49
+ describe "when calling complex artist attributes" do
50
+
51
+ it "should have a traversible list of images" do
52
+ @label.images.should be_instance_of(Array)
53
+ @label.images[0].should be_instance_of(Discogs::Image)
54
+ end
55
+
56
+ it "should have a traversible list of sub-labels" do
57
+ @label.sublabels.should be_instance_of(Array)
58
+ @label.sublabels[0].should == "SubSombre"
59
+ @label.sublabels[1].should == "Sony BMG"
60
+ end
61
+
62
+ it "should have specifications for each image" do
63
+ specs = [ [ '400', '300', 'primary' ], [ '450', '350', 'secondary' ] ]
64
+
65
+ @label.images.each_with_index do |image, index|
66
+ image.width.should == specs[index][0]
67
+ image.height.should == specs[index][1]
68
+ image.type.should == specs[index][2]
69
+ end
70
+ end
71
+
72
+ it "should have a traversible list of releases" do
73
+ @label.releases.should be_instance_of(Array)
74
+ @label.releases[0].should be_instance_of(Discogs::Label::Release)
75
+ end
76
+
77
+ it "should have a catno for the first release" do
78
+ @label.releases[0].catno.should == "SMB01"
79
+ end
80
+
81
+ it "should have an artist name for the second release" do
82
+ @label.releases[1].artist.should == "Moonblood"
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,123 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_user_agent")
7
+ @release_id = "666666"
8
+ end
9
+
10
+ describe "when asking for release information" do
11
+
12
+ before do
13
+ @http_request = mock(Net::HTTP)
14
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_release_xml)
15
+ @http_response_as_file = mock(StringIO, :read => valid_release_xml)
16
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
+ @http_request.should_receive(:start).and_return(@http_response)
18
+ Net::HTTP.should_receive(:new).and_return(@http_request)
19
+
20
+ @release = @wrapper.get_release(@release_id)
21
+ end
22
+
23
+ describe "when calling simple release attributes" do
24
+
25
+ it "should have a title attribute" do
26
+ @release.title.should == "Into the Abyss"
27
+ end
28
+
29
+ it "should have an ID attribute" do
30
+ @release.id.should == "666666"
31
+ end
32
+
33
+ it "should have one or more extra artists" do
34
+ @release.extraartists.should be_instance_of(Array)
35
+ @release.extraartists[0].should be_instance_of(Discogs::Release::Artist)
36
+ end
37
+
38
+ it "should have one or more tracks" do
39
+ @release.tracklist.should be_instance_of(Array)
40
+ @release.tracklist[0].should be_instance_of(Discogs::Release::Track)
41
+ end
42
+
43
+ it "should have one or more genres" do
44
+ @release.genres.should be_instance_of(Array)
45
+ @release.genres[0].should == "Heavy Metal"
46
+ end
47
+
48
+ it "should have one or more formats" do
49
+ @release.formats.should be_instance_of(Array)
50
+ @release.formats[0].should be_instance_of(Discogs::Release::Format)
51
+ end
52
+
53
+ it "should have one or more images" do
54
+ @release.images.should be_instance_of(Array)
55
+ @release.images[0].should be_instance_of(Discogs::Image)
56
+ end
57
+
58
+ end
59
+
60
+ describe "when calling complex release attributes" do
61
+
62
+ it "should have a duration for the first track" do
63
+ @release.tracklist[0].duration.should == "8:11"
64
+ end
65
+
66
+ it "should have specifications for each image" do
67
+ specs = [ [ '600', '595', 'primary' ], [ '600', '593', 'secondary' ], [ '600', '539', 'secondary' ], [ '600', '452', 'secondary' ], [ '600', '567', 'secondary' ] ]
68
+ @release.images.each_with_index do |image, index|
69
+ image.width.should == specs[index][0]
70
+ image.height.should == specs[index][1]
71
+ image.type.should == specs[index][2]
72
+ end
73
+ end
74
+
75
+ it "should have a traversible list of styles" do
76
+ @release.styles.should be_instance_of(Array)
77
+ @release.styles[0].should == "Black Metal"
78
+ @release.styles[1].should == "Thrash"
79
+ end
80
+
81
+ it "should have a traversible list of labels" do
82
+ @release.styles.should be_instance_of(Array)
83
+ @release.labels[0].should be_instance_of(Discogs::Release::Label)
84
+ @release.labels[0].catno.should == "Death9"
85
+ @release.labels[0].name.should == "Culted"
86
+ end
87
+
88
+ it "should have a name and quantity for the first format" do
89
+ @release.formats[0].name.should == "CD"
90
+ @release.formats[0].qty.should == "1"
91
+ end
92
+
93
+ it "should have an array of descriptions for the first format" do
94
+ @release.formats[0].descriptions.should be_instance_of(Array)
95
+ @release.formats[0].descriptions[0].should == "Album"
96
+ end
97
+
98
+ it "should have an artist associated to the second track" do
99
+ @release.tracklist[1].artists.should be_instance_of(Array)
100
+ @release.tracklist[1].artists[0].should be_instance_of(Discogs::Release::Track::Artist)
101
+ @release.tracklist[1].artists[0].name.should == "Arakain"
102
+ end
103
+
104
+ it "should have an extra artist associated to the second track" do
105
+ @release.tracklist[1].extraartists.should be_instance_of(Array)
106
+ @release.tracklist[1].extraartists[0].should be_instance_of(Discogs::Release::Track::Artist)
107
+ @release.tracklist[1].extraartists[0].name.should == "Debustrol"
108
+ @release.tracklist[1].extraartists[0].role.should == "Sadism"
109
+ end
110
+
111
+ it "should have a role associated to the first extra artist" do
112
+ @release.extraartists[0].role.should == "Lyrics By"
113
+ end
114
+
115
+ it "should have no artist associated to the third track" do
116
+ @release.tracklist[2].artists.should be_nil
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -0,0 +1,330 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_user_agent")
7
+ @search_term = "slaughter"
8
+ end
9
+
10
+ def mock_search(page)
11
+ @http_request = mock(Net::HTTP)
12
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_search_xml(page))
13
+ @http_response_as_file = mock(StringIO, :read => valid_search_xml(page))
14
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
15
+ @http_request.should_receive(:start).and_return(@http_response)
16
+ Net::HTTP.should_receive(:new).and_return(@http_request)
17
+ end
18
+
19
+ describe "when asking for search result information" do
20
+
21
+ before do
22
+ mock_search(1)
23
+
24
+ @search = @wrapper.search(@search_term)
25
+ end
26
+
27
+ describe "when dealing with page information" do
28
+
29
+ it "should have a current_page method" do
30
+ @search.current_page.should == 1
31
+ end
32
+
33
+ it "should be able to report if this is the last page" do
34
+ @search.last_page?.should be_false
35
+ end
36
+
37
+ end
38
+
39
+ describe "when handling exact results" do
40
+
41
+ it "should have the exact results stored as an array" do
42
+ @search.exactresults.should be_instance_of(Array)
43
+ end
44
+
45
+ it "should be stored as result objects" do
46
+ @search.exactresults.each do |result|
47
+ result.should be_instance_of(Discogs::Search::Result)
48
+ end
49
+ end
50
+
51
+ it "should have a incrementing num for each exact result" do
52
+ @search.exactresults.each_with_index do |result, index|
53
+ result.num.should == (index + 1).to_s
54
+ end
55
+ end
56
+
57
+ it "should have a type for the first result" do
58
+ @search.exactresults[0].type.should == "artist"
59
+ end
60
+
61
+ it "should have an anv for the fifth result" do
62
+ @search.exactresults[5].anv.should == "Slaughter"
63
+ end
64
+
65
+ it "should be able to filter all non-artists from exact results" do
66
+ @search.exact(:artist).should be_instance_of(Array)
67
+ @search.exact(:artist).length.should == 6
68
+ end
69
+
70
+ it "should be able to filter all non-releases from exact results" do
71
+ @search.exact(:release).should be_instance_of(Array)
72
+ @search.exact(:release).length.should == 1
73
+ end
74
+
75
+ it "should be able to filter all non-labels from exact results" do
76
+ @search.exact(:label).should be_instance_of(Array)
77
+ @search.exact(:label).length.should == 1
78
+ end
79
+
80
+ it "should return an empty array on a junk filter" do
81
+ @search.exact(:cheesecake).should be_instance_of(Array)
82
+ @search.exact(:cheesecake).should be_empty
83
+ end
84
+
85
+ it "should simply return all exact results without a filter" do
86
+ @search.exact.should be_instance_of(Array)
87
+ @search.exact.length.should == 8
88
+ end
89
+
90
+ it "should have a shortcut for accessing the first exact artist" do
91
+ @search.closest(:artist).should be_instance_of(Discogs::Search::Result)
92
+ @search.closest(:artist).should == @search.exact(:artist)[0]
93
+ end
94
+
95
+ it "should have a shortcut for accessing the first exact release" do
96
+ @search.closest(:release).should be_instance_of(Discogs::Search::Result)
97
+ @search.closest(:release).should == @search.exact(:release)[0]
98
+ end
99
+
100
+ it "should have a shortcut for accessing the first exact label" do
101
+ @search.closest(:label).should be_instance_of(Discogs::Search::Result)
102
+ @search.closest(:label).should == @search.exact(:label)[0]
103
+ end
104
+
105
+ it "should return nil on junk filter for closest match" do
106
+ @search.closest(:alcoholic).should be_nil
107
+ end
108
+
109
+ end
110
+
111
+ describe "when handling search results" do
112
+
113
+ it "should have a start attribute" do
114
+ @search.start.should == "1"
115
+ end
116
+
117
+ it "should have an end attribute" do
118
+ @search.end.should == "20"
119
+ end
120
+
121
+ it "should have number of results attribute" do
122
+ @search.total_results.should == 1846
123
+ end
124
+
125
+ it "should have number of pages attribute" do
126
+ @search.total_pages.should == 93
127
+ end
128
+
129
+ it "should have the search results stored as an array" do
130
+ @search.searchresults.should be_instance_of(Array)
131
+ end
132
+
133
+ it "should be stored as result objects" do
134
+ @search.searchresults.each do |result|
135
+ result.should be_instance_of(Discogs::Search::Result)
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ describe "when handling search results" do
142
+
143
+ it "should have a start attribute" do
144
+ @search.start.should == "1"
145
+ end
146
+
147
+ it "should have an end attribute" do
148
+ @search.end.should == "20"
149
+ end
150
+
151
+ it "should have number of results attribute" do
152
+ @search.total_results.should == 1846
153
+ end
154
+
155
+ it "should have number of pages attribute" do
156
+ @search.total_pages.should == 93
157
+ end
158
+
159
+ it "should have the search results stored as an array" do
160
+ @search.searchresults.should be_instance_of(Array)
161
+ end
162
+
163
+ it "should be stored as result objects" do
164
+ @search.searchresults.each do |result|
165
+ result.should be_instance_of(Discogs::Search::Result)
166
+ end
167
+ end
168
+
169
+ end
170
+
171
+ describe "when handling search results" do
172
+
173
+ it "should have a start attribute" do
174
+ @search.start.should == "1"
175
+ end
176
+
177
+ it "should have an end attribute" do
178
+ @search.end.should == "20"
179
+ end
180
+
181
+ it "should have number of results attribute" do
182
+ @search.total_results.should == 1846
183
+ end
184
+
185
+ it "should have number of pages attribute" do
186
+ @search.total_pages.should == 93
187
+ end
188
+
189
+ it "should have the search results stored as an array" do
190
+ @search.searchresults.should be_instance_of(Array)
191
+ end
192
+
193
+ it "should be stored as result objects" do
194
+ @search.searchresults.each do |result|
195
+ result.should be_instance_of(Discogs::Search::Result)
196
+ end
197
+ end
198
+
199
+ it "should have a incrementing num for each search result" do
200
+ @search.searchresults.each_with_index do |result, index|
201
+ result.num.should == (index + 1).to_s
202
+ end
203
+ end
204
+
205
+ it "should have a type for the third result" do
206
+ @search.searchresults[2].type.should == "label"
207
+ end
208
+
209
+ it "should have a title for the fourth result" do
210
+ @search.searchresults[3].title.should == "Satanic Slaughter"
211
+ end
212
+
213
+ it "should have a summary for the sixth result" do
214
+ @search.searchresults[5].summary.should == "Gary Slaughter"
215
+ end
216
+
217
+ it "should be able to filter all non-artists from extended results" do
218
+ @search.results(:artist).should be_instance_of(Array)
219
+ @search.results(:artist).length.should == 12
220
+ end
221
+
222
+ it "should be able to filter all non-releases from extended results" do
223
+ @search.results(:release).should be_instance_of(Array)
224
+ @search.results(:release).length.should == 6
225
+ end
226
+
227
+ it "should be able to filter all non-labels from extended results" do
228
+ @search.results(:label).should be_instance_of(Array)
229
+ @search.results(:label).length.should == 2
230
+ end
231
+
232
+ it "should return an empty array on a junk filter" do
233
+ @search.results(:cheesecake).should be_instance_of(Array)
234
+ @search.results(:cheesecake).should be_empty
235
+ end
236
+
237
+ it "should simply return all extended results without a filter" do
238
+ @search.results.should be_instance_of(Array)
239
+ @search.results.length.should == 20
240
+ end
241
+
242
+ end
243
+
244
+ end
245
+
246
+ describe "when getting the next page" do
247
+
248
+ before do
249
+ mock_search(2)
250
+
251
+ @search = @wrapper.search(@search_term, :page => 2)
252
+ end
253
+
254
+ describe "when dealing with page information" do
255
+
256
+ it "should have a current_page method" do
257
+ @search.current_page.should == 2
258
+ end
259
+
260
+ it "should be able to report if this is the last page" do
261
+ @search.last_page?.should be_false
262
+ end
263
+
264
+ end
265
+
266
+ describe "when handling exact results" do
267
+
268
+ it "should not have any exact results" do
269
+ @search.exactresults.should be_nil
270
+ end
271
+
272
+ it "should return empty array for exact filtering" do
273
+ @search.exact.should == []
274
+ end
275
+
276
+ it "should still allow filtering and return an empty array" do
277
+ @search.exact(:artist).should == []
278
+ end
279
+
280
+ it "should return nil for closest matches when no exact results are available" do
281
+ @search.closest(:artist).should be_nil
282
+ @search.closest(:release).should be_nil
283
+ @search.closest(:label).should be_nil
284
+ end
285
+
286
+ it "should return nil on junk filter for closest match" do
287
+ @search.closest(:alcoholic).should be_nil
288
+ end
289
+
290
+ end
291
+
292
+ describe "when handling search results" do
293
+
294
+ it "should have a start attribute" do
295
+ @search.start.should == "21"
296
+ end
297
+
298
+ it "should have an end attribute" do
299
+ @search.end.should == "40"
300
+ end
301
+
302
+ it "should have number of results attribute" do
303
+ @search.total_results.should == 1846
304
+ end
305
+
306
+ it "should have number of pages attribute (still)" do
307
+ @search.total_pages.should == 93
308
+ end
309
+
310
+ it "should have the search results stored as an array" do
311
+ @search.searchresults.should be_instance_of(Array)
312
+ end
313
+
314
+ it "should be stored as result objects" do
315
+ @search.searchresults.each do |result|
316
+ result.should be_instance_of(Discogs::Search::Result)
317
+ end
318
+ end
319
+
320
+ it "should have a incrementing num for each search result" do
321
+ @search.searchresults.each_with_index do |result, index|
322
+ result.num.should == (index + 21).to_s
323
+ end
324
+ end
325
+
326
+ end
327
+
328
+ end
329
+
330
+ end