buntine-discogs 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README +61 -0
  2. data/Rakefile +27 -0
  3. data/discogs.gemspec +19 -0
  4. data/lib/discogs.rb +10 -0
  5. data/lib/wrapper/resource.rb +75 -0
  6. data/lib/wrapper/resource_mappings.rb +80 -0
  7. data/lib/wrapper/resources/artist.rb +16 -0
  8. data/lib/wrapper/resources/artist_release.rb +16 -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 +17 -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 +88 -0
  21. data/spec/resource_spec.rb +27 -0
  22. data/spec/resources/artist_release_spec.rb +55 -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 +35 -0
  36. data/spec/wrapper_methods/get_artist_spec.rb +95 -0
  37. data/spec/wrapper_methods/get_label_spec.rb +91 -0
  38. data/spec/wrapper_methods/get_release_spec.rb +125 -0
  39. data/spec/wrapper_methods/search_spec.rb +99 -0
  40. data/spec/wrapper_spec.rb +100 -0
  41. metadata +93 -0
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Label do
4
+
5
+ it "should map to empty array" do
6
+ Discogs::Label.element_names.should == []
7
+ end
8
+
9
+ it "should map plural to empty array" do
10
+ Discogs::Label.plural_element_names.should == []
11
+ end
12
+
13
+ ## See ./spec/wrapper_methods/get_label_spec.rb for extensive tests of this class.
14
+
15
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Release::Artist do
4
+
5
+ it "should map to artist" do
6
+ Discogs::Release::Artist.element_names.should == [ :artist ]
7
+ end
8
+
9
+ it "should map to plural artists and extraartists" do
10
+ Discogs::Release::Artist.plural_element_names.should == [ :artists, :extraartists ]
11
+ end
12
+
13
+ describe "when asking for release-artist information" do
14
+
15
+ before do
16
+ data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_release_artist.xml"))
17
+ @release_artist = Discogs::Release::Artist.new(data)
18
+ @release_artist.build!
19
+ end
20
+
21
+ it "should have a name attribute" do
22
+ @release_artist.name.should == "Master's Hammer"
23
+ end
24
+
25
+ it "should have a role attribute" do
26
+ @release_artist.role.should == "Shrieks"
27
+ end
28
+
29
+ it "should have a join attribute" do
30
+ @release_artist.join.should == "Relatives"
31
+ end
32
+
33
+ it "should have an anv attribute" do
34
+ @release_artist.anv.should == "wtf?"
35
+ end
36
+
37
+ it "should have a tracks attribute" do
38
+ @release_artist.tracks.should == "1,2,4"
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Release::Label do
4
+
5
+ it "should map to label" do
6
+ Discogs::Release::Label.element_names.should == [ :label ]
7
+ end
8
+
9
+ it "should map to plural labels" do
10
+ Discogs::Release::Label.plural_element_names.should == [ :labels ]
11
+ end
12
+
13
+ describe "when asking for release-label information" do
14
+
15
+ before do
16
+ data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_release_label.xml"))
17
+ @release_label = Discogs::Release::Label.new(data)
18
+ @release_label.build!
19
+ end
20
+
21
+ it "should have a name attribute" do
22
+ @release_label.name.should == "Toxic Diffusion"
23
+ end
24
+
25
+ it "should have a catno attribute" do
26
+ @release_label.catno.should == "clp89"
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Release do
4
+
5
+ it "should map to empty array" do
6
+ Discogs::Release.element_names.should == []
7
+ end
8
+
9
+ it "should map plural to empty array" do
10
+ Discogs::Release.plural_element_names.should == []
11
+ end
12
+
13
+ ## See ./spec/wrapper_methods/get_release_spec.rb for extensive tests of this class.
14
+
15
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Search::Result do
4
+
5
+ it "should map to result" do
6
+ Discogs::Search::Result.element_names.should == [ :result ]
7
+ end
8
+
9
+ it "should map to plural exactresults and searchresults" do
10
+ Discogs::Search::Result.plural_element_names.should == [ :exactresults, :searchresults ]
11
+ end
12
+
13
+ describe "when asking for search result information" do
14
+
15
+ before do
16
+ data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_search_result.xml"))
17
+ @search_result = Discogs::Search::Result.new(data)
18
+ @search_result.build!
19
+ end
20
+
21
+ it "should have a number attribute" do
22
+ @search_result.num.should == "2"
23
+ end
24
+
25
+ it "should have a type attribute" do
26
+ @search_result.type.should == "artist"
27
+ end
28
+
29
+ it "should have a title attribute" do
30
+ @search_result.title.should == "Karin Slaughter"
31
+ end
32
+
33
+ it "should have a uri attribute" do
34
+ @search_result.uri.should == "http://www.discogs.com/artist/Karin+Slaughter"
35
+ end
36
+
37
+ it "should have a summary attribute" do
38
+ @search_result.summary.should == "Karin Slaughter Karin Slaughter"
39
+ end
40
+
41
+ it "should have a anv attribute" do
42
+ @search_result.anv.should == "Slaughter"
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Search do
4
+
5
+ it "should map to empty array" do
6
+ Discogs::Search.element_names.should == []
7
+ end
8
+
9
+ it "should map plural to empty array" do
10
+ Discogs::Search.plural_element_names.should == []
11
+ end
12
+
13
+ ## See ./spec/wrapper_methods/search_spec.rb for extensive tests of this class.
14
+
15
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Release::Track do
4
+
5
+ it "should map to track" do
6
+ Discogs::Release::Track.element_names.should == [ :track ]
7
+ end
8
+
9
+ it "should map to plural tracklist" do
10
+ Discogs::Release::Track.plural_element_names.should == [ :tracklist ]
11
+ end
12
+
13
+ describe "when asking for track information" do
14
+
15
+ before do
16
+ data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_track.xml"))
17
+ @track = Discogs::Release::Track.new(data)
18
+ @track.build!
19
+ end
20
+
21
+ it "should have a title attribute" do
22
+ @track.title.should == "A dark forest spreads all around"
23
+ end
24
+
25
+ it "should have a duration attribute" do
26
+ @track.duration.should == "7:31"
27
+ end
28
+
29
+ it "should have a position attribute" do
30
+ @track.position.should == "2"
31
+ end
32
+
33
+ it "should have an array of artists" do
34
+ @track.artists.should be_instance_of(Array)
35
+ end
36
+
37
+ it "should have an array of extra artists" do
38
+ @track.extraartists.should be_instance_of(Array)
39
+ end
40
+
41
+ it "should have built each artist" do
42
+ @track.artists[0].should be_instance_of(Discogs::Release::Track::Artist)
43
+
44
+ @track.artists[0].name.should == "Master's Hammer"
45
+ end
46
+
47
+ it "should have built each extra artist" do
48
+ @track.extraartists[0].should be_instance_of(Discogs::Release::Track::Artist)
49
+
50
+ @track.extraartists[0].name.should == "Root"
51
+ @track.extraartists[0].role.should == "Imagery"
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.dirname(__FILE__) + '/../lib/discogs'
4
+
5
+ def valid_release_xml
6
+ data = File.read(File.join(File.dirname(__FILE__), "samples", "valid_release.xml"))
7
+ data.gsub /\n/, ''
8
+ end
9
+
10
+ def valid_artist_xml
11
+ data = File.read(File.join(File.dirname(__FILE__), "samples", "valid_artist.xml"))
12
+ data.gsub /\n/, ''
13
+ end
14
+
15
+ def valid_label_xml
16
+ data = File.read(File.join(File.dirname(__FILE__), "samples", "valid_label.xml"))
17
+ data.gsub /\n/, ''
18
+ end
19
+
20
+ def valid_search_xml
21
+ data = File.read(File.join(File.dirname(__FILE__), "samples", "valid_search_results.xml"))
22
+ data.gsub /\n/, ''
23
+ end
24
+
25
+ def sample_valid_binary
26
+ "\037\213\b\000\325\3054J\002\377\265T\337O\3330\020\376W,?L\233D\353\004(\203\315\215D\3304\020T\233V\006\017\323\036\214}4\036\211\035l\207\222\377~\227_U\v\025C\232\366\344\273\363\335\227/\337\335\231;\360%\361A\204)\265w\224<\200\363\332\232)\215\307\021%\016\356+\360\301\243K\023\356 \a\341\201h\205\376\036m\253*\274;\226\022\312\000\nSt!\026\340\373\223d\240\027\031\002\037D\210\025\352\022\246\324\203\264F\tWSR9=\245Y\b\345\a\306\226\313\345Xi/\355\302\217\245-X\213\303\276\217\342\275Q\034\037\306\373\321\321\321d2\376]\302\242\255\213'\321\337K'\321\326\362\245V!\3539\261\377\302\3640\376'\246\253\362'L;QP\\\341\202\306\246\fF\302\215( \231Ykd\246s\345\300p\326\2068\353R\223\301\300\232\240C\016I\n5\266\201\\\330\a\340\254\v\361\\\334@\216\031\355I\244\b\306N\351\247\375\213x7\212\336S\322 \242\017P\356_\350[\240\004\305cC\r<\006'\266\363:\267\372F\aK\336\210\242\374HR{W\r\354\234E&_C\006\216\374\234\227\332\351P\211\\\207\372\027g\355\325\300\372\311\217\236[Wo@\\Y)r\377r\321I\346\264'_\234\330,\275\306\217\0060\243\264\336!\337\234U\225\004\267Cf\372\021\024I1\365\t\017\266\371\237\267\326\025\242iDg\364\022]iS\347\224\334\207\272[\e\005^:]\006\\+L]\363\222x\227r\266\036\330\3600\231u\300+\003C\v0\270\262\375\231|\316A\006g\215\226\234\2657\230:d\370P\347Mf{&\227 3c9\353\274>\330t\223\234\332\312\343\024\364\027\335\211e\322V&\270:\3711\347l\260\207'@%8\023\321(:\034E\021\212\324\275\v\n\a\321\006\374b/\352\016);E\025\0218kE+*\376\020\312\213\356Lx\217o\005\231U^K\3626\235\235\275\ecW[\000\216\303$\357r\034r\234\327\306Lxi\275n\024L\216c\316V\316\v\323\254*'\232\202vL{\220gX\273\317\261\25630\344\004[%5\352BR|\257\n\360\030)\220zX-\313k\340\323-TOA<4\373\331\357\334\253`\266\260<3\270Q\227\031\220y\300\031|\021\216\255\2119\264\n\247\244y\367\223?4\242\342\264\376\005\000\000"
27
+ end
28
+
29
+ def sample_invalid_data
30
+ <<-EOF
31
+ <resp requests="2" stat="fail">
32
+ <error>Missing or invalid API Key</error>
33
+ </resp>
34
+ EOF
35
+ end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_key")
7
+ @artist_name = "Root"
8
+ end
9
+
10
+ describe "when asking for artist information" do
11
+
12
+ before do
13
+ @http_request = mock(Net::HTTP)
14
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_artist_xml)
15
+ @http_response_as_file = mock(StringIO, :read => valid_artist_xml)
16
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
+ @http_session = mock("HTTP Session")
18
+ @http_session.should_receive(:request).and_return(@http_response)
19
+ @http_request.should_receive(:start).and_yield(@http_session)
20
+ Net::HTTP.should_receive(:new).and_return(@http_request)
21
+
22
+ @artist = @wrapper.get_artist(@artist_name)
23
+ end
24
+
25
+ describe "when calling simple artist attributes" do
26
+
27
+ it "should have a name attribute" do
28
+ @artist.name.should == "Root"
29
+ end
30
+
31
+ it "should have a realname attribute" do
32
+ @artist.realname.should == "Rootan"
33
+ end
34
+
35
+ it "should have one or more aliases" do
36
+ @artist.aliases.should be_instance_of(Array)
37
+ @artist.aliases[0].should == "Roooot"
38
+ end
39
+
40
+ it "should have one or more name variations" do
41
+ @artist.namevariations.should be_instance_of(Array)
42
+ @artist.namevariations[0].should == "Rootan"
43
+ end
44
+
45
+ it "should have one or more members" do
46
+ @artist.members.should be_instance_of(Array)
47
+ @artist.members[0].should == "Big Boss"
48
+ end
49
+
50
+ end
51
+
52
+ describe "when calling complex artist attributes" do
53
+
54
+ it "should have a traversible list of URLs" do
55
+ @artist.urls.should be_instance_of(Array)
56
+ @artist.urls[0].should == "http://www.root.net"
57
+ @artist.urls[1].should == "http://www.rootan.com"
58
+ end
59
+
60
+ it "should have a traversible list of images" do
61
+ @artist.images.should be_instance_of(Array)
62
+ @artist.images[0].should be_instance_of(Discogs::Image)
63
+ end
64
+
65
+ it "should have specifications for each image" do
66
+ specs = [ [ '350', '240', 'secondary' ], [ '222', '226', 'secondary' ], [ '600', '600', 'primary' ] ]
67
+ @artist.images.each_with_index do |image, index|
68
+ image.width.should == specs[index][0]
69
+ image.height.should == specs[index][1]
70
+ image.type.should == specs[index][2]
71
+ end
72
+ end
73
+
74
+ it "should have a traversible list of releases" do
75
+ @artist.releases.should be_instance_of(Array)
76
+ @artist.releases[0].should be_instance_of(Discogs::Artist::Release)
77
+ end
78
+
79
+ it "should have an ID for the first release" do
80
+ @artist.releases[0].id.should == "1805661"
81
+ end
82
+
83
+ it "should have a year for the first release" do
84
+ @artist.releases[0].year.should == "1991"
85
+ end
86
+
87
+ it "should have a label for the third release" do
88
+ @artist.releases[2].label.should == "Apollo"
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_key")
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_session = mock("HTTP Session")
18
+ @http_session.should_receive(:request).and_return(@http_response)
19
+ @http_request.should_receive(:start).and_yield(@http_session)
20
+ Net::HTTP.should_receive(:new).and_return(@http_request)
21
+
22
+ @label = @wrapper.get_label(@label_name)
23
+ end
24
+
25
+ describe "when calling simple label attributes" do
26
+
27
+ it "should have a name attribute" do
28
+ @label.name.should == "Sombre Records"
29
+ end
30
+
31
+ it "should have a contact info attribute" do
32
+ @label.contactinfo.should == "Unknown, Germany"
33
+ end
34
+
35
+ it "should have a profile attribute" do
36
+ @label.profile.should == "Released some OK LPs"
37
+ end
38
+
39
+ it "should have a parent label attribute" do
40
+ @label.parentlabel.should == "SuperSombre"
41
+ end
42
+
43
+ it "should have one or more URLs" do
44
+ @label.urls.should be_instance_of(Array)
45
+ @label.urls[0].should == "http://www.sombrerecords.com"
46
+ @label.urls[1].should == "http://www.discogs.com/label/Sombre+Records"
47
+ end
48
+
49
+ end
50
+
51
+ describe "when calling complex artist attributes" do
52
+
53
+ it "should have a traversible list of images" do
54
+ @label.images.should be_instance_of(Array)
55
+ @label.images[0].should be_instance_of(Discogs::Image)
56
+ end
57
+
58
+ it "should have a traversible list of sub-labels" do
59
+ @label.sublabels.should be_instance_of(Array)
60
+ @label.sublabels[0].should == "SubSombre"
61
+ @label.sublabels[1].should == "Sony BMG"
62
+ end
63
+
64
+ it "should have specifications for each image" do
65
+ specs = [ [ '400', '300', 'primary' ], [ '450', '350', 'secondary' ] ]
66
+
67
+ @label.images.each_with_index do |image, index|
68
+ image.width.should == specs[index][0]
69
+ image.height.should == specs[index][1]
70
+ image.type.should == specs[index][2]
71
+ end
72
+ end
73
+
74
+ it "should have a traversible list of releases" do
75
+ @label.releases.should be_instance_of(Array)
76
+ @label.releases[0].should be_instance_of(Discogs::Label::Release)
77
+ end
78
+
79
+ it "should have a catno for the first release" do
80
+ @label.releases[0].catno.should == "SMB01"
81
+ end
82
+
83
+ it "should have an artist name for the second release" do
84
+ @label.releases[1].artist.should == "Moonblood"
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ end