discogs-wrapper 1.0.0

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.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,43 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Image do
4
+
5
+ it "should map to image" do
6
+ Discogs::Image.element_names.should == [ :image ]
7
+ end
8
+
9
+ it "should map to plural images" do
10
+ Discogs::Image.plural_element_names.should == [ :images ]
11
+ end
12
+
13
+ describe "when asking for image information" do
14
+
15
+ before do
16
+ data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_image.xml"))
17
+ @image = Discogs::Image.new(data)
18
+ @image.build!
19
+ end
20
+
21
+ it "should have a type attribute" do
22
+ @image.type.should == "primary"
23
+ end
24
+
25
+ it "should have a width attribute" do
26
+ @image.width.should == "600"
27
+ end
28
+
29
+ it "should have a height attribute" do
30
+ @image.height.should == "595"
31
+ end
32
+
33
+ it "should have a uri attribute" do
34
+ @image.uri.should == "http://www.discogs.com/image/R-666-1222413500.jpeg"
35
+ end
36
+
37
+ it "should have a uri150 attribute" do
38
+ @image.uri150.should == "http://www.discogs.com/image/R-150-666-1222413500.jpeg"
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Label::Release do
4
+
5
+ it "should map to release" do
6
+ Discogs::Label::Release.element_names.should == [ :release ]
7
+ end
8
+
9
+ it "should map to plural releases" do
10
+ Discogs::Label::Release.plural_element_names.should == [ :releases ]
11
+ end
12
+
13
+ describe "when asking for label-release information" do
14
+
15
+ before do
16
+ data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_label_release.xml"))
17
+ @label_release = Discogs::Label::Release.new(data)
18
+ @label_release.build!
19
+ end
20
+
21
+ it "should have a ID attribute" do
22
+ @label_release.id.should == "116322"
23
+ end
24
+
25
+ it "should have a status attribute" do
26
+ @label_release.status.should == "Accepted"
27
+ end
28
+
29
+ it "should have a catno attribute" do
30
+ @label_release.catno.should == "SMB09"
31
+ end
32
+
33
+ it "should have an artist attribute" do
34
+ @label_release.artist.should == "Morrior"
35
+ end
36
+
37
+ it "should have a title attribute" do
38
+ @label_release.title.should == "Death Metal Session"
39
+ end
40
+
41
+ it "should have a format attribute" do
42
+ @label_release.format.should == "12\""
43
+ end
44
+
45
+ it "should have a year attribute" do
46
+ @label_release.year.should == "1991"
47
+ end
48
+
49
+ it "should have a trackinfo attribute" do
50
+ @label_release.trackinfo.should == "Side A, track 4"
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -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,36 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.dirname(__FILE__) + '/../lib/discogs'
4
+
5
+ def valid_release_xml
6
+ read_sample "valid_release.xml"
7
+ end
8
+
9
+ def valid_artist_xml
10
+ read_sample "valid_artist.xml"
11
+ end
12
+
13
+ def valid_label_xml
14
+ read_sample "valid_label.xml"
15
+ end
16
+
17
+ def valid_search_xml(page=1)
18
+ read_sample "valid_search_results_#{page}.xml"
19
+ end
20
+
21
+ def read_sample(filename)
22
+ data = File.read(File.join(File.dirname(__FILE__), "samples", filename))
23
+ data.gsub /\n/, ''
24
+ end
25
+
26
+ def sample_valid_binary
27
+ "\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"
28
+ end
29
+
30
+ def sample_invalid_data
31
+ <<-EOF
32
+ <resp requests="2" stat="fail">
33
+ <error>Missing or invalid User agent</error>
34
+ </resp>
35
+ EOF
36
+ end
@@ -0,0 +1,109 @@
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 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_request.should_receive(:start).and_return(@http_response)
18
+ Net::HTTP.should_receive(:new).and_return(@http_request)
19
+
20
+ @artist = @wrapper.get_artist(@artist_name)
21
+ end
22
+
23
+ describe "when calling simple artist attributes" do
24
+
25
+ it "should have a name attribute" do
26
+ @artist.name.should == "Root"
27
+ end
28
+
29
+ it "should have a realname attribute" do
30
+ @artist.realname.should == "Rootan"
31
+ end
32
+
33
+ it "should have one or more aliases" do
34
+ @artist.aliases.should be_instance_of(Array)
35
+ @artist.aliases[0].should == "Roooot"
36
+ end
37
+
38
+ it "should have one or more name variations" do
39
+ @artist.namevariations.should be_instance_of(Array)
40
+ @artist.namevariations[0].should == "Rootan"
41
+ end
42
+
43
+ it "should have one or more members" do
44
+ @artist.members.should be_instance_of(Array)
45
+ @artist.members[0].should == "Big Boss"
46
+ end
47
+
48
+ it "should be able to filter non-main releases" do
49
+ @artist.main_releases.should be_instance_of(Array)
50
+ @artist.main_releases.length.should == 4
51
+ end
52
+
53
+ it "should be able to filter non-bootleg releases" do
54
+ @artist.bootlegs.should be_instance_of(Array)
55
+ @artist.bootlegs.length.should == 1
56
+ end
57
+
58
+ it "should be able to filter non-main releases" do
59
+ @artist.appearances.should be_instance_of(Array)
60
+ @artist.appearances.length.should == 1
61
+ end
62
+
63
+ end
64
+
65
+ describe "when calling complex artist attributes" do
66
+
67
+ it "should have a traversible list of URLs" do
68
+ @artist.urls.should be_instance_of(Array)
69
+ @artist.urls[0].should == "http://www.root.net"
70
+ @artist.urls[1].should == "http://www.rootan.com"
71
+ end
72
+
73
+ it "should have a traversible list of images" do
74
+ @artist.images.should be_instance_of(Array)
75
+ @artist.images[0].should be_instance_of(Discogs::Image)
76
+ end
77
+
78
+ it "should have specifications for each image" do
79
+ specs = [ [ '350', '240', 'secondary' ], [ '222', '226', 'secondary' ], [ '600', '600', 'primary' ] ]
80
+ @artist.images.each_with_index do |image, index|
81
+ image.width.should == specs[index][0]
82
+ image.height.should == specs[index][1]
83
+ image.type.should == specs[index][2]
84
+ end
85
+ end
86
+
87
+ it "should have a traversible list of releases" do
88
+ @artist.releases.should be_instance_of(Array)
89
+ @artist.releases.length.should == 6
90
+ @artist.releases[0].should be_instance_of(Discogs::Artist::Release)
91
+ end
92
+
93
+ it "should have an ID for the first release" do
94
+ @artist.releases[0].id.should == "1805661"
95
+ end
96
+
97
+ it "should have a year for the first release" do
98
+ @artist.releases[0].year.should == "1991"
99
+ end
100
+
101
+ it "should have a label for the third release" do
102
+ @artist.releases[2].label.should == "Apollo"
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
109
+ end