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
data/lib/tools/cache.rb DELETED
@@ -1,48 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module MusicBrainz
4
- module Tools
5
- class Cache
6
- class << self
7
- @@cache_path = nil
8
-
9
- def cache_path=(path)
10
- @@cache_path = path
11
- end
12
-
13
- def cache_path
14
- @@cache_path
15
- end
16
-
17
- def clear_cache
18
- FileUtils.rm_r(@@cache_path) if @@cache_path && File.exist?(@@cache_path)
19
- end
20
-
21
- def cache_contents(url)
22
- response = nil
23
- url_parts = url.split('/')
24
- file_name = url_parts.pop
25
- directory = url_parts.pop
26
- file_path = @@cache_path ? "#{@@cache_path}/#{directory}/#{file_name}" : nil
27
-
28
- if file_path && File.exist?(file_path)
29
- response = File.open(file_path).gets
30
- else
31
- response = yield
32
-
33
- unless response.nil? or file_path.nil?
34
- FileUtils.mkdir_p file_path.split('/')[0..-2].join('/')
35
- file = File.new(file_path, 'w')
36
- file.puts(response.gets) # .force_encoding('UTF-8')
37
- file.chmod(0755)
38
- file.close
39
- response.rewind
40
- end
41
- end
42
-
43
- response
44
- end
45
- end
46
- end
47
- end
48
- end
data/lib/tools/proxy.rb DELETED
@@ -1,62 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module MusicBrainz
4
- module Tools
5
- class Proxy
6
- class << self
7
- @@last_query_time = 0
8
- @@query_interval = 1.5 # Min: 1.0 Safe: 1.5
9
- @@tries_limit = 5
10
-
11
- WEB_SERVICE_URL = 'http://musicbrainz.org/ws/2/'
12
- USER_AGENT = "gem musicbrainz (https://github.com/magnolia-fan/musicbrainz) @ " + Socket.gethostname
13
-
14
- def query_interval=(sec)
15
- @@query_interval = sec.to_f
16
- end
17
-
18
- def query_interval
19
- @@query_interval
20
- end
21
-
22
- def tries_limit=(num)
23
- @@tries_limit = num.to_i
24
- end
25
-
26
- def query(params = {})
27
- url = WEB_SERVICE_URL + params[:resource].to_s.gsub('_', '-') + '/' + (params[:id].to_s || '')
28
- params.delete(:resource)
29
- params.delete(:id) unless params[:id].nil?
30
- url << '?' + params.map{ |k, v|
31
- k = k.to_s.gsub('_', '-')
32
- v = (v.is_a?(Array) ? v.map{ |_| _.to_s.gsub('_', '-') }.join('+') : v.to_s)
33
- k + '=' + v
34
- }.join('&') unless params.empty?
35
- MusicBrainz::Tools::Cache.cache_contents(url) {
36
- get_contents url
37
- }
38
- end
39
-
40
- def get_contents(url)
41
- response = nil
42
-
43
- @@tries_limit.times {
44
- time_passed = Time.now.to_f - @@last_query_time
45
- sleep(@@query_interval - time_passed) if time_passed < @@query_interval
46
-
47
- begin
48
- response = open(url, "User-Agent" => USER_AGENT)
49
- @@last_query_time = Time.now.to_f
50
- rescue => e
51
- response = nil if e.io.status[0].to_i == 404
52
- end
53
-
54
- break unless response.nil?
55
- }
56
-
57
- response
58
- end
59
- end
60
- end
61
- end
62
- end
data/lib/version.rb DELETED
@@ -1,5 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module MusicBrainz
4
- VERSION = "0.7.1"
5
- end
@@ -1,38 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require "spec_helper"
4
-
5
- describe MusicBrainz do
6
- before(:all) {
7
- @old_cache_path = MusicBrainz::Tools::Cache.cache_path
8
- }
9
-
10
- before(:each) {
11
- $stdout.stub!(:puts)
12
- MusicBrainz::Tools::Cache.cache_path = nil
13
- }
14
-
15
- after(:all) {
16
- MusicBrainz::Tools::Cache.cache_path = @old_cache_path
17
- }
18
-
19
- it "allows deprecated use of cache_path" do
20
- MusicBrainz::Tools::Cache.cache_path = "some/path"
21
- MusicBrainz::cache_path.should == "some/path"
22
- end
23
-
24
- it "allows deprecated use of cache_path=" do
25
- MusicBrainz.cache_path = "some/path"
26
- MusicBrainz::Tools::Cache.cache_path.should == "some/path"
27
- end
28
-
29
- it "allows deprecated use of query_interval" do
30
- MusicBrainz::Tools::Proxy.query_interval = 2
31
- MusicBrainz::query_interval.should == 2
32
- end
33
-
34
- it "allows deprecated use of query_interval=" do
35
- MusicBrainz.query_interval = 2
36
- MusicBrainz::Tools::Proxy.query_interval.should == 2
37
- end
38
- end
@@ -1,59 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require "spec_helper"
4
-
5
- describe MusicBrainz::Tools::Cache do
6
- before(:all) do
7
- @old_cache_path = MusicBrainz::Tools::Cache.cache_path
8
- @tmp_cache_path = File.join(File.dirname(__FILE__), '../../tmp/cache/tools')
9
- end
10
-
11
- after(:all) do
12
- MusicBrainz::Tools::Cache.cache_path = @old_cache_path
13
- end
14
-
15
- before(:each) do
16
- file_path = File.join(File.dirname(__FILE__), "../fixtures/kasabian.xml")
17
- @test_response = ::StringIO.new(File.open(file_path).gets)
18
- end
19
-
20
- context "with cache enabled" do
21
- it "calls get contents only once when requesting the resource twice" do
22
- MusicBrainz::Tools::Cache.cache_path = @tmp_cache_path
23
- mbid = "69b39eab-6577-46a4-a9f5-817839092033"
24
-
25
- MusicBrainz::Tools::Proxy.stub(:get_contents).and_return(@test_response)
26
- MusicBrainz::Tools::Proxy.should_receive(:get_contents).once
27
-
28
- File.exist?("#{@tmp_cache_path}/artist/#{mbid}?inc=url-rels").should be_false
29
- artist = MusicBrainz::Artist.find(mbid)
30
- artist.should be_a_kind_of(MusicBrainz::Artist)
31
-
32
- File.exist?("#{@tmp_cache_path}/artist/#{mbid}?inc=url-rels").should be_true
33
- artist = MusicBrainz::Artist.find(mbid)
34
- artist.should be_a_kind_of(MusicBrainz::Artist)
35
-
36
- MusicBrainz::Tools::Cache.clear_cache
37
- end
38
- end
39
-
40
- context "with cache disabled" do
41
- it "calls get contents twice when requesting the resource twice" do
42
- MusicBrainz::Tools::Cache.cache_path = nil
43
- mbid = "69b39eab-6577-46a4-a9f5-817839092033"
44
-
45
- MusicBrainz::Tools::Proxy.stub(:get_contents).and_return(@test_response)
46
- MusicBrainz::Tools::Proxy.should_receive(:get_contents).twice
47
-
48
- File.exist?("#{@tmp_cache_path}/artist/#{mbid}?inc=url-rels").should be_false
49
- artist = MusicBrainz::Artist.find(mbid)
50
- artist.should be_a_kind_of(MusicBrainz::Artist)
51
-
52
- File.exist?("#{@tmp_cache_path}/artist/#{mbid}?inc=url-rels").should be_false
53
- @test_response.rewind
54
- MusicBrainz.stub(:get_contents).and_return(@test_response)
55
- artist = MusicBrainz::Artist.find(mbid)
56
- artist.should be_a_kind_of(MusicBrainz::Artist)
57
- end
58
- end
59
- end