7digital 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README.rdoc +9 -7
  2. data/lib/sevendigital.rb +54 -53
  3. data/lib/sevendigital/api_operator.rb +33 -30
  4. data/lib/sevendigital/api_operator_cached.rb +23 -23
  5. data/lib/sevendigital/api_request.rb +23 -23
  6. data/lib/sevendigital/client.rb +136 -124
  7. data/lib/sevendigital/default_configuration.yml +2 -2
  8. data/lib/sevendigital/digestion_tract/api_response_digestor.rb +52 -52
  9. data/lib/sevendigital/digestion_tract/artist_digestor.rb +31 -31
  10. data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +27 -27
  11. data/lib/sevendigital/digestion_tract/digestor.rb +66 -66
  12. data/lib/sevendigital/digestion_tract/format_digestor.rb +21 -21
  13. data/lib/sevendigital/digestion_tract/label_digestor.rb +19 -19
  14. data/lib/sevendigital/digestion_tract/pager_digestor.rb +23 -23
  15. data/lib/sevendigital/digestion_tract/price_digestor.rb +24 -24
  16. data/lib/sevendigital/digestion_tract/release_digestor.rb +52 -52
  17. data/lib/sevendigital/digestion_tract/track_digestor.rb +37 -37
  18. data/lib/sevendigital/management/artist_manager.rb +45 -39
  19. data/lib/sevendigital/management/manager.rb +11 -11
  20. data/lib/sevendigital/management/release_manager.rb +57 -50
  21. data/lib/sevendigital/management/track_manager.rb +28 -17
  22. data/lib/sevendigital/model/api_response.rb +24 -12
  23. data/lib/sevendigital/model/artist.rb +46 -36
  24. data/lib/sevendigital/model/chart_item.rb +9 -9
  25. data/lib/sevendigital/model/format.rb +9 -9
  26. data/lib/sevendigital/model/label.rb +9 -9
  27. data/lib/sevendigital/model/price.rb +11 -11
  28. data/lib/sevendigital/model/release.rb +33 -33
  29. data/lib/sevendigital/model/sevendigital_error.rb +3 -3
  30. data/lib/sevendigital/model/sevendigital_object.rb +51 -51
  31. data/lib/sevendigital/model/track.rb +28 -7
  32. data/lib/sevendigital/pager.rb +16 -16
  33. data/lib/sevendigital/peachy_patch.rb +19 -0
  34. data/lib/sevendigital/proxy_police.rb +23 -23
  35. data/spec/api_operator_cached_spec.rb +47 -46
  36. data/spec/api_operator_spec.rb +114 -107
  37. data/spec/api_request_spec.rb +26 -27
  38. data/spec/client_spec.rb +75 -45
  39. data/spec/data/config/sevendigital.yml +5 -5
  40. data/spec/data/configuration_env_override.yml +5 -5
  41. data/spec/digestion_tract/api_response_digestor_spec.rb +78 -74
  42. data/spec/digestion_tract/artist_digestor_spec.rb +81 -82
  43. data/spec/digestion_tract/chart_digestor_spec.rb +52 -53
  44. data/spec/digestion_tract/format_digestor_spec.rb +38 -39
  45. data/spec/digestion_tract/label_digestor_spec.rb +33 -34
  46. data/spec/digestion_tract/pager_digestor_spec.rb +50 -51
  47. data/spec/digestion_tract/price_digestor_spec.rb +57 -57
  48. data/spec/digestion_tract/release_digestor_spec.rb +101 -102
  49. data/spec/digestion_tract/track_digestor_spec.rb +104 -106
  50. data/spec/management/artist_manager_spec.rb +128 -107
  51. data/spec/management/release_manager_spec.rb +222 -178
  52. data/spec/management/track_manager_spec.rb +88 -52
  53. data/spec/model/api_response_spec.rb +44 -31
  54. data/spec/model/artist_spec.rb +166 -121
  55. data/spec/model/release_spec.rb +109 -110
  56. data/spec/model/track_spec.rb +140 -0
  57. data/spec/pager_spec.rb +7 -8
  58. data/spec/peachy_spec_helper_patch.rb +7 -0
  59. data/spec/proxy_police_spec.rb +47 -48
  60. data/spec/spec_helper.rb +52 -48
  61. data/spec/test-xml/methods/artist/byTag/top.xml +50 -50
  62. data/spec/test-xml/methods/artist/details.xml +9 -9
  63. data/spec/test-xml/methods/artist/releases.xml +544 -544
  64. data/spec/test-xml/methods/artist/search.xml +19 -0
  65. data/spec/test-xml/methods/artist/similar.xml +39 -39
  66. data/spec/test-xml/methods/artist/toptracks.xml +279 -279
  67. data/spec/test-xml/methods/release/bydate.xml +173 -173
  68. data/spec/test-xml/methods/release/bytag/top.xml +150 -150
  69. data/spec/test-xml/methods/release/chart.xml +181 -181
  70. data/spec/test-xml/methods/release/details.xml +48 -48
  71. data/spec/test-xml/methods/release/recommend.xml +89 -89
  72. data/spec/test-xml/methods/release/search.xml +195 -0
  73. data/spec/test-xml/methods/release/tracks.xml +28 -28
  74. data/spec/test-xml/methods/track/chart.xml +149 -149
  75. data/spec/test-xml/methods/track/details.xml +30 -30
  76. data/spec/test-xml/methods/track/search.xml +160 -0
  77. data/spec/test-xml/objects/artist.xml +6 -6
  78. data/spec/test-xml/objects/artist_chart_item.xml +7 -7
  79. data/spec/test-xml/objects/artist_list.xml +22 -22
  80. data/spec/test-xml/objects/artist_list_empty.xml +4 -4
  81. data/spec/test-xml/objects/price.xml +7 -7
  82. data/spec/test-xml/objects/release.xml +40 -40
  83. data/spec/test-xml/objects/release_chart_item.xml +39 -34
  84. data/spec/test-xml/objects/release_list.xml +18 -18
  85. data/spec/test-xml/objects/release_list_empty.xml +4 -4
  86. data/spec/test-xml/objects/response.xml +39 -0
  87. data/spec/test-xml/objects/track.xml +33 -33
  88. data/spec/test-xml/objects/track_chart_item.xml +27 -27
  89. metadata +10 -5
  90. data/lib/peachy_patchy.rb +0 -14
  91. data/lib/sevendigital/version.rb +0 -3
