7digital 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,52 +1,88 @@
1
- # encoding: UTF-8
2
- require 'spec'
3
- require 'date'
4
- require 'sevendigital'
5
-
6
- describe "TrackManager" do
7
-
8
- before do
9
-
10
- @client = stub(Sevendigital::Client)
11
- @client.stub!(:operator).and_return(mock(Sevendigital::ApiOperator))
12
- @track_manager = Sevendigital::TrackManager.new(@client)
13
-
14
- end
15
-
16
- it "get_details should call track/details api method and return digested track" do
17
- a_track_id = 123
18
- an_api_response = fake_api_response("track/details")
19
- a_track = Sevendigital::Track.new(@client)
20
-
21
- mock_client_digestor(@client, :track_digestor) \
22
- .should_receive(:from_xml).with(an_api_response.content.track).and_return(a_track)
23
-
24
- @client.operator.should_receive(:call_api) { |api_request|
25
- api_request.api_method.should == "track/details"
26
- api_request.parameters[:trackId].should == a_track_id
27
- an_api_response
28
- }
29
-
30
- @track_manager.get_details(a_track_id).should == a_track
31
-
32
- end
33
-
34
- it "get_chart should call track/chart api method and digest the release list from response" do
35
-
36
- api_response = fake_api_response("track/chart")
37
- a_chart = []
38
-
39
- mock_client_digestor(@client, :chart_item_digestor) \
40
- .should_receive(:list_from_xml).with(api_response.content.chart).and_return(a_chart)
41
-
42
- @client.operator.should_receive(:call_api) { |api_request|
43
- api_request.api_method.should == "track/chart"
44
- api_response
45
- }
46
-
47
- chart = @track_manager.get_chart
48
- chart.should == a_chart
49
- end
50
-
51
-
52
- end
1
+ # encoding: UTF-8
2
+ require 'date'
3
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
4
+
5
+ describe "TrackManager" do
6
+
7
+ before do
8
+
9
+ @client = stub(Sevendigital::Client)
10
+ @client.stub!(:operator).and_return(mock(Sevendigital::ApiOperator))
11
+ @track_manager = Sevendigital::TrackManager.new(@client)
12
+
13
+ end
14
+
15
+ it "get_details should call track/details api method and return digested track" do
16
+ a_track_id = 123
17
+ an_api_response = fake_api_response("track/details")
18
+ a_track = Sevendigital::Track.new(@client)
19
+
20
+ mock_client_digestor(@client, :track_digestor) \
21
+ .should_receive(:from_xml).with(an_api_response.content.track).and_return(a_track)
22
+
23
+ @client.operator.should_receive(:call_api) { |api_request|
24
+ api_request.api_method.should == "track/details"
25
+ api_request.parameters[:trackId].should == a_track_id
26
+ an_api_response
27
+ }
28
+
29
+ @track_manager.get_details(a_track_id).should == a_track
30
+
31
+ end
32
+
33
+ it "get_chart should call track/chart api method and digest the release list from response" do
34
+
35
+ api_response = fake_api_response("track/chart")
36
+ a_chart = []
37
+
38
+ mock_client_digestor(@client, :chart_item_digestor) \
39
+ .should_receive(:list_from_xml).with(api_response.content.chart).and_return(a_chart)
40
+
41
+ @client.operator.should_receive(:call_api) { |api_request|
42
+ api_request.api_method.should == "track/chart"
43
+ api_response
44
+ }
45
+
46
+ chart = @track_manager.get_chart
47
+ chart.should == a_chart
48
+ end
49
+
50
+ it "build_preview_url should return URL for track/preview api request" do
51
+ track_id = 123456
52
+ fake_preview_url = "http://7digital.com/track/preview"
53
+
54
+ @client.operator.should_receive(:create_request_uri) { |api_request|
55
+ api_request.api_method.should == "track/preview"
56
+ api_request.parameters[:trackId].should == track_id
57
+ fake_preview_url
58
+ }
59
+
60
+ preview_url = @track_manager.build_preview_url(track_id)
61
+
62
+ preview_url.should == fake_preview_url
63
+ end
64
+
65
+ it "search should call track/search api method and digest the nested track list from response" do
66
+
67
+ query = "radiohead"
68
+ api_response = fake_api_response("track/search")
69
+ a_track_list = [Sevendigital::Track.new(@client)]
70
+
71
+ mock_client_digestor(@client, :track_digestor) \
72
+ .should_receive(:nested_list_from_xml) \
73
+ .with(api_response.content.search_results, :search_result, :search_results) \
74
+ .and_return(a_track_list)
75
+
76
+ @client.operator.should_receive(:call_api) { |api_request|
77
+ api_request.api_method.should == "track/search"
78
+ api_request.parameters[:q].should == query
79
+ api_response
80
+ }
81
+
82
+ tracks = @track_manager.search(query)
83
+ tracks.should == a_track_list
84
+
85
+ end
86
+
87
+
88
+ end
@@ -1,32 +1,45 @@
1
- require "spec"
2
- require 'sevendigital'
3
-
4
- describe "ApiResponse" do
5
-
6
- it "should be ok if error code is 0 and content is not empty" do
7
-
8
- response = Sevendigital::ApiResponse.new
9
- response.error_code = 0
10
- response.content = '<xml></xml>'
11
- response.ok?.should == true
12
-
13
- end
14
-
15
- it "should not be ok if error code is not 0" do
16
-
17
- response = Sevendigital::ApiResponse.new
18
- response.error_code = 5
19
- response.content = '<xml></xml>'
20
- response.ok?.should == false
21
-
22
- end
23
-
24
- it "should not be ok if response content is nil" do
25
-
26
- response = Sevendigital::ApiResponse.new
27
- response.error_code = 0
28
- response.ok?.should == false
29
-
30
- end
31
-
1
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
2
+
3
+ describe "ApiResponse" do
4
+
5
+ it "should be ok if error code is 0 and content is not empty" do
6
+
7
+ response = Sevendigital::ApiResponse.new
8
+ response.error_code = 0
9
+ response.content = '<xml></xml>'
10
+ response.ok?.should == true
11
+
12
+ end
13
+
14
+ it "should not be ok if error code is not 0" do
15
+
16
+ response = Sevendigital::ApiResponse.new
17
+ response.error_code = 5
18
+ response.content = '<xml></xml>'
19
+ response.ok?.should == false
20
+
21
+ end
22
+
23
+ it "should not be ok if response content is nil" do
24
+
25
+ response = Sevendigital::ApiResponse.new
26
+ response.error_code = 0
27
+ response.ok?.should == false
28
+
29
+ end
30
+
31
+ it "should be serializable" do
32
+ original_response = Sevendigital::ApiResponseDigestor.new(@client).from_xml\
33
+ ("<response status='ok'><testElement id='123'>value</testElement></response>")
34
+ original_response.error_code = 99
35
+
36
+ tmp = Marshal.dump(original_response)
37
+ restored_response = Marshal.load(tmp)
38
+
39
+ restored_response.error_code.should == original_response.error_code
40
+ restored_response.content.should == original_response.content
41
+ restored_response.content.test_element.value.should == "value"
42
+
43
+ end
44
+
32
45
  end
