7digital 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/README.rdoc +7 -0
  2. data/lib/peachy_patchy.rb +14 -0
  3. data/lib/sevendigital.rb +53 -0
  4. data/lib/sevendigital/api_operator.rb +31 -0
  5. data/lib/sevendigital/api_operator_cached.rb +23 -0
  6. data/lib/sevendigital/api_request.rb +24 -0
  7. data/lib/sevendigital/client.rb +124 -0
  8. data/lib/sevendigital/default_configuration.yml +2 -0
  9. data/lib/sevendigital/digestion_tract/api_response_digestor.rb +52 -0
  10. data/lib/sevendigital/digestion_tract/artist_digestor.rb +31 -0
  11. data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +27 -0
  12. data/lib/sevendigital/digestion_tract/digestor.rb +66 -0
  13. data/lib/sevendigital/digestion_tract/format_digestor.rb +21 -0
  14. data/lib/sevendigital/digestion_tract/label_digestor.rb +20 -0
  15. data/lib/sevendigital/digestion_tract/pager_digestor.rb +23 -0
  16. data/lib/sevendigital/digestion_tract/price_digestor.rb +25 -0
  17. data/lib/sevendigital/digestion_tract/release_digestor.rb +52 -0
  18. data/lib/sevendigital/digestion_tract/track_digestor.rb +37 -0
  19. data/lib/sevendigital/management/artist_manager.rb +39 -0
  20. data/lib/sevendigital/management/manager.rb +11 -0
  21. data/lib/sevendigital/management/release_manager.rb +51 -0
  22. data/lib/sevendigital/management/track_manager.rb +18 -0
  23. data/lib/sevendigital/model/api_response.rb +13 -0
  24. data/lib/sevendigital/model/artist.rb +37 -0
  25. data/lib/sevendigital/model/chart_item.rb +9 -0
  26. data/lib/sevendigital/model/format.rb +9 -0
  27. data/lib/sevendigital/model/label.rb +9 -0
  28. data/lib/sevendigital/model/price.rb +11 -0
  29. data/lib/sevendigital/model/release.rb +34 -0
  30. data/lib/sevendigital/model/sevendigital_error.rb +3 -0
  31. data/lib/sevendigital/model/sevendigital_object.rb +51 -0
  32. data/lib/sevendigital/model/track.rb +8 -0
  33. data/lib/sevendigital/pager.rb +17 -0
  34. data/lib/sevendigital/proxy_police.rb +24 -0
  35. data/lib/sevendigital/version.rb +3 -0
  36. data/spec/api_operator_cached_spec.rb +47 -0
  37. data/spec/api_operator_spec.rb +108 -0
  38. data/spec/api_request_spec.rb +27 -0
  39. data/spec/client_spec.rb +46 -0
  40. data/spec/data/config/sevendigital.yml +5 -0
  41. data/spec/data/configuration_env_override.yml +5 -0
  42. data/spec/data/configuration_override.yml +1 -0
  43. data/spec/digestion_tract/api_response_digestor_spec.rb +74 -0
  44. data/spec/digestion_tract/artist_digestor_spec.rb +83 -0
  45. data/spec/digestion_tract/chart_digestor_spec.rb +54 -0
  46. data/spec/digestion_tract/format_digestor_spec.rb +40 -0
  47. data/spec/digestion_tract/label_digestor_spec.rb +35 -0
  48. data/spec/digestion_tract/pager_digestor_spec.rb +52 -0
  49. data/spec/digestion_tract/price_digestor_spec.rb +57 -0
  50. data/spec/digestion_tract/release_digestor_spec.rb +102 -0
  51. data/spec/digestion_tract/track_digestor_spec.rb +107 -0
  52. data/spec/management/artist_manager_spec.rb +108 -0
  53. data/spec/management/release_manager_spec.rb +178 -0
  54. data/spec/management/track_manager_spec.rb +52 -0
  55. data/spec/model/api_response_spec.rb +32 -0
  56. data/spec/model/artist_spec.rb +122 -0
  57. data/spec/model/release_spec.rb +111 -0
  58. data/spec/pager_spec.rb +8 -0
  59. data/spec/proxy_police_spec.rb +49 -0
  60. data/spec/spec_helper.rb +48 -0
  61. data/spec/test-xml/methods/artist/byTag/top.xml +51 -0
  62. data/spec/test-xml/methods/artist/details.xml +10 -0
  63. data/spec/test-xml/methods/artist/releases.xml +545 -0
  64. data/spec/test-xml/methods/artist/similar.xml +40 -0
  65. data/spec/test-xml/methods/artist/toptracks.xml +280 -0
  66. data/spec/test-xml/methods/release/bydate.xml +174 -0
  67. data/spec/test-xml/methods/release/bytag/top.xml +151 -0
  68. data/spec/test-xml/methods/release/chart.xml +182 -0
  69. data/spec/test-xml/methods/release/details.xml +49 -0
  70. data/spec/test-xml/methods/release/recommend.xml +90 -0
  71. data/spec/test-xml/methods/release/tracks.xml +29 -0
  72. data/spec/test-xml/methods/track/chart.xml +150 -0
  73. data/spec/test-xml/methods/track/details.xml +31 -0
  74. data/spec/test-xml/objects/artist.xml +7 -0
  75. data/spec/test-xml/objects/artist_chart_item.xml +8 -0
  76. data/spec/test-xml/objects/artist_list.xml +23 -0
  77. data/spec/test-xml/objects/artist_list_empty.xml +5 -0
  78. data/spec/test-xml/objects/price.xml +8 -0
  79. data/spec/test-xml/objects/release.xml +40 -0
  80. data/spec/test-xml/objects/release_chart_item.xml +34 -0
  81. data/spec/test-xml/objects/release_list.xml +19 -0
  82. data/spec/test-xml/objects/release_list_empty.xml +5 -0
  83. data/spec/test-xml/objects/track.xml +34 -0
  84. data/spec/test-xml/objects/track_chart_item.xml +28 -0
  85. metadata +151 -0
