bassnode-discogs 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +5 -0
  2. data/COPYING +619 -0
  3. data/LICENSE +5 -0
  4. data/README.markdown +75 -0
  5. data/Rakefile +27 -0
  6. data/bassnode-discogs.gemspec +18 -0
  7. data/lib/discogs.rb +21 -0
  8. data/lib/wrapper/resource.rb +79 -0
  9. data/lib/wrapper/resource_mappings.rb +84 -0
  10. data/lib/wrapper/resources/artist.rb +37 -0
  11. data/lib/wrapper/resources/artist_release.rb +17 -0
  12. data/lib/wrapper/resources/format.rb +11 -0
  13. data/lib/wrapper/resources/generic_list.rb +29 -0
  14. data/lib/wrapper/resources/image.rb +11 -0
  15. data/lib/wrapper/resources/label.rb +16 -0
  16. data/lib/wrapper/resources/label_release.rb +17 -0
  17. data/lib/wrapper/resources/release.rb +22 -0
  18. data/lib/wrapper/resources/release_artist.rb +18 -0
  19. data/lib/wrapper/resources/release_label.rb +10 -0
  20. data/lib/wrapper/resources/search.rb +61 -0
  21. data/lib/wrapper/resources/search_result.rb +16 -0
  22. data/lib/wrapper/resources/track.rb +15 -0
  23. data/lib/wrapper/wrapper.rb +109 -0
  24. data/spec/resource_spec.rb +27 -0
  25. data/spec/resources/artist_release_spec.rb +59 -0
  26. data/spec/resources/artist_spec.rb +15 -0
  27. data/spec/resources/format_spec.rb +41 -0
  28. data/spec/resources/generic_list_spec.rb +66 -0
  29. data/spec/resources/image_spec.rb +43 -0
  30. data/spec/resources/label_release_spec.rb +55 -0
  31. data/spec/resources/label_spec.rb +15 -0
  32. data/spec/resources/release_artist_spec.rb +43 -0
  33. data/spec/resources/release_label_spec.rb +31 -0
  34. data/spec/resources/release_spec.rb +15 -0
  35. data/spec/resources/search_result_spec.rb +47 -0
  36. data/spec/resources/search_spec.rb +15 -0
  37. data/spec/resources/track_spec.rb +56 -0
  38. data/spec/samples/valid_artist.xml +76 -0
  39. data/spec/samples/valid_artist_release.xml +8 -0
  40. data/spec/samples/valid_description_list.xml +5 -0
  41. data/spec/samples/valid_format.xml +7 -0
  42. data/spec/samples/valid_genre_list.xml +5 -0
  43. data/spec/samples/valid_image.xml +1 -0
  44. data/spec/samples/valid_label.xml +34 -0
  45. data/spec/samples/valid_label_release.xml +8 -0
  46. data/spec/samples/valid_release.xml +99 -0
  47. data/spec/samples/valid_release_artist.xml +8 -0
  48. data/spec/samples/valid_release_label.xml +1 -0
  49. data/spec/samples/valid_search_result.xml +6 -0
  50. data/spec/samples/valid_search_results_1.xml +142 -0
  51. data/spec/samples/valid_search_results_2.xml +206 -0
  52. data/spec/samples/valid_track.xml +16 -0
  53. data/spec/spec_helper.rb +36 -0
  54. data/spec/wrapper_methods/get_artist_spec.rb +109 -0
  55. data/spec/wrapper_methods/get_label_spec.rb +89 -0
  56. data/spec/wrapper_methods/get_release_spec.rb +123 -0
  57. data/spec/wrapper_methods/search_spec.rb +330 -0
  58. data/spec/wrapper_spec.rb +180 -0
  59. metadata +125 -0