@@ -1,122 +1,167 @@
1
- require "spec"
2
- require "date"
3
- require 'sevendigital'
4
-
5
- describe "Artist" do
6
-
7
- before do
8
- @client = stub(Sevendigital::Client)
9
- @artist_manager = mock(Sevendigital::ArtistManager)
10
- @client.stub!(:artist).and_return @artist_manager
11
-
12
- @artist = Sevendigital::Artist.new(@client)
13
- @artist.id = 1234
14
- end
15
-
16
- it "get_details should get artist's basic details from manager" do
17
- expected_options = {:page => 2}
18
- fresh_artist = fake_artist_with_details
19
-
20
- @artist_manager.should_receive(:get_details) { |artist_id, options|
21
- artist_id.should == @artist.id
22
- (options.keys & expected_options.keys).should == expected_options.keys
23
- fresh_artist
24
- }
25
- @artist.get_details(expected_options)
26
-
27
- @artist.sort_name.should == fresh_artist.sort_name
28
- @artist.image.should == fresh_artist.image
29
- @artist.url.should == fresh_artist.url
30
-
31
- end
32
-
33
- it "get_releases should get releases from manager" do
34
- expected_options = {:page => 2}
35
-
36
- @artist_manager.should_receive(:get_releases) { |artist_id, options|
37
- artist_id.should == @artist.id
38
- (options.keys & expected_options.keys).should == expected_options.keys
39
- fake_release_list
40
- }
41
- @artist.get_releases(expected_options)
42
-
43
- end
44
-
45
- it "get_releases should link all releases back to artist itself" do
46
-
47
- @artist_manager.should_receive(:get_releases) { |artist_id, options|
48
- artist_id.should == @artist.id
49
- fake_release_list
50
- }
51
-
52
- releases = @artist.get_releases()
53
- releases.all?{|release| release.artist == @artist}.should == true
54
-
55
- end
56
-
57
- it "get_top_tracks should get tracks from manager" do
58
- expected_options = {:page => 2}
59
-
60
- @artist_manager.should_receive(:get_top_tracks) { |artist_id, options|
61
- artist_id.should == @artist.id
62
- (options.keys & expected_options.keys).should == expected_options.keys
63
- fake_track_list
64
- }
65
- @artist.get_top_tracks(expected_options)
66
-
67
- end
68
-
69
- it "get_top_tracks should link all tracks back to artist itself" do
70
-
71
- @artist_manager.should_receive(:get_top_tracks) { |artist_id, options|
72
- artist_id.should == @artist.id
73
- fake_track_list
74
- }
75
-
76
- tracks = @artist.get_top_tracks()
77
-
78
- tracks.all?{|track| track.artist == @artist}.should == true
79
-
80
- end
81
-
82
- it "get_similar should get similar artists from manager" do
83
- expected_options = {:page => 2}
84
-
85
- @artist_manager.should_receive(:get_similar) { |artist_id, options|
86
- artist_id.should == @artist.id
87
- (options.keys & expected_options.keys).should == expected_options.keys
88
- fake_artist_list
89
- }
90
- @artist.get_similar(expected_options)
91
-
92
- end
93
-
94
- def fake_track_list
95
- tracks = Array.new
96
- tracks << Sevendigital::Track.new(@client)
97
- tracks << Sevendigital::Track.new(@client)
98
- tracks
99
- end
100
-
101
- def fake_release_list
102
- releases = Array.new
103
- releases << Sevendigital::Release.new(@client)
104
- releases << Sevendigital::Release.new(@client)
105
- releases
106
- end
107
-
108
- def fake_artist_list
109
- artists = Array.new
110
- artists << Sevendigital::Artist.new(@client)
111
- artists << Sevendigital::Artist.new(@client)
112
- artists
113
- end
114
-
115
- def fake_artist_with_details
116
- artist = Sevendigital::Artist.new(@client)
117
- artist.sort_name = "The, The"
118
- artist.image = "image"
119
- artist.url = "url"
120
- artist
121
- end
1
+ require "date"
2
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
3
+
4
+ describe "Artist" do
5
+
6
+ before do
7
+ @client = stub(Sevendigital::Client)
8
+ @artist_manager = mock(Sevendigital::ArtistManager)
9
+ @client.stub!(:artist).and_return @artist_manager
10
+
11
+ @artist = Sevendigital::Artist.new(@client)
12
+ @artist.id = 1234
13
+ end
14
+
15
+ it "get_details should get artist's basic details from manager" do
16
+ expected_options = {:page => 2}
17
+ fresh_artist = fake_artist_with_details
18
+
19
+ @artist_manager.should_receive(:get_details) { |artist_id, options|
20
+ artist_id.should == @artist.id
21
+ (options.keys & expected_options.keys).should == expected_options.keys
22
+ fresh_artist
23
+ }
24
+ @artist.get_details(expected_options)
25
+
26
+ @artist.sort_name.should == fresh_artist.sort_name
27
+ @artist.image.should == fresh_artist.image
28
+ @artist.url.should == fresh_artist.url
29
+
30
+ end
31
+
32
+ it "get_releases should get releases from manager" do
33
+ expected_options = {:page => 2}
34
+
35
+ @artist_manager.should_receive(:get_releases) { |artist_id, options|
36
+ artist_id.should == @artist.id
37
+ (options.keys & expected_options.keys).should == expected_options.keys
38
+ fake_release_list
39
+ }
40
+ @artist.get_releases(expected_options)
41
+
42
+ end
43
+
44
+ it "get_releases should link all releases back to artist itself" do
45
+
46
+ @artist_manager.should_receive(:get_releases) { |artist_id, options|
47
+ artist_id.should == @artist.id
48
+ fake_release_list
49
+ }
50
+
51
+ releases = @artist.get_releases()
52
+ releases.all?{|release| release.artist == @artist}.should == true
53
+
54
+ end
55
+
56
+ it "get_top_tracks should get tracks from manager" do
57
+ expected_options = {:page => 2}
58
+
59
+ @artist_manager.should_receive(:get_top_tracks) { |artist_id, options|
60
+ artist_id.should == @artist.id
61
+ (options.keys & expected_options.keys).should == expected_options.keys
62
+ fake_track_list
63
+ }
64
+ @artist.get_top_tracks(expected_options)
65
+
66
+ end
67
+
68
+ it "get_top_tracks should link all tracks back to artist itself" do
69
+
70
+ @artist_manager.should_receive(:get_top_tracks) { |artist_id, options|
71
+ artist_id.should == @artist.id
72
+ fake_track_list
73
+ }
74
+
75
+ tracks = @artist.get_top_tracks()
76
+
77
+ tracks.all?{|track| track.artist == @artist}.should == true
78
+
79
+ end
80
+
81
+ it "get_similar should get similar artists from manager" do
82
+ expected_options = {:page => 2}
83
+
84
+ @artist_manager.should_receive(:get_similar) { |artist_id, options|
85
+ artist_id.should == @artist.id
86
+ (options.keys & expected_options.keys).should == expected_options.keys
87
+ fake_artist_list
88
+ }
89
+ @artist.get_similar(expected_options)
90
+
91
+ end
92
+
93
+ it "should be a various artist if name contains various" do
94
+
95
+ @artist.name = "various"
96
+ @artist.various?.should == true
97
+
98
+ end
99
+
100
+ it "should be a various artist if appears as contains various" do
101
+
102
+ @artist.name = "mr"
103
+ @artist.appears_as = "mr various"
104
+ @artist.various?.should == true
105
+
106
+ end
107
+
108
+ it "should be a various artist if resembles various artist" do
109
+
110
+ @artist.name = "v.a."
111
+ @artist.various?.should == true
112
+ @artist.name = "vario"
113
+ @artist.various?.should == true
114
+ @artist.name = "vaious"
115
+ @artist.various?.should == true
116
+ @artist.name = "varios"
117
+ @artist.various?.should == true
118
+ @artist.name = "aaaa"
119
+ @artist.various?.should == false
120
+ @artist.name = "vaious"
121
+ @artist.various?.should == true
122
+ @artist.name = "varoius"
123
+ @artist.various?.should == true
124
+ @artist.name = "variuos"
125
+ @artist.various?.should == true
126
+
127
+ end
128
+
129
+ it "should not be a various artist if it doesn't resemble various artist" do
130
+
131
+ @artist.name = "mr small"
132
+ @artist.appears_as = "mr big"
133
+ @artist.various?.should == false
134
+
135
+ end
136
+
137
+
138
+
139
+ def fake_track_list
140
+ tracks = Array.new
141
+ tracks << Sevendigital::Track.new(@client)
142
+ tracks << Sevendigital::Track.new(@client)
143
+ tracks
144
+ end
145
+
146
+ def fake_release_list
147
+ releases = Array.new
148
+ releases << Sevendigital::Release.new(@client)
149
+ releases << Sevendigital::Release.new(@client)
150
+ releases
151
+ end
152
+
153
+ def fake_artist_list
154
+ artists = Array.new
155
+ artists << Sevendigital::Artist.new(@client)
156
+ artists << Sevendigital::Artist.new(@client)
157
+ artists
158
+ end
159
+
160
+ def fake_artist_with_details
161
+ artist = Sevendigital::Artist.new(@client)
162
+ artist.sort_name = "The, The"
163
+ artist.image = "image"
164
+ artist.url = "url"
165
+ artist
166
+ end
122
167
  end