musicbrainz 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +1 -4
  2. data/.travis.yml +2 -2
  3. data/Contributors +1 -0
  4. data/README.md +91 -40
  5. data/lib/mb.rb +2 -0
  6. data/lib/musicbrainz.rb +27 -22
  7. data/lib/musicbrainz/bindings/artist.rb +23 -0
  8. data/lib/musicbrainz/bindings/artist_release_groups.rb +13 -0
  9. data/lib/musicbrainz/bindings/artist_search.rb +23 -0
  10. data/lib/musicbrainz/bindings/release.rb +28 -0
  11. data/lib/musicbrainz/bindings/release_group.rb +18 -0
  12. data/lib/musicbrainz/bindings/release_group_releases.rb +13 -0
  13. data/lib/musicbrainz/bindings/release_tracks.rb +13 -0
  14. data/lib/musicbrainz/bindings/track.rb +16 -0
  15. data/lib/musicbrainz/client.rb +72 -0
  16. data/lib/musicbrainz/client_modules/caching_proxy.rb +46 -0
  17. data/lib/musicbrainz/client_modules/failsafe_proxy.rb +38 -0
  18. data/lib/musicbrainz/client_modules/transparent_proxy.rb +12 -0
  19. data/lib/musicbrainz/configuration.rb +60 -0
  20. data/lib/musicbrainz/deprecated.rb +36 -0
  21. data/lib/musicbrainz/middleware.rb +23 -0
  22. data/lib/musicbrainz/models/artist.rb +47 -0
  23. data/lib/musicbrainz/models/base_model.rb +63 -0
  24. data/lib/musicbrainz/models/release.rb +27 -0
  25. data/lib/musicbrainz/models/release_group.rb +28 -0
  26. data/lib/musicbrainz/models/track.rb +17 -0
  27. data/lib/musicbrainz/version.rb +3 -0
  28. data/musicbrainz.gemspec +10 -12
  29. data/spec/bindings/release_spec.rb +43 -0
  30. data/spec/client_modules/cache_spec.rb +62 -0
  31. data/spec/deprecated/cache_config_spec.rb +32 -0
  32. data/spec/deprecated/proxy_config_spec.rb +32 -0
  33. data/spec/{requests → models}/artist_spec.rb +3 -9
  34. data/spec/{requests → models}/release_group_spec.rb +2 -2
  35. data/spec/{requests → models}/release_spec.rb +1 -1
  36. data/spec/{requests → models}/track_spec.rb +0 -0
  37. data/spec/spec_helper.rb +13 -7
  38. metadata +63 -58
  39. data/Rakefile +0 -13
  40. data/lib/deprecated.rb +0 -25
  41. data/lib/musicbrainz/artist.rb +0 -63
  42. data/lib/musicbrainz/base.rb +0 -71
  43. data/lib/musicbrainz/release.rb +0 -43
  44. data/lib/musicbrainz/release_group.rb +0 -41
  45. data/lib/musicbrainz/track.rb +0 -23
  46. data/lib/parsers/artist.rb +0 -47
  47. data/lib/parsers/base.rb +0 -41
  48. data/lib/parsers/release.rb +0 -28
  49. data/lib/parsers/release_group.rb +0 -27
  50. data/lib/parsers/track.rb +0 -18
  51. data/lib/tools/cache.rb +0 -48
  52. data/lib/tools/proxy.rb +0 -62
  53. data/lib/version.rb +0 -5
  54. data/spec/misc/deprecated_spec.rb +0 -38
  55. data/spec/tools/cache_spec.rb +0 -59
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "spec_helper"
4
+
5
+ describe MusicBrainz::Bindings::Release do
6
+ describe '.parse' do
7
+ describe 'attributes' do
8
+ describe 'format' do
9
+ context 'single cd' do
10
+ it 'returns CD' do
11
+ response = '<release><medium-list count="1"><medium><format>CD</format></medium></medium-list></release>'
12
+ xml = Nokogiri::XML.parse(response)
13
+ described_class.parse(xml)[:format].should == 'CD'
14
+ end
15
+ end
16
+
17
+ context 'multiple cds' do
18
+ it 'returns 2xCD' do
19
+ response = '<release><medium-list count="2"><medium><format>CD</format><track-list count="11" /></medium><medium><title>bonus disc</title><format>CD</format></medium></medium-list></release>'
20
+ xml = Nokogiri::XML.parse(response)
21
+ described_class.parse(xml)[:format].should == '2xCD'
22
+ end
23
+ end
24
+
25
+ context 'different formats' do
26
+ it 'returns DVD + CD' do
27
+ response = '<release><medium-list count="2"><medium><format>DVD</format></medium><medium><format>CD</format></medium></medium-list></release>'
28
+ xml = Nokogiri::XML.parse(response)
29
+ described_class.parse(xml)[:format].should == 'DVD + CD'
30
+ end
31
+ end
32
+
33
+ context 'different formats plus multiple mediums with same format' do
34
+ it 'returns 2xCD + DVD' do
35
+ response = '<release><medium-list count="2"><medium><format>CD</format></medium><medium><format>CD</format></medium><medium><format>DVD</format></medium></medium-list></release>'
36
+ xml = Nokogiri::XML.parse(response)
37
+ described_class.parse(xml)[:format].should == '2xCD + DVD'
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ require "ostruct"
4
+ require "spec_helper"
5
+
6
+ describe MusicBrainz::ClientModules::CachingProxy do
7
+ let(:old_cache_path){ File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'spec_cache') }
8
+ let(:tmp_cache_path){ File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'cache_module_spec_cache') }
9
+ let(:test_mbid){ "69b39eab-6577-46a4-a9f5-817839092033" }
10
+ let(:test_cache_file){ "#{tmp_cache_path}/03/48/ec/6c2bee685d9a96f95ed46378f624714e7a4650b0d44c1a8eee5bac2480.xml" }
11
+ let(:test_response_file){ File.join(File.dirname(__FILE__), "../fixtures/kasabian.xml") }
12
+ let(:test_response){ File.open(test_response_file).read }
13
+
14
+ before(:all) do
15
+ MusicBrainz.config.cache_path = tmp_cache_path
16
+ end
17
+
18
+ after(:all) do
19
+ MusicBrainz.config.cache_path = old_cache_path
20
+ MusicBrainz.config.perform_caching = true
21
+ MusicBrainz.config.query_interval = 1.5
22
+ end
23
+
24
+ context "with cache enabled" do
25
+ it "calls http only once when requesting the resource twice" do
26
+ MusicBrainz.config.perform_caching = true
27
+ File.exist?(test_cache_file).should be_false
28
+
29
+ # Stubbing
30
+ MusicBrainz.client.http.stub(:get).and_return(OpenStruct.new(status: 200, body: test_response))
31
+ MusicBrainz.client.http.should_receive(:get).once
32
+
33
+ 2.times do
34
+ artist = MusicBrainz::Artist.find(test_mbid)
35
+ artist.should be_a_kind_of(MusicBrainz::Artist)
36
+ File.exist?(test_cache_file).should be_true
37
+ end
38
+
39
+ MusicBrainz.client.clear_cache
40
+ end
41
+ end
42
+
43
+ context "with cache disabled" do
44
+ it "calls http twice when requesting the resource twice" do
45
+ MusicBrainz.config.perform_caching = false
46
+ File.exist?(test_cache_file).should be_false
47
+
48
+ # Hacking for test performance purposes
49
+ MusicBrainz.config.query_interval = 0.0
50
+
51
+ # Stubbing
52
+ MusicBrainz.client.http.stub(:get).and_return(OpenStruct.new(status: 200, body: test_response))
53
+ MusicBrainz.client.http.should_receive(:get).twice
54
+
55
+ 2.times do
56
+ artist = MusicBrainz::Artist.find(test_mbid)
57
+ artist.should be_a_kind_of(MusicBrainz::Artist)
58
+ File.exist?(test_cache_file).should be_false
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "spec_helper"
4
+
5
+ describe MusicBrainz::Deprecated::CacheConfig do
6
+ before(:all) {
7
+ @old_cache_path = MusicBrainz.config.cache_path
8
+ }
9
+
10
+ before(:each) {
11
+ MusicBrainz.config.cache_path = nil
12
+ }
13
+
14
+ after(:all) {
15
+ MusicBrainz.config.cache_path = @old_cache_path
16
+ }
17
+
18
+ it "allows deprecated use of cache_path" do
19
+ MusicBrainz.config.cache_path = "test1"
20
+
21
+ MusicBrainz::Tools::Cache.cache_path.should == "test1"
22
+ MusicBrainz.cache_path.should == "test1"
23
+ end
24
+
25
+ it "allows deprecated use of cache_path=" do
26
+ MusicBrainz::Tools::Cache.cache_path = "test2"
27
+ MusicBrainz.config.cache_path.should == "test2"
28
+
29
+ MusicBrainz.cache_path = "test3"
30
+ MusicBrainz.config.cache_path.should == "test3"
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "spec_helper"
4
+
5
+ describe MusicBrainz::Deprecated::ProxyConfig do
6
+ before(:all) {
7
+ @old_query_interval = MusicBrainz.config.query_interval
8
+ }
9
+
10
+ before(:each) {
11
+ MusicBrainz.config.query_interval = nil
12
+ }
13
+
14
+ after(:all) {
15
+ MusicBrainz.config.query_interval = @old_query_interval
16
+ }
17
+
18
+ it "allows deprecated use of query_interval" do
19
+ MusicBrainz.config.query_interval = 2
20
+
21
+ MusicBrainz::Tools::Proxy.query_interval.should == 2
22
+ MusicBrainz.query_interval.should == 2
23
+ end
24
+
25
+ it "allows deprecated use of query_interval=" do
26
+ MusicBrainz::Tools::Proxy.query_interval = 3
27
+ MusicBrainz.config.query_interval.should == 3
28
+
29
+ MusicBrainz.query_interval = 4
30
+ MusicBrainz.config.query_interval.should == 4
31
+ end
32
+ end
@@ -24,15 +24,9 @@ describe MusicBrainz::Artist do
24
24
  matches = MusicBrainz::Artist.search('Chris Martin')