@@ -0,0 +1,180 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ def mock_http_with_response(code="200", response=nil)
6
+ @http_request = mock(Net::HTTP)
7
+ @http_response = mock(Net::HTTPResponse, :code => code, :body => "")
8
+
9
+ unless response.nil?
10
+ @http_response_as_file = mock(StringIO, :read => response)
11
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
12
+ end
13
+
14
+ # As of 04/09/2010 - The and_yield method is not working for me. I've removed
15
+ # this from the specs for now, but it's a little troubling because it used to
16
+ # work correctly... (replacement on line #21)
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
+
21
+ @http_request.should_receive(:start).and_return(@http_response)
22
+ Net::HTTP.should_receive(:new).and_return(@http_request)
23
+ end
24
+
25
+ before do
26
+ @api_key = "some_key"
27
+ @wrapper = Discogs::Wrapper.new(@api_key)
28
+ @release_id = "666666"
29
+ @artist_name = "Dark"
30
+ @label_name = "Monitor"
31
+ @search_term = "barry"
32
+ end
33
+
34
+ it "should have an api key" do
35
+ @wrapper.api_key.should == @api_key
36
+ end
37
+
38
+ describe "requested URIs" do
39
+ before do
40
+ @uri = mock("uri", :host => "", :query => "", :path => "")
41
+ end
42
+
43
+ it "should generate the correct release URL to parse" do
44
+ mock_http_with_response "200", valid_release_xml
45
+ URI.should_receive(:parse).with("http://www.discogs.com/release/666666?api_key=some_key&f=xml").and_return(@uri)
46
+
47
+ @wrapper.get_release(@release_id)
48
+ end
49
+
50
+ it "should generate the correct artist URL to parse" do
51
+ mock_http_with_response "200", valid_artist_xml
52
+ URI.should_receive(:parse).with("http://www.discogs.com/artist/Dark?api_key=some_key&f=xml").and_return(@uri)
53
+
54
+ @wrapper.get_artist(@artist_name)
55
+ end
56
+
57
+ it "should generate the correct label URL to parse" do
58
+ mock_http_with_response "200", valid_label_xml
59
+ URI.should_receive(:parse).with("http://www.discogs.com/label/Monitor?api_key=some_key&f=xml").and_return(@uri)
60
+
61
+ @wrapper.get_label(@label_name)
62
+ end
63
+
64
+ it "should generate the correct default search URL to parse" do
65
+ mock_http_with_response "200", valid_search_xml
66
+ URI.should_receive(:parse).with("http://www.discogs.com/search?api_key=some_key&f=xml&page=1&q=barry&type=all").and_return(@uri)
67
+
68
+ @wrapper.search(@search_term)
69
+ end
70
+
71
+ it "should generate the correct second-page search URL to parse" do
72
+ mock_http_with_response "200", valid_search_xml
73
+ URI.should_receive(:parse).with("http://www.discogs.com/search?api_key=some_key&f=xml&page=2&q=barry&type=all").and_return(@uri)
74
+
75
+ @wrapper.search(@search_term, :page => 2)
76
+ end
77
+
78
+ it "should generate the correct second-page artist search URL to parse" do
79
+ mock_http_with_response "200", valid_search_xml
80
+ URI.should_receive(:parse).with("http://www.discogs.com/search?api_key=some_key&f=xml&page=2&q=barry&type=artist").and_return(@uri)
81
+
82
+ @wrapper.search(@search_term, :page => 2, :type => :artist)
83
+ end
84
+
85
+ it "should sanitize the path correctly" do
86
+ mock_http_with_response "200", valid_artist_xml
87
+ URI.should_receive(:parse).with("http://www.discogs.com/artist/A+very+long+band+name?api_key=some_key&f=xml").and_return(@uri)
88
+
89
+ @wrapper.get_artist("A very long band name")
90
+ end
91
+
92
+ end
93
+
94
+ ## NOTE: See ./spec/wrapper_methods/*.rb for indepth tests on valid API requests.
95
+
96
+ describe "when requesting a release" do
97
+
98
+ it "should successfully return a Discogs::Release object" do
99
+ mock_http_with_response "200", valid_release_xml
100
+
101
+ @wrapper.get_release(@release_id).should be_instance_of(Discogs::Release)
102
+ end
103
+
104
+ it "should raise an exception if an invalid API Key is supplied" do
105
+ mock_http_with_response "400"
106
+
107
+ lambda { @wrapper.get_release(@release_id) }.should raise_error(Discogs::InvalidAPIKey)
108
+ end
109
+
110
+ it "should raise an exception if the release does not exist" do
111
+ mock_http_with_response "404"
112
+
113
+ lambda { @wrapper.get_release(@release_id) }.should raise_error(Discogs::UnknownResource)
114
+ end
115
+
116
+ it "should raise an exception if the server dies a horrible death" do
117
+ mock_http_with_response "500"
118
+
119
+ lambda { @wrapper.get_release(@release_id) }.should raise_error(Discogs::InternalServerError)
120
+ end
121
+
122
+ end
123
+
124
+ describe "when requesting an artist" do
125
+
126
+ it "should successfully return a Discogs::Artist object" do
127
+ mock_http_with_response "200", valid_artist_xml
128
+
129
+ @wrapper.get_artist(@artist_name).should be_instance_of(Discogs::Artist)
130
+ end
131
+
132
+ it "should raise an exception if an invalid API Key is supplied" do
133
+ mock_http_with_response "400"
134
+
135
+ lambda { @wrapper.get_artist(@artist_name) }.should raise_error(Discogs::InvalidAPIKey)
136
+ end
137
+
138
+ it "should raise an exception if the artist does not exist" do
139
+ mock_http_with_response "404"
140
+
141
+ lambda { @wrapper.get_artist(@artist_name) }.should raise_error(Discogs::UnknownResource)
142
+ end
143
+
144
+ it "should raise an exception if the server dies a horrible death" do
145
+ mock_http_with_response "500"
146
+
147
+ lambda { @wrapper.get_artist(@artist_name) }.should raise_error(Discogs::InternalServerError)
148
+ end
149
+
150
+ end
151
+
152
+ describe "when requesting a label" do
153
+
154
+ it "should successfully return a Discogs::Label object" do
155
+ mock_http_with_response "200", valid_label_xml
156
+
157
+ @wrapper.get_label(@label_name).should be_instance_of(Discogs::Label)
158
+ end
159
+
160
+ it "should raise an exception if an invalid API Key is supplied" do
161
+ mock_http_with_response "400"
162
+
163
+ lambda { @wrapper.get_label(@label_name) }.should raise_error(Discogs::InvalidAPIKey)
164
+ end
165
+
166
+ it "should raise an exception if the label does not exist" do
167
+ mock_http_with_response "404"
168
+
169
+ lambda { @wrapper.get_label(@label_name) }.should raise_error(Discogs::UnknownResource)
170
+ end
171
+
172
+ it "should raise an exception if the server dies a horrible death" do
173
+ mock_http_with_response "500"
174
+
175
+ lambda { @wrapper.get_label(@label_name) }.should raise_error(Discogs::InternalServerError)
176
+ end
177
+
178
+ end
179
+
180
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bassnode-discogs
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 2
10
+ version: 0.3.2
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Buntine
14
+ - Ed Hickey
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-04-12 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Discogs::Wrapper is a full wrapper for the http://www.discogs.com API
24
+ email: info@andrewbuntine.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - COPYING
34
+ - LICENSE
35
+ - README.markdown
36
+ - Rakefile
37
+ - bassnode-discogs.gemspec
38
+ - lib/discogs.rb
39
+ - lib/wrapper/resource.rb
40
+ - lib/wrapper/resource_mappings.rb
41
+ - lib/wrapper/resources/artist.rb
42
+ - lib/wrapper/resources/artist_release.rb
43
+ - lib/wrapper/resources/format.rb
44
+ - lib/wrapper/resources/generic_list.rb
45
+ - lib/wrapper/resources/image.rb
46
+ - lib/wrapper/resources/label.rb
47
+ - lib/wrapper/resources/label_release.rb
48
+ - lib/wrapper/resources/release.rb
49
+ - lib/wrapper/resources/release_artist.rb
50
+ - lib/wrapper/resources/release_label.rb
51
+ - lib/wrapper/resources/search.rb
52
+ - lib/wrapper/resources/search_result.rb
53
+ - lib/wrapper/resources/track.rb
54
+ - lib/wrapper/wrapper.rb
55
+ - spec/resource_spec.rb
56
+ - spec/resources/artist_release_spec.rb
57
+ - spec/resources/artist_spec.rb
58
+ - spec/resources/format_spec.rb
59
+ - spec/resources/generic_list_spec.rb
60
+ - spec/resources/image_spec.rb
61
+ - spec/resources/label_release_spec.rb
62
+ - spec/resources/label_spec.rb
63
+ - spec/resources/release_artist_spec.rb
64
+ - spec/resources/release_label_spec.rb
65
+ - spec/resources/release_spec.rb
66
+ - spec/resources/search_result_spec.rb
67
+ - spec/resources/search_spec.rb
68
+ - spec/resources/track_spec.rb
69
+ - spec/samples/valid_artist.xml
70
+ - spec/samples/valid_artist_release.xml
71
+ - spec/samples/valid_description_list.xml
72
+ - spec/samples/valid_format.xml
73
+ - spec/samples/valid_genre_list.xml
74
+ - spec/samples/valid_image.xml
75
+ - spec/samples/valid_label.xml
76
+ - spec/samples/valid_label_release.xml
77
+ - spec/samples/valid_release.xml
78
+ - spec/samples/valid_release_artist.xml
79
+ - spec/samples/valid_release_label.xml
80
+ - spec/samples/valid_search_result.xml
81
+ - spec/samples/valid_search_results_1.xml
82
+ - spec/samples/valid_search_results_2.xml
83
+ - spec/samples/valid_track.xml
84
+ - spec/spec_helper.rb
85
+ - spec/wrapper_methods/get_artist_spec.rb
86
+ - spec/wrapper_methods/get_label_spec.rb
87
+ - spec/wrapper_methods/get_release_spec.rb
88
+ - spec/wrapper_methods/search_spec.rb
89
+ - spec/wrapper_spec.rb
90
+ has_rdoc: true
91
+ homepage: http://www.github.com/bassnode/discogs
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options: []
96
+
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project: bassnode-discogs
120
+ rubygems_version: 1.3.7
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Discogs::Wrapper is a full wrapper for the http://www.discogs.com API
124
+ test_files: []
125
+