@@ -1,111 +1,110 @@
1
- require "spec"
2
- require "date"
3
- require 'sevendigital'
4
-
5
- describe "Release" do
6
-
7
- before do
8
- @client = stub(Sevendigital::Client)
9
- @release_manager = mock(Sevendigital::ReleaseManager)
10
- @client.stub!(:release).and_return @release_manager
11
-
12
- @release = Sevendigital::Release.new(@client)
13
- @release.id = 1234
14
- end
15
-
16
- it "should get its basic details from manager" do
17
- expected_options = {:page => 2}
18
- fresh_release = fake_release_with_details
19
-
20
- @release_manager.should_receive(:get_details) { |release_id, options|
21
- release_id.should == @release.id
22
- (options.keys & expected_options.keys).should == expected_options.keys
23
- fresh_release
24
- }
25
- @release.get_details(expected_options)
26
-
27
- @release.version.should == fresh_release.version
28
- @release.type.should == fresh_release.type
29
- @release.artist.should == fresh_release.artist
30
- @release.image.should == fresh_release.image
31
- @release.url.should == fresh_release.url
32
- @release.release_date.should == fresh_release.release_date
33
- @release.added_date.should == fresh_release.added_date
34
- @release.barcode.should == fresh_release.barcode
35
- @release.year.should == fresh_release.year
36
- @release.explicit_content.should == fresh_release.explicit_content
37
- @release.formats.should == fresh_release.formats
38
- @release.label.should == fresh_release.label
39
- @release.price.should == fresh_release.price
40
-
41
- end
42
-
43
- it "get_tracks should get tracks from manager" do
44
- expected_options = {:page => 2}
45
-
46
- @release_manager.should_receive(:get_tracks) { |release_id, options|
47
- release_id.should == @release.id
48
- (options.keys & expected_options.keys).should == expected_options.keys
49
- fake_track_list
50
- }
51
- @release.get_tracks(expected_options)
52
-
53
- end
54
-
55
- it "get_tracks should link all tracks back to release itself" do
56
-
57
- @release_manager.should_receive(:get_tracks) { |release_id, options|
58
- release_id.should == @release.id
59
- fake_track_list
60
- }
61
-
62
- tracks = @release.get_tracks()
63
-
64
- tracks.all?{|track| track.release == @release}.should == true
65
-
66
- end
67
-
68
- it "get_recommendations should get recommendations from manager" do
69
- expected_options = {:page => 2}
70
-
71
- @release_manager.should_receive(:get_recommendations) { |release_id, options|
72
- release_id.should == @release.id
73
- (options.keys & expected_options.keys).should == expected_options.keys
74
- fake_releases_list
75
- }
76
- @release.get_recommendations(expected_options)
77
-
78
- end
79
-
80
- def fake_releases_list
81
- releases = Array.new
82
- releases << Sevendigital::Release.new(@client)
83
- releases << Sevendigital::Release.new(@client)
84
- releases
85
- end
86
-
87
- def fake_track_list
88
- tracks = Array.new
89
- tracks << Sevendigital::Track.new(@client)
90
- tracks << Sevendigital::Track.new(@client)
91
- tracks
92
- end
93
-
94
- def fake_release_with_details
95
- release = Sevendigital::Release.new(@client)
96
- release.version = "(release version)"
97
- release.type = :album
98
- release.artist = Sevendigital::Artist.new(@client)
99
- release.image = "image"
100
- release.url = "url"
101
- release.release_date = DateTime.new(2010, 1, 1)
102
- release.added_date = DateTime.new(2000, 1, 1)
103
- release.barcode = "AAA"
104
- release.year = 1999
105
- release.explicit_content = true
106
- release.formats = []
107
- release.label = Sevendigital::Label.new
108
- release.price = Sevendigital::Price.new
109
- release
110
- end
1
+ require "date"
2
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
3
+
4
+ describe "Release" do
5
+
6
+ before do
7
+ @client = stub(Sevendigital::Client)
8
+ @release_manager = mock(Sevendigital::ReleaseManager)
9
+ @client.stub!(:release).and_return @release_manager
10
+
11
+ @release = Sevendigital::Release.new(@client)
12
+ @release.id = 1234
13
+ end
14
+
15
+ it "should get its basic details from manager" do
16
+ expected_options = {:page => 2}
17
+ fresh_release = fake_release_with_details
18
+
19
+ @release_manager.should_receive(:get_details) { |release_id, options|
20
+ release_id.should == @release.id
21
+ (options.keys & expected_options.keys).should == expected_options.keys
22
+ fresh_release
23
+ }
24
+ @release.get_details(expected_options)
25
+
26
+ @release.version.should == fresh_release.version
27
+ @release.type.should == fresh_release.type
28
+ @release.artist.should == fresh_release.artist
29
+ @release.image.should == fresh_release.image
30
+ @release.url.should == fresh_release.url
31
+ @release.release_date.should == fresh_release.release_date
32
+ @release.added_date.should == fresh_release.added_date
33
+ @release.barcode.should == fresh_release.barcode
34
+ @release.year.should == fresh_release.year
35
+ @release.explicit_content.should == fresh_release.explicit_content
36
+ @release.formats.should == fresh_release.formats
37
+ @release.label.should == fresh_release.label
38
+ @release.price.should == fresh_release.price
39
+
40
+ end
41
+
42
+ it "get_tracks should get tracks from manager" do
43
+ expected_options = {:page => 2}
44
+
45
+ @release_manager.should_receive(:get_tracks) { |release_id, options|
46
+ release_id.should == @release.id
47
+ (options.keys & expected_options.keys).should == expected_options.keys
48
+ fake_track_list
49
+ }
50
+ @release.get_tracks(expected_options)
51
+
52
+ end
53
+
54
+ it "get_tracks should link all tracks back to release itself" do
55
+
56
+ @release_manager.should_receive(:get_tracks) { |release_id, options|
57
+ release_id.should == @release.id
58
+ fake_track_list
59
+ }
60
+
61
+ tracks = @release.get_tracks()
62
+
63
+ tracks.all?{|track| track.release == @release}.should == true
64
+
65
+ end
66
+
67
+ it "get_recommendations should get recommendations from manager" do
68
+ expected_options = {:page => 2}
69
+
70
+ @release_manager.should_receive(:get_recommendations) { |release_id, options|
71
+ release_id.should == @release.id
72
+ (options.keys & expected_options.keys).should == expected_options.keys
73
+ fake_releases_list
74
+ }
75
+ @release.get_recommendations(expected_options)
76
+
77
+ end
78
+
79
+ def fake_releases_list
80
+ releases = Array.new
81
+ releases << Sevendigital::Release.new(@client)
82
+ releases << Sevendigital::Release.new(@client)
83
+ releases
84
+ end
85
+
86
+ def fake_track_list
87
+ tracks = Array.new
88
+ tracks << Sevendigital::Track.new(@client)
89
+ tracks << Sevendigital::Track.new(@client)
90
+ tracks
91
+ end
92
+
93
+ def fake_release_with_details
94
+ release = Sevendigital::Release.new(@client)
95
+ release.version = "(release version)"
96
+ release.type = :album
97
+ release.artist = Sevendigital::Artist.new(@client)
98
+ release.image = "image"
99
+ release.url = "url"
100
+ release.release_date = DateTime.new(2010, 1, 1)
101
+ release.added_date = DateTime.new(2000, 1, 1)
102
+ release.barcode = "AAA"
103
+ release.year = 1999
104
+ release.explicit_content = true
105
+ release.formats = []
106
+ release.label = Sevendigital::Label.new
107
+ release.price = Sevendigital::Price.new
108
+ release
109
+ end
111
110
  end