25
25
 
26
26
  matches[0][:score].should == 100
27
- matches[0][:mbid].should == "98d1ec5a-dd97-4c0b-9c83-7928aac89bca"
27
+ matches[0][:id].should == "98d1ec5a-dd97-4c0b-9c83-7928aac89bca"
28
28
  matches[1][:score].should == 100
29
- matches[1][:mbid].should == "af2ab893-3212-4226-9e73-73a1660b6952"
30
- matches[2][:score].should == 95
31
- matches[2][:mbid].should == "444d1b63-534b-4ea6-89f0-0af6ab2e20c3"
32
- matches[3][:score].should == 95
33
- matches[3][:mbid].should == "b732a912-af95-472c-be52-b14610734c64"
34
- matches[4][:score].should == 95
35
- matches[4][:mbid].should == "90fff570-a4ef-4cd4-ba21-e00c7261b05a"
29
+ matches[1][:id].should == "af2ab893-3212-4226-9e73-73a1660b6952"
36
30
  end
37
31
 
38
32
  it "finds name first than alias" do
@@ -61,6 +55,6 @@ describe MusicBrainz::Artist do
61
55
  release_groups.first.id.should == "533cbc5f-ec7e-32ab-95f3-8d1f804a5176"
62
56
  release_groups.first.type.should == "Single"
