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,162 @@
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
+ @user_agent = "some_app"
27
+ @wrapper = Discogs::Wrapper.new(@user_agent)
28
+ @release_id = "666666"
29
+ @artist_name = "Dark"
30
+ @label_name = "Monitor"
31
+ @search_term = "barry"
32
+ end
33
+
34
+ it "should have an user agent" do
35
+ @wrapper.user_agent.should == @user_agent
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://api.discogs.com/release/666666?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://api.discogs.com/artist/Dark?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://api.discogs.com/label/Monitor?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://api.discogs.com/search?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://api.discogs.com/search?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://api.discogs.com/search?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://api.discogs.com/artist/A+very+long+band+name?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 the release does not exist" do
105
+ mock_http_with_response "404"
106
+
107
+ lambda { @wrapper.get_release(@release_id) }.should raise_error(Discogs::UnknownResource)
108
+ end
109
+
110
+ it "should raise an exception if the server dies a horrible death" do
111
+ mock_http_with_response "500"
112
+
113
+ lambda { @wrapper.get_release(@release_id) }.should raise_error(Discogs::InternalServerError)
114
+ end
115
+
116
+ end
117
+
118
+ describe "when requesting an artist" do
119
+
120
+ it "should successfully return a Discogs::Artist object" do
121
+ mock_http_with_response "200", valid_artist_xml
122
+
123
+ @wrapper.get_artist(@artist_name).should be_instance_of(Discogs::Artist)
124
+ end
125
+
126
+ it "should raise an exception if the artist does not exist" do
127
+ mock_http_with_response "404"
128
+
129
+ lambda { @wrapper.get_artist(@artist_name) }.should raise_error(Discogs::UnknownResource)
130
+ end
131
+
132
+ it "should raise an exception if the server dies a horrible death" do
133
+ mock_http_with_response "500"
134
+
135
+ lambda { @wrapper.get_artist(@artist_name) }.should raise_error(Discogs::InternalServerError)
136
+ end
137
+
138
+ end
139
+
140
+ describe "when requesting a label" do
141
+
142
+ it "should successfully return a Discogs::Label object" do
143
+ mock_http_with_response "200", valid_label_xml
144
+
145
+ @wrapper.get_label(@label_name).should be_instance_of(Discogs::Label)
146
+ end
147
+
148
+ it "should raise an exception if the label does not exist" do
149
+ mock_http_with_response "404"
150
+
151
+ lambda { @wrapper.get_label(@label_name) }.should raise_error(Discogs::UnknownResource)
152
+ end
153
+
154
+ it "should raise an exception if the server dies a horrible death" do
155
+ mock_http_with_response "500"
156
+
157
+ lambda { @wrapper.get_label(@label_name) }.should raise_error(Discogs::InternalServerError)
158
+ end
159
+
160
+ end
161
+
162
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discogs-wrapper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Buntine
14
+ - Ed Hickey
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-09-27 00:00:00 +10:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Discogs::Wrapper is a full wrapper for the http://www.discogs.com API V2
24
+ email: info@andrewbuntine.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - lib/wrapper/resource_mappings.rb
33
+ - lib/wrapper/wrapper.rb
34
+ - lib/wrapper/resource.rb
35
+ - lib/wrapper/resources/format.rb
36
+ - lib/wrapper/resources/search.rb
37
+ - lib/wrapper/resources/label_release.rb
38
+ - lib/wrapper/resources/artist.rb
39
+ - lib/wrapper/resources/release_artist.rb
40
+ - lib/wrapper/resources/artist_release.rb
41
+ - lib/wrapper/resources/release_label.rb
42
+ - lib/wrapper/resources/generic_list.rb
43
+ - lib/wrapper/resources/search_result.rb
44
+ - lib/wrapper/resources/label.rb
45
+ - lib/wrapper/resources/image.rb
46
+ - lib/wrapper/resources/track.rb
47
+ - lib/wrapper/resources/release.rb
48
+ - lib/discogs.rb
49
+ - Rakefile
50
+ - README.markdown
51
+ - discogs.gemspec
52
+ - spec/wrapper_methods/get_release_spec.rb
53
+ - spec/wrapper_methods/search_spec.rb
54
+ - spec/wrapper_methods/get_artist_spec.rb
55
+ - spec/wrapper_methods/get_label_spec.rb
56
+ - spec/resource_spec.rb
57
+ - spec/resources/label_spec.rb
58
+ - spec/resources/generic_list_spec.rb
59
+ - spec/resources/artist_release_spec.rb
60
+ - spec/resources/artist_spec.rb
61
+ - spec/resources/release_artist_spec.rb
62
+ - spec/resources/search_spec.rb
63
+ - spec/resources/label_release_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/image_spec.rb
68
+ - spec/resources/track_spec.rb
69
+ - spec/resources/format_spec.rb
70
+ - spec/wrapper_spec.rb
71
+ - spec/spec_helper.rb
72
+ has_rdoc: true
73
+ homepage: http://www.github.com/buntine/discogs
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.7
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Discogs::Wrapper is a full wrapper for the http://www.discogs.com API V2
106
+ test_files:
107
+ - spec/wrapper_methods/get_release_spec.rb
108
+ - spec/wrapper_methods/search_spec.rb
109
+ - spec/wrapper_methods/get_artist_spec.rb
110
+ - spec/wrapper_methods/get_label_spec.rb
111
+ - spec/resource_spec.rb
112
+ - spec/resources/label_spec.rb
113
+ - spec/resources/generic_list_spec.rb
114
+ - spec/resources/artist_release_spec.rb
115
+ - spec/resources/artist_spec.rb
116
+ - spec/resources/release_artist_spec.rb
117
+ - spec/resources/search_spec.rb
118
+ - spec/resources/label_release_spec.rb
119
+ - spec/resources/release_label_spec.rb
120
+ - spec/resources/release_spec.rb
121
+ - spec/resources/search_result_spec.rb
122
+ - spec/resources/image_spec.rb
123
+ - spec/resources/track_spec.rb
124
+ - spec/resources/format_spec.rb
125
+ - spec/wrapper_spec.rb
126
+ - spec/spec_helper.rb