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,125 @@
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
+ @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_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
+ @release = @wrapper.get_release(@release_id)
23
+ end
24
+
25
+ describe "when calling simple release attributes" do
26
+
27
+ it "should have a title attribute" do
28
+ @release.title.should == "Into the Abyss"
29
+ end
30
+
31
+ it "should have an ID attribute" do
32
+ @release.id.should == "666666"
33
+ end
34
+
35
+ it "should have one or more extra artists" do
36
+ @release.extraartists.should be_instance_of(Array)
37
+ @release.extraartists[0].should be_instance_of(Discogs::Release::Artist)
38
+ end
39
+
40
+ it "should have one or more tracks" do
41
+ @release.tracklist.should be_instance_of(Array)
42
+ @release.tracklist[0].should be_instance_of(Discogs::Release::Track)
43
+ end
44
+
45
+ it "should have one or more genres" do
46
+ @release.genres.should be_instance_of(Array)
47
+ @release.genres[0].should == "Heavy Metal"
48
+ end
49
+
50
+ it "should have one or more formats" do
51
+ @release.formats.should be_instance_of(Array)
52
+ @release.formats[0].should be_instance_of(Discogs::Release::Format)
53
+ end
54
+
55
+ it "should have one or more images" do
56
+ @release.images.should be_instance_of(Array)
57
+ @release.images[0].should be_instance_of(Discogs::Image)
58
+ end
59
+
60
+ end
61
+
62
+ describe "when calling complex release attributes" do
63
+
64
+ it "should have a duration for the first track" do
65
+ @release.tracklist[0].duration.should == "8:11"
66
+ end
67
+
68
+ it "should have specifications for each image" do
69
+ specs = [ [ '600', '595', 'primary' ], [ '600', '593', 'secondary' ], [ '600', '539', 'secondary' ], [ '600', '452', 'secondary' ], [ '600', '567', 'secondary' ] ]
70
+ @release.images.each_with_index do |image, index|
71
+ image.width.should == specs[index][0]
72
+ image.height.should == specs[index][1]
73
+ image.type.should == specs[index][2]
74
+ end
75
+ end
76
+
77
+ it "should have a traversible list of styles" do
78
+ @release.styles.should be_instance_of(Array)
79
+ @release.styles[0].should == "Black Metal"
80
+ @release.styles[1].should == "Thrash"
81
+ end
82
+
83
+ it "should have a traversible list of labels" do
84
+ @release.styles.should be_instance_of(Array)
85
+ @release.labels[0].should be_instance_of(Discogs::Release::Label)
86
+ @release.labels[0].catno.should == "Death9"
87
+ @release.labels[0].name.should == "Culted"
88
+ end
89
+
90
+ it "should have a name and quantity for the first format" do
91
+ @release.formats[0].name.should == "CD"
92
+ @release.formats[0].qty.should == "1"
93
+ end
94
+
95
+ it "should have an array of descriptions for the first format" do
96
+ @release.formats[0].descriptions.should be_instance_of(Array)
97
+ @release.formats[0].descriptions[0].should == "Album"
98
+ end
99
+
100
+ it "should have an artist associated to the second track" do
101
+ @release.tracklist[1].artists.should be_instance_of(Array)
102
+ @release.tracklist[1].artists[0].should be_instance_of(Discogs::Release::Track::Artist)
103
+ @release.tracklist[1].artists[0].name.should == "Arakain"
104
+ end
105
+
106
+ it "should have an extra artist associated to the second track" do
107
+ @release.tracklist[1].extraartists.should be_instance_of(Array)
108
+ @release.tracklist[1].extraartists[0].should be_instance_of(Discogs::Release::Track::Artist)
109
+ @release.tracklist[1].extraartists[0].name.should == "Debustrol"
110
+ @release.tracklist[1].extraartists[0].role.should == "Sadism"
111
+ end
112
+
113
+ it "should have a role associated to the first extra artist" do
114
+ @release.extraartists[0].role.should == "Lyrics By"
115
+ end
116
+
117
+ it "should have no artist associated to the third track" do
118
+ @release.tracklist[2].artists.should be_nil
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+ end
@@ -0,0 +1,99 @@
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
+ @search_term = "slaughter"
8
+ end
9
+
10
+ describe "when asking for search result information" do
11
+
12
+ before do
13
+ @http_request = mock(Net::HTTP)
14
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_search_xml)
15
+ @http_response_as_file = mock(StringIO, :read => valid_search_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
+ @search = @wrapper.search(@search_term)
23
+ end
24
+
25
+ describe "when handling exact results" do
26
+
27
+ it "should have the exact results stored as an array" do
28
+ @search.exactresults.should be_instance_of(Array)
29
+ end
30
+
31
+ it "should be stored as result objects" do
32
+ @search.exactresults.each do |result|
33
+ result.should be_instance_of(Discogs::Search::Result)
34
+ end
35
+ end
36
+
37
+ it "should have a incrementing num for each exact result" do
38
+ @search.exactresults.each_with_index do |result, index|
39
+ result.num.should == (index + 1).to_s
40
+ end
41
+ end
42
+
43
+ it "should have a type for the first result" do
44
+ @search.exactresults[0].type.should == "artist"
45
+ end
46
+
47
+ it "should have an anv for the fifth result" do
48
+ @search.exactresults[5].anv.should == "Slaughter"
49
+ end
50
+
51
+ end
52
+
53
+ describe "when handling search results" do
54
+
55
+ it "should have a start attribute" do
56
+ @search.start.should == "1"
57
+ end
58
+
59
+ it "should have an end attribute" do
60
+ @search.end.should == "20"
61
+ end
62
+
63
+ it "should have number of results attribute" do
64
+ @search.total_results.should == "1846"
65
+ end
66
+
67
+ it "should have the search results stored as an array" do
68
+ @search.searchresults.should be_instance_of(Array)
69
+ end
70
+
71
+ it "should be stored as result objects" do
72
+ @search.searchresults.each do |result|
73
+ result.should be_instance_of(Discogs::Search::Result)
74
+ end
75
+ end
76
+
77
+ it "should have a incrementing num for each search result" do
78
+ @search.searchresults.each_with_index do |result, index|
79
+ result.num.should == (index + 1).to_s
80
+ end
81
+ end
82
+
83
+ it "should have a type for the third result" do
84
+ @search.searchresults[2].type.should == "label"
85
+ end
86
+
87
+ it "should have a title for the fourth result" do
88
+ @search.searchresults[3].title.should == "Satanic Slaughter"
89
+ end
90
+
91
+ it "should have a summary for the sixth result" do
92
+ @search.searchresults[5].summary.should == "Gary Slaughter"
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1,100 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ def mock_http_with_response(code="200")
6
+ @http_request = mock(Net::HTTP)
7
+ @http_response = mock(Net::HTTPResponse, :code => code, :body => "")
8
+ @http_session = mock("HTTP Session")
9
+ @http_session.should_receive(:request).and_return(@http_response)
10
+ @http_request.should_receive(:start).and_yield(@http_session)
11
+ Net::HTTP.should_receive(:new).and_return(@http_request)
12
+ end
13
+
14
+ before do
15
+ @api_key = "some_key"
16
+ @wrapper = Discogs::Wrapper.new(@api_key)
17
+ @release_id = "666666"
18
+ @artist_name = "Dark"
19
+ @label_name = "Monitor"
20
+ end
21
+
22
+ it "should have an api key" do
23
+ @wrapper.api_key.should == @api_key
24
+ end
25
+
26
+ ## NOTE: See ./spec/wrapper_methods/*.rb for indepth tests on valid API requests.
27
+
28
+ describe "when requesting a release" do
29
+
30
+ it "should successfully return a Discogs::Release object" do
31
+ @http_response_as_file = mock(StringIO, :read => valid_release_xml)
32
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
33
+ mock_http_with_response "200"
34
+
35
+ @wrapper.get_release(@release_id).should be_instance_of(Discogs::Release)
36
+ end
37
+
38
+ it "should raise an exception if an invalid API Key is supplied" do
39
+ mock_http_with_response "400"
40
+
41
+ lambda { @wrapper.get_release(@release_id) }.should raise_error(Discogs::InvalidAPIKey)
42
+ end
43
+
44
+ it "should raise an exception if the release does not exist" do
45
+ mock_http_with_response "404"
46
+
47
+ lambda { @wrapper.get_release(@release_id) }.should raise_error(Discogs::UnknownResource)
48
+ end
49
+
50
+ end
51
+
52
+ describe "when requesting an artist" do
53
+
54
+ it "should successfully return a Discogs::Artist object" do
55
+ @http_response_as_file = mock(StringIO, :read => valid_artist_xml)
56
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
57
+ mock_http_with_response "200"
58
+
59
+ @wrapper.get_artist(@artist_name).should be_instance_of(Discogs::Artist)
60
+ end
61
+
62
+ it "should raise an exception if an invalid API Key is supplied" do
63
+ mock_http_with_response "400"
64
+
65
+ lambda { @wrapper.get_artist(@artist_name) }.should raise_error(Discogs::InvalidAPIKey)
66
+ end
67
+
68
+ it "should raise an exception if the artist does not exist" do
69
+ mock_http_with_response "404"
70
+
71
+ lambda { @wrapper.get_artist(@artist_name) }.should raise_error(Discogs::UnknownResource)
72
+ end
73
+
74
+ end
75
+
76
+ describe "when requesting a label" do
77
+
78
+ it "should successfully return a Discogs::Label object" do
79
+ @http_response_as_file = mock(StringIO, :read => valid_label_xml)
80
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
81
+ mock_http_with_response "200"
82
+
83
+ @wrapper.get_label(@label_name).should be_instance_of(Discogs::Label)
84
+ end
85
+
86
+ it "should raise an exception if an invalid API Key is supplied" do
87
+ mock_http_with_response "400"
88
+
89
+ lambda { @wrapper.get_label(@label_name) }.should raise_error(Discogs::InvalidAPIKey)
90
+ end
91
+
92
+ it "should raise an exception if the label does not exist" do
93
+ mock_http_with_response "404"
94
+
95
+ lambda { @wrapper.get_label(@label_name) }.should raise_error(Discogs::UnknownResource)
96
+ end
97
+
98
+ end
99
+
100
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buntine-discogs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Buntine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-04 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Discogs::Wrapper is a full wrapper for the http://www.discogs.com API
17
+ email: info@andrewbuntine.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/wrapper
26
+ - lib/wrapper/resource_mappings.rb
27
+ - lib/wrapper/wrapper.rb
28
+ - lib/wrapper/resource.rb
29
+ - lib/wrapper/resources
30
+ - lib/wrapper/resources/format.rb
31
+ - lib/wrapper/resources/search.rb
32
+ - lib/wrapper/resources/label_release.rb
33
+ - lib/wrapper/resources/artist.rb
34
+ - lib/wrapper/resources/release_artist.rb
35
+ - lib/wrapper/resources/artist_release.rb
36
+ - lib/wrapper/resources/release_label.rb
37
+ - lib/wrapper/resources/generic_list.rb
38
+ - lib/wrapper/resources/search_result.rb
39
+ - lib/wrapper/resources/label.rb
40
+ - lib/wrapper/resources/image.rb
41
+ - lib/wrapper/resources/track.rb
42
+ - lib/wrapper/resources/release.rb
43
+ - lib/discogs.rb
44
+ - Rakefile
45
+ - README
46
+ - discogs.gemspec
47
+ has_rdoc: false
48
+ homepage: http://www.github.com/buntine/discogs
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: Discogs::Wrapper is a full wrapper for the http://www.discogs.com API
73
+ test_files:
74
+ - spec/wrapper_methods/get_release_spec.rb
75
+ - spec/wrapper_methods/search_spec.rb
76
+ - spec/wrapper_methods/get_artist_spec.rb
77
+ - spec/wrapper_methods/get_label_spec.rb
78
+ - spec/resource_spec.rb
79
+ - spec/resources/label_spec.rb
80
+ - spec/resources/generic_list_spec.rb
81
+ - spec/resources/artist_release_spec.rb
82
+ - spec/resources/artist_spec.rb
83
+ - spec/resources/release_artist_spec.rb
84
+ - spec/resources/search_spec.rb
85
+ - spec/resources/label_release_spec.rb
86
+ - spec/resources/release_label_spec.rb
87
+ - spec/resources/release_spec.rb
88
+ - spec/resources/search_result_spec.rb
89
+ - spec/resources/image_spec.rb
90
+ - spec/resources/track_spec.rb
91
+ - spec/resources/format_spec.rb
92
+ - spec/wrapper_spec.rb
93
+ - spec/spec_helper.rb