@@ -0,0 +1,108 @@
1
+ require "spec"
2
+ require "sevendigital"
3
+
4
+ describe "ArtistManager" do
5
+
6
+ before do
7
+ @client = stub(Sevendigital::Client)
8
+ @client.stub!(:operator).and_return(mock(Sevendigital::ApiOperator))
9
+ @artist_manager = Sevendigital::ArtistManager.new(@client)
10
+ end
11
+
12
+ it "get_details should call artist/details api method and return digested artist" do
13
+ an_artist_id = 123
14
+ an_artist = Sevendigital::Artist.new(@client)
15
+ an_api_response = fake_api_response("release/details")
16
+
17
+ mock_client_digestor(@client, :artist_digestor) \
18
+ .should_receive(:from_xml).with(an_api_response.content.artist).and_return(an_artist)
19
+
20
+ @client.operator.should_receive(:call_api) { |api_request|
21
+ api_request.api_method.should == "artist/details"
22
+ api_request.parameters[:artistId].should == an_artist_id
23
+ an_api_response
24
+ }
25
+
26
+ artist = @artist_manager.get_details(an_artist_id)
27
+ artist.should == an_artist
28
+ end
29
+
30
+ it "get_releases should call artist/releases api method and return list of digested releases" do
31
+ an_artist_id = 123
32
+ a_list_of_releases = [Sevendigital::Release.new(@client), Sevendigital::Release.new(@client)]
33
+ an_api_response = fake_api_response("artist/releases")
34
+
35
+ mock_client_digestor(@client, :release_digestor) \
36
+ .should_receive(:list_from_xml).with(an_api_response.content.releases).and_return(a_list_of_releases)
37
+
38
+ @client.operator.should_receive(:call_api) { |api_request|
39
+ api_request.api_method.should == "artist/releases"
40
+ api_request.parameters[:artistId].should == an_artist_id
41
+ an_api_response
42
+ }
43
+
44
+ releases = @artist_manager.get_releases(an_artist_id)
45
+ releases.should == a_list_of_releases
46
+ end
47
+
48
+ it "get_top_tracks should call artist/toptracks method and digest the returned list of tracks" do
49
+ an_artist_id = 123
50
+ a_top_tracks_list = [Sevendigital::Track.new(@client)]
51
+ an_api_response = fake_api_response("artist/toptracks")
52
+
53
+ mock_client_digestor(@client, :track_digestor) \
54
+ .should_receive(:list_from_xml).with(an_api_response.content.tracks).and_return(a_top_tracks_list)
55
+
56
+ @client.operator.should_receive(:call_api) { |api_request|
57
+ api_request.api_method.should == "artist/toptracks"
58
+ api_request.parameters[:artistId].should == an_artist_id
59
+ an_api_response
60
+ }
61
+
62
+ tracks = @artist_manager.get_top_tracks(an_artist_id)
63
+ tracks.should == a_top_tracks_list
64
+
65
+ end
66
+
67
+ it "get_similar should call artist/similar method and digest the returned list of artists" do
68
+ an_artist_id = 123
69
+ a_similar_artists_list = [Sevendigital::Artist.new(@client), Sevendigital::Artist.new(@client)]
70
+ an_api_response = fake_api_response("artist/similar")
71
+
72
+ mock_client_digestor(@client, :artist_digestor) \
73
+ .should_receive(:list_from_xml).with(an_api_response.content.artists).and_return(a_similar_artists_list)
74
+
75
+ @client.operator.should_receive(:call_api) { |api_request|
76
+ api_request.api_method.should == "artist/similar"
77
+ api_request.parameters[:artistId].should == an_artist_id
78
+ an_api_response
79
+ }
80
+
81
+ artists = @artist_manager.get_similar(an_artist_id)
82
+ artists.should == a_similar_artists_list
83
+
84
+ end
85
+
86
+ it "get_top_by_tag should call artist/byTag/top api method and digest the nested artist list from response" do
87
+
88
+ tags = "alternative-indie"
89
+ api_response = fake_api_response("artist/byTag/top")
90
+ an_artist_list = []
91
+
92
+ mock_client_digestor(@client, :artist_digestor) \
93
+ .should_receive(:nested_list_from_xml) \
94
+ .with(api_response.content.tagged_results, :tagged_item, :tagged_results) \
95
+ .and_return(an_artist_list)
96
+
97
+ @client.operator.should_receive(:call_api) { |api_request|
98
+ api_request.api_method.should == "artist/byTag/top"
99
+ api_request.parameters[:tags].should == tags
100
+ api_response
101
+ }
102
+
103
+ releases = @artist_manager.get_top_by_tag(tags)
104
+ releases.should == an_artist_list
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,178 @@
1
+ # encoding: UTF-8
2
+ require 'spec'
3
+ require 'date'
4
+ require 'sevendigital'
5
+
6
+ describe "ReleaseManager" do
7
+
8
+ before do
9
+
10
+ @client = stub(Sevendigital::Client)
11
+ @client.stub!(:operator).and_return(mock(Sevendigital::ApiOperator))
12
+ @release_manager = Sevendigital::ReleaseManager.new(@client)
13
+
14
+ end
15
+
16
+ it "should get release by release id" do
17
+ expected_release_id = 123
18
+ api_response = fake_api_response("release/details")
19
+ a_release = Sevendigital::Release.new(@client)
20
+
21
+ mock_client_digestor(@client, :release_digestor) \
22
+ .should_receive(:from_xml).with(api_response.content.release).and_return(a_release)
23
+
24
+ @client.operator.should_receive(:call_api) { |api_request|
25
+ api_request.api_method.should == "release/details"
26
+ api_request.parameters[:releaseId].should == expected_release_id
27
+ api_response
28
+ }
29
+
30
+ @release_manager.get_details(expected_release_id).should == a_release
31
+
32
+ end
33
+
34
+ it "get_tracks should call release/tracks api method and digest the track list from response" do
35
+
36
+ a_release_id = 123
37
+ api_response = fake_api_response("release/tracks")
38
+ a_track_list = []
39
+
40
+ mock_client_digestor(@client, :track_digestor) \
41
+ .should_receive(:list_from_xml).with(api_response.content.tracks).and_return(a_track_list)
42
+
43
+ @client.operator.should_receive(:call_api) { |api_request|
44
+ api_request.api_method.should == "release/tracks"
45
+ api_request.parameters[:releaseId].should == a_release_id
46
+ api_response
47
+ }
48
+
49
+ tracks = @release_manager.get_tracks(a_release_id)
50
+ tracks.should == a_track_list
51
+
52
+ end
53
+
54
+ it "get_chart should call release/chart api method and digest the release list from response" do
55
+
56
+ api_response = fake_api_response("release/chart")
57
+ a_chart = []
58
+
59
+ mock_client_digestor(@client, :chart_item_digestor) \
60
+ .should_receive(:list_from_xml).with(api_response.content.chart).and_return(a_chart)
61
+
62
+ @client.operator.should_receive(:call_api) { |api_request|
63
+ api_request.api_method.should == "release/chart"
64
+ api_response
65
+ }
66
+
67
+ chart = @release_manager.get_chart
68
+ chart.should == a_chart
69
+ end
70
+
71
+ it "get_latest should call release/tracks api method and digest the track list from response" do
72
+
73
+ a_release_id = 123
74
+ api_response = fake_api_response("release/tracks")
75
+ a_track_list = []
76
+
77
+ mock_client_digestor(@client, :track_digestor) \
78
+ .should_receive(:list_from_xml).with(api_response.content.tracks).and_return(a_track_list)
79
+
80
+ @client.operator.should_receive(:call_api) { |api_request|
81
+ api_request.api_method.should == "release/tracks"
82
+ api_request.parameters[:releaseId].should == a_release_id
83
+ api_response
84
+ }
85
+
86
+ tracks = @release_manager.get_tracks(a_release_id)
87
+ tracks.should == a_track_list
88
+
89
+ end
90
+
91
+ it "get_by_date should call release/tracks with supplied parameters and digest the release list from response" do
92
+
93
+ from_date = DateTime.new(2010, 01, 01)
94
+ to_date = DateTime.new(2010, 05, 01)
95
+ api_response = fake_api_response("release/bydate")
96
+ a_release_list = []
97
+
98
+ mock_client_digestor(@client, :release_digestor) \
99
+ .should_receive(:list_from_xml).with(api_response.content.releases).and_return(a_release_list)
100
+
101
+ @client.operator.should_receive(:call_api) { |api_request|
102
+ api_request.api_method.should == "release/byDate"
103
+ api_request.parameters[:fromDate].should == from_date.strftime("%Y%m%d")
104
+ api_request.parameters[:toDate].should == to_date.strftime("%Y%m%d")
105
+ api_response
106
+ }
107
+
108
+ tracks = @release_manager.get_by_date(from_date, to_date)
109
+ tracks.should == a_release_list
110
+
111
+ end
112
+
113
+ it "get_by_date should call release/tracks with no parameters and digest the release list from response" do
114
+
115
+ api_response = fake_api_response("release/bydate")
116
+ a_release_list = []
117
+
118
+ mock_client_digestor(@client, :release_digestor) \
119
+ .should_receive(:list_from_xml).with(api_response.content.releases).and_return(a_release_list)
120
+
121
+ @client.operator.should_receive(:call_api) { |api_request|
122
+ api_request.api_method.should == "release/byDate"
123
+ api_request.parameters.has_key?(:fromDate).should == false
124
+ api_request.parameters.has_key?(:toDate).should == false
125
+ api_response
126
+ }
127
+
128
+ tracks = @release_manager.get_by_date
129
+ tracks.should == a_release_list
130
+
131
+ end
132
+
133
+ it "get_recommendations should call release/recommend api method and digest the nested release list from response" do
134
+
135
+ a_release_id = 123
136
+ api_response = fake_api_response("release/recommend")
137
+ a_release_list = []
138
+
139
+ mock_client_digestor(@client, :release_digestor) \
140
+ .should_receive(:nested_list_from_xml) \
141
+ .with(api_response.content.recommendations, :recommended_item, :recommendations) \
142
+ .and_return(a_release_list)
143
+
144
+ @client.operator.should_receive(:call_api) { |api_request|
145
+ api_request.api_method.should == "release/recommend"
146
+ api_request.parameters[:releaseId].should == a_release_id
147
+ api_response
148
+ }
149
+
150
+ releases = @release_manager.get_recommendations(a_release_id)
151
+ releases.should == a_release_list
152
+
153
+ end
154
+
155
+ it "get_top_by_tag should call release/byTag/top api method and digest the nested release list from response" do
156
+
157
+ tags = "alternative-indie"
158
+ api_response = fake_api_response("release/byTag/top")
159
+ a_release_list = []
160
+
161
+ mock_client_digestor(@client, :release_digestor) \
162
+ .should_receive(:nested_list_from_xml) \
163
+ .with(api_response.content.tagged_results, :tagged_item, :tagged_results) \
164
+ .and_return(a_release_list)
165
+
166
+ @client.operator.should_receive(:call_api) { |api_request|
167
+ api_request.api_method.should == "release/byTag/top"
168
+ api_request.parameters[:tags].should == tags
169
+ api_response
170
+ }
171
+
172
+ releases = @release_manager.get_top_by_tag(tags)
173
+ releases.should == a_release_list
174
+
175
+ end
176
+
177
+
178
+ end
@@ -0,0 +1,52 @@
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
@@ -0,0 +1,32 @@
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
+
32
+ end
@@ -0,0 +1,122 @@
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
122
+ end