63
57
  release_groups.first.title.should == "Club Foot"
64
- release_groups.first.first_release_date.should == Time.utc(2004, 5, 10)
58
+ release_groups.first.first_release_date.should == Date.new(2004, 5, 10)
65
59
  end
66
60
  end
@@ -19,7 +19,7 @@ describe MusicBrainz::ReleaseGroup do
19
19
  release_group.id.should == "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
20
20
  release_group.type.should == "Album"
21
21
  release_group.title.should == "Empire"
22
- release_group.first_release_date.should == Time.utc(2006, 8, 28)
22
+ release_group.first_release_date.should == Date.new(2006, 8, 28)
23
23
  end
24
24
 
25
25
  it "gets correct release group's releases" do
@@ -28,7 +28,7 @@ describe MusicBrainz::ReleaseGroup do
28
28
  releases.first.id.should == "2225dd4c-ae9a-403b-8ea0-9e05014c778f"
29
29
  releases.first.status.should == "Official"
30
30
  releases.first.title.should == "Empire"
31
- releases.first.date.should == Time.utc(2006, 8, 28)
31
+ releases.first.date.should == Date.new(2006, 8, 28)
32
32
  releases.first.country.should == "GB"
33
33
  end
34
34
  end
@@ -19,7 +19,7 @@ describe MusicBrainz::Release do
19
19
  release.id.should == "2225dd4c-ae9a-403b-8ea0-9e05014c778f"