@@ -0,0 +1,140 @@
1
+ require "date"
2
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
3
+
4
+ describe "Track" do
5
+
6
+ before do
7
+ @client = stub(Sevendigital::Client)
8
+ @track_manager = mock(Sevendigital::TrackManager)
9
+ @client.stub!(:track).and_return @track_manager
10
+
11
+ @track = Sevendigital::Track.new(@client)
12
+ @track.id = 1234
13
+ end
14
+
15
+ it "get_details should get track's basic details from manager" do
16
+ expected_options = {:page => 2}
17
+ fresh_track = fake_track_with_details
18
+
19
+ @track_manager.should_receive(:get_details) { |track_id, options|
20
+ track_id.should == @track.id
21
+ (options.keys & expected_options.keys).should == expected_options.keys
22
+ fresh_track
23
+ }
24
+ @track.get_details(expected_options)
25
+
26
+ @track.track_number.should == fresh_track.track_number
27
+ @track.duration.should == fresh_track.duration
28
+ @track.explicit_content.should == fresh_track.explicit_content
29
+ @track.isrc.should == fresh_track.isrc
30
+ @track.release.should == fresh_track.release
31
+ @track.url.should == fresh_track.url
32
+
33
+ end
34
+
35
+ it "preview_url should get preview URL from manager" do
36
+ expected_options = {:country => "mx"}
37
+ fake_preview_url = "http://preview.com/trackid/123456"
38
+
39
+ @track_manager.should_receive(:build_preview_url) { |track_id, options|
40
+ track_id.should == @track.id
41
+ (options.keys & expected_options.keys).should == expected_options.keys
42
+ fake_preview_url
43
+ }
44
+
45
+ @track.preview_url(expected_options).should == fake_preview_url
46
+
47
+ end
48
+
49
+ it "should have a short title without any version in brackets" do
50
+
51
+ @track.title = "Girl With One Eye (Bayou Percussion Version)"
52
+ @track.short_title.should == "Girl With One Eye"
53
+
54
+ @track.title = "The Thing I Like Best About Him Is His Girlfriend (Gr's Man-Made Island Edition)"
55
+ @track.short_title.should == "The Thing I Like Best About Him Is His Girlfriend"
56
+
57
+ @track.title = "Your Head to Your Toes (Live at the BBC)"
58
+ @track.short_title.should == "Your Head to Your Toes"
59
+
60
+ @track.title = "Welcome To The World of The Plastic Beach (Feat. Snoop Dogg and Hypnotic Brass Ensemble)"
61
+ @track.short_title.should == "Welcome To The World of The Plastic Beach"
62
+
63
+ @track.title = "(lp version)"
64
+ @track.short_title.should == "(lp version)"
65
+
66
+ @track.title = "What's the Story (Morning Glory)"
67
+ @track.short_title.should == "What's the Story (Morning Glory)"
68
+
69
+ @track.title = "track 1 (something else)"
70
+ @track.short_title.should == "track 1 (something else)"
71
+
72
+ @track.title = "track 1 (dj remix)"
73
+ @track.short_title.should == "track 1"
74
+
75
+ @track.title = "track 1 ( dj mix )"
76
+ @track.short_title.should == "track 1"
77
+ end
78
+
79
+ describe "alternate_version?" do
80
+
81
+ before do
82
+ @artist1 = Sevendigital::Artist.new(@client)
83
+ @artist2 = Sevendigital::Artist.new(@client)
84
+ @track1 = Sevendigital::Track.new(@client)
85
+ @track1.artist = @artist1
86
+ @track2 = Sevendigital::Track.new(@client)
87
+ @track2.artist = @artist2
88
+
89
+ @artist1.name = "artist 1"
90
+ @track1.title = "track 1"
91
+
92
+ end
93
+
94
+ it "should be considered alternate version if artist names and titles match" do
95
+ @artist2.name = "Artist 1"
96
+ @track2.title = "Track 1"
97
+
98
+ @track1.alternate_version_of?(@track2).should == true
99
+ end
100
+
101
+ it "should be considered alternate version if artist names and short titles match" do
102
+ @track1.title = "track 1 (uk version)"
103
+
104
+ @artist2.name = "Artist 1"
105
+ @track2.title = "TRACK 1 (us remix)"
106
+
107
+ @track1.alternate_version_of?(@track2).should == true
108
+ end
109
+
110
+ it "should not be considered alternate version if artist names don't match" do
111
+ @artist2.name = "artist 2"
112
+ @track2.title = "track 1"
113
+
114
+ @track1.alternate_version_of?(@track2).should == false
115
+ end
116
+
117
+ it "should not be considered alternate version if short titles don't match" do
118
+ @artist2.name = "artist 1"
119
+ @track2.title = "track 2"
120
+
121
+ @track1.alternate_version_of?(@track2).should == false
122
+ end
123
+
124
+
125
+ end
126
+
127
+ def fake_track_with_details
128
+ track = Sevendigital::Track.new(@client)
129
+ track.title = "Song 1"
130
+ track.version = "Version 2"
131
+ track.artist = Sevendigital::Artist.new(@client)
132
+ track.track_number = 7
133
+ track.duration = 77
134
+ track.explicit_content = true
135
+ track.isrc = "7D"
136
+ track.release = Sevendigital::Release.new(@client)
137
+ track.url = "http://aaa.bbb.ccc/"
138
+ track
139
+ end
140
+ end
@@ -1,8 +1,7 @@
1
- require 'spec'
2
- require File.join(File.dirname(__FILE__), %w[spec_helper])
3
-
4
- describe "Pager" do
5
-
6
- it "should paginate list"
7
-
8
- end
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe "Pager" do
4
+
5
+ it "should paginate list"
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ module Peachy
2
+ class Proxy
3
+ def ==(other_proxy)
4
+ (to_s == other_proxy.to_s)
5
+ end
6
+ end
7
+ end
@@ -1,49 +1,48 @@
1
- # encoding: UTF-8
2
- require 'spec'
3
- require 'date'
4
- require File.join(File.dirname(__FILE__), %w[spec_helper])
5
-
6
- describe "Proxy Police" do
7
-
8
- it "should create a Peachy proxy from xml string with root element with given name" do
9
-
10
- xml = <<XML
11
- <rootElement id="123">
12
- <subElement>expected value</subElement>
13
- </rootElement>
14
- XML
15
-
16
- proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, :root_element)
17
- proxy.kind_of?(Peachy::Proxy).should == true
18
- proxy.sub_element.value.should == "expected value"
19
- end
20
-
21
- it "should create a Peachy proxy from root of the xml string if no element name given" do
22
-
23
- xml = <<XML
24
- <rootElement id="123">
25
- <subElement>expected value</subElement>
26
- </rootElement>
27
- XML
28
-
29
- proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, nil)
30
- proxy.kind_of?(Peachy::Proxy).should == true
31
- proxy.root_element.sub_element.value.should == "expected value"
32
-
33
- end
34
-
35
- it "should not create a Peachy proxy from xml string without root element with given name" do
36
-
37
- xml = <<XML
38
- <rootElement id="123">
39
- <subElement>expected value</subElement>
40
- </rootElement>
41
- XML
42
-
43
- proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, :different_element)
44
- proxy.should == nil
45
-
46
- end
47
-
48
-
1
+ # encoding: UTF-8
2
+ require 'date'
3
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
4
+
5
+ describe "Proxy Police" do
6
+
7
+ it "should create a Peachy proxy from xml string with root element with given name" do
8
+
9
+ xml = <<XML
10
+ <rootElement id="123">
11
+ <subElement>expected value</subElement>
12
+ </rootElement>
13
+ XML
14
+
15
+ proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, :root_element)
16
+ proxy.kind_of?(Peachy::Proxy).should == true
17
+ proxy.sub_element.value.should == "expected value"
18
+ end
19
+
20
+ it "should create a Peachy proxy from root of the xml string if no element name given" do
21
+
22
+ xml = <<XML
23
+ <rootElement id="123">
24
+ <subElement>expected value</subElement>
25
+ </rootElement>
26
+ XML
27
+
28
+ proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, nil)
29
+ proxy.kind_of?(Peachy::Proxy).should == true
30
+ proxy.root_element.sub_element.value.should == "expected value"
31
+
32
+ end
33
+
34
+ it "should not create a Peachy proxy from xml string without root element with given name" do
35
+
36
+ xml = <<XML
37
+ <rootElement id="123">
38
+ <subElement>expected value</subElement>
39
+ </rootElement>
40
+ XML
41
+
42
+ proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, :different_element)
43
+ proxy.should == nil
44
+
45
+ end
46
+
47
+
49
48
  end