20
20
  release.title.should == "Empire"
21
21
  release.status.should == "Official"
22
- release.date.should == Time.utc(2006, 8, 28)
22
+ release.date.should == Date.new(2006, 8, 28)
23
23
  release.country.should == "GB"
24
24
  end
25
25
 
File without changes
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,19 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "rubygems"
4
2
  require "bundler/setup"
5
- require "ap"
6
-
7
3
  require "musicbrainz"
8
4
 
9
- MusicBrainz::Tools::Cache.cache_path = "tmp/cache"
5
+ RSpec.configure do |c|
6
+ c.order = 'random'
7
+ end
8
+
9
+ MusicBrainz.configure do |c|
10
+ test_email = `git config user.email`.chomp
11
+ test_email = "magnolia_fan@me.com" if test_email.empty?
12
+
13
+ c.app_name = "MusicBrainzGemTestSuite"
14
+ c.app_version = MusicBrainz::VERSION
15
+ c.contact = test_email
10
16
 
11
- RSpec.configure do |config|
12
- # Configuration is not currently necessary
17
+ c.cache_path = File.join(File.dirname(__FILE__), '..', 'tmp', 'spec_cache')
18
+ c.perform_caching = true
13
19
  end
metadata CHANGED
@@ -1,80 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musicbrainz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
5
4
  prerelease:
5
+ version: 0.7.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gregory Eremin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-06 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: nokogiri
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
15
+ version_requirements: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
20
+ none: false
21
+ name: faraday
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
24
+ requirement: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ! '>='
28
27
  - !ruby/object:Gem::Version
29
28
  version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
29
  none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
34
32
  requirements:
35
33
  - - ! '>='
36
34
  - !ruby/object:Gem::Version
37
35
  version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
36
  none: false
37
+ name: nokogiri
38
+ type: :runtime
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
42
41
  requirements:
43
42
  - - ! '>='
44
43
  - !ruby/object:Gem::Version
45
44
  version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: awesome_print
48
- requirement: !ruby/object:Gem::Requirement
49
45
  none: false
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
50
48
  requirements:
51
49
  - - ! '>='
52
50
  - !ruby/object:Gem::Version
53
51
  version: '0'
52
+ none: false
53
+ name: rspec
54
54
  type: :development
55
55
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
56
+ requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ! '>='
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: rspec
64
- requirement: !ruby/object:Gem::Requirement
65
61
  none: false
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: !ruby/object:Gem::Requirement
66
64
  requirements:
67
65
  - - ! '>='
68
66
  - !ruby/object:Gem::Version
69
67
  version: '0'
68
+ none: false
69
+ name: awesome_print
70
70
  type: :development
71
71
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
72
+ requirement: !ruby/object:Gem::Requirement
74
73
  requirements:
75
74
  - - ! '>='
76
75
  - !ruby/object:Gem::Version
77
76
  version: '0'
77
+ none: false
78
78
  description:
79
79
  email:
80
80
  - magnolia_fan@me.com
@@ -89,31 +89,40 @@ files:
89
89
  - Gemfile
90
90
  - LICENSE
91
91
  - README.md
92
- - Rakefile
93
- - lib/deprecated.rb
92
+ - lib/mb.rb
94
93
  - lib/musicbrainz.rb
95
- - lib/musicbrainz/artist.rb
96
- - lib/musicbrainz/base.rb
97
- - lib/musicbrainz/release.rb
98
- - lib/musicbrainz/release_group.rb
99
- - lib/musicbrainz/track.rb
100
- - lib/parsers/artist.rb
101
- - lib/parsers/base.rb
102
- - lib/parsers/release.rb
103
- - lib/parsers/release_group.rb
104
- - lib/parsers/track.rb
105
- - lib/tools/cache.rb
106
- - lib/tools/proxy.rb
107
- - lib/version.rb
94
+ - lib/musicbrainz/bindings/artist.rb
95
+ - lib/musicbrainz/bindings/artist_release_groups.rb
96
+ - lib/musicbrainz/bindings/artist_search.rb
97
+ - lib/musicbrainz/bindings/release.rb
98
+ - lib/musicbrainz/bindings/release_group.rb
99
+ - lib/musicbrainz/bindings/release_group_releases.rb
100
+ - lib/musicbrainz/bindings/release_tracks.rb
101
+ - lib/musicbrainz/bindings/track.rb
102
+ - lib/musicbrainz/client.rb
103
+ - lib/musicbrainz/client_modules/caching_proxy.rb
104
+ - lib/musicbrainz/client_modules/failsafe_proxy.rb
105
+ - lib/musicbrainz/client_modules/transparent_proxy.rb
106
+ - lib/musicbrainz/configuration.rb
107
+ - lib/musicbrainz/deprecated.rb
108
+ - lib/musicbrainz/middleware.rb
109
+ - lib/musicbrainz/models/artist.rb
110
+ - lib/musicbrainz/models/base_model.rb
111
+ - lib/musicbrainz/models/release.rb
112
+ - lib/musicbrainz/models/release_group.rb
113
+ - lib/musicbrainz/models/track.rb
114
+ - lib/musicbrainz/version.rb
108
115
  - musicbrainz.gemspec
116
+ - spec/bindings/release_spec.rb
117
+ - spec/client_modules/cache_spec.rb
118
+ - spec/deprecated/cache_config_spec.rb
119
+ - spec/deprecated/proxy_config_spec.rb
109
120
  - spec/fixtures/kasabian.xml
110
- - spec/misc/deprecated_spec.rb
111
- - spec/requests/artist_spec.rb
112
- - spec/requests/release_group_spec.rb
113
- - spec/requests/release_spec.rb
114
- - spec/requests/track_spec.rb
121
+ - spec/models/artist_spec.rb
122
+ - spec/models/release_group_spec.rb
123
+ - spec/models/release_spec.rb
124
+ - spec/models/track_spec.rb
115
125
  - spec/spec_helper.rb
116
- - spec/tools/cache_spec.rb
117
126
  homepage: http://github.com/magnolia-fan/musicbrainz
118
127
  licenses:
119
128
  - MIT
@@ -122,23 +131,17 @@ rdoc_options: []
122
131
  require_paths:
123
132
  - lib
124
133
  required_ruby_version: !ruby/object:Gem::Requirement
125
- none: false
126
134
  requirements:
127
135
  - - ! '>='
128
136
  - !ruby/object:Gem::Version
129
137
  version: '0'
130
- segments:
131
- - 0
132
- hash: 4552071205810046641
133
- required_rubygems_version: !ruby/object:Gem::Requirement
134
138
  none: false
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
140
  requirements:
136
141
  - - ! '>='
137
142
  - !ruby/object:Gem::Version
138
143
  version: '0'
139
- segments:
140
- - 0
141
- hash: 4552071205810046641
144
+ none: false
142
145
  requirements: []
143
146
  rubyforge_project:
144
147
  rubygems_version: 1.8.23
@@ -146,11 +149,13 @@ signing_key:
146
149
  specification_version: 3
147
150
  summary: MusicBrainz Web Service wrapper with ActiveRecord-style models
148
151
  test_files:
152
+ - spec/bindings/release_spec.rb
153
+ - spec/client_modules/cache_spec.rb
154
+ - spec/deprecated/cache_config_spec.rb
155
+ - spec/deprecated/proxy_config_spec.rb
149
156
  - spec/fixtures/kasabian.xml
150
- - spec/misc/deprecated_spec.rb
151
- - spec/requests/artist_spec.rb
152
- - spec/requests/release_group_spec.rb
153
- - spec/requests/release_spec.rb
154
- - spec/requests/track_spec.rb
157
+ - spec/models/artist_spec.rb
158
+ - spec/models/release_group_spec.rb
159
+ - spec/models/release_spec.rb
160
+ - spec/models/track_spec.rb
155
161
  - spec/spec_helper.rb
156
- - spec/tools/cache_spec.rb