7digital 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -7
- data/lib/sevendigital.rb +54 -53
- data/lib/sevendigital/api_operator.rb +33 -30
- data/lib/sevendigital/api_operator_cached.rb +23 -23
- data/lib/sevendigital/api_request.rb +23 -23
- data/lib/sevendigital/client.rb +136 -124
- data/lib/sevendigital/default_configuration.yml +2 -2
- data/lib/sevendigital/digestion_tract/api_response_digestor.rb +52 -52
- data/lib/sevendigital/digestion_tract/artist_digestor.rb +31 -31
- data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +27 -27
- data/lib/sevendigital/digestion_tract/digestor.rb +66 -66
- data/lib/sevendigital/digestion_tract/format_digestor.rb +21 -21
- data/lib/sevendigital/digestion_tract/label_digestor.rb +19 -19
- data/lib/sevendigital/digestion_tract/pager_digestor.rb +23 -23
- data/lib/sevendigital/digestion_tract/price_digestor.rb +24 -24
- data/lib/sevendigital/digestion_tract/release_digestor.rb +52 -52
- data/lib/sevendigital/digestion_tract/track_digestor.rb +37 -37
- data/lib/sevendigital/management/artist_manager.rb +45 -39
- data/lib/sevendigital/management/manager.rb +11 -11
- data/lib/sevendigital/management/release_manager.rb +57 -50
- data/lib/sevendigital/management/track_manager.rb +28 -17
- data/lib/sevendigital/model/api_response.rb +24 -12
- data/lib/sevendigital/model/artist.rb +46 -36
- data/lib/sevendigital/model/chart_item.rb +9 -9
- data/lib/sevendigital/model/format.rb +9 -9
- data/lib/sevendigital/model/label.rb +9 -9
- data/lib/sevendigital/model/price.rb +11 -11
- data/lib/sevendigital/model/release.rb +33 -33
- data/lib/sevendigital/model/sevendigital_error.rb +3 -3
- data/lib/sevendigital/model/sevendigital_object.rb +51 -51
- data/lib/sevendigital/model/track.rb +28 -7
- data/lib/sevendigital/pager.rb +16 -16
- data/lib/sevendigital/peachy_patch.rb +19 -0
- data/lib/sevendigital/proxy_police.rb +23 -23
- data/spec/api_operator_cached_spec.rb +47 -46
- data/spec/api_operator_spec.rb +114 -107
- data/spec/api_request_spec.rb +26 -27
- data/spec/client_spec.rb +75 -45
- data/spec/data/config/sevendigital.yml +5 -5
- data/spec/data/configuration_env_override.yml +5 -5
- data/spec/digestion_tract/api_response_digestor_spec.rb +78 -74
- data/spec/digestion_tract/artist_digestor_spec.rb +81 -82
- data/spec/digestion_tract/chart_digestor_spec.rb +52 -53
- data/spec/digestion_tract/format_digestor_spec.rb +38 -39
- data/spec/digestion_tract/label_digestor_spec.rb +33 -34
- data/spec/digestion_tract/pager_digestor_spec.rb +50 -51
- data/spec/digestion_tract/price_digestor_spec.rb +57 -57
- data/spec/digestion_tract/release_digestor_spec.rb +101 -102
- data/spec/digestion_tract/track_digestor_spec.rb +104 -106
- data/spec/management/artist_manager_spec.rb +128 -107
- data/spec/management/release_manager_spec.rb +222 -178
- data/spec/management/track_manager_spec.rb +88 -52
- data/spec/model/api_response_spec.rb +44 -31
- data/spec/model/artist_spec.rb +166 -121
- data/spec/model/release_spec.rb +109 -110
- data/spec/model/track_spec.rb +140 -0
- data/spec/pager_spec.rb +7 -8
- data/spec/peachy_spec_helper_patch.rb +7 -0
- data/spec/proxy_police_spec.rb +47 -48
- data/spec/spec_helper.rb +52 -48
- data/spec/test-xml/methods/artist/byTag/top.xml +50 -50
- data/spec/test-xml/methods/artist/details.xml +9 -9
- data/spec/test-xml/methods/artist/releases.xml +544 -544
- data/spec/test-xml/methods/artist/search.xml +19 -0
- data/spec/test-xml/methods/artist/similar.xml +39 -39
- data/spec/test-xml/methods/artist/toptracks.xml +279 -279
- data/spec/test-xml/methods/release/bydate.xml +173 -173
- data/spec/test-xml/methods/release/bytag/top.xml +150 -150
- data/spec/test-xml/methods/release/chart.xml +181 -181
- data/spec/test-xml/methods/release/details.xml +48 -48
- data/spec/test-xml/methods/release/recommend.xml +89 -89
- data/spec/test-xml/methods/release/search.xml +195 -0
- data/spec/test-xml/methods/release/tracks.xml +28 -28
- data/spec/test-xml/methods/track/chart.xml +149 -149
- data/spec/test-xml/methods/track/details.xml +30 -30
- data/spec/test-xml/methods/track/search.xml +160 -0
- data/spec/test-xml/objects/artist.xml +6 -6
- data/spec/test-xml/objects/artist_chart_item.xml +7 -7
- data/spec/test-xml/objects/artist_list.xml +22 -22
- data/spec/test-xml/objects/artist_list_empty.xml +4 -4
- data/spec/test-xml/objects/price.xml +7 -7
- data/spec/test-xml/objects/release.xml +40 -40
- data/spec/test-xml/objects/release_chart_item.xml +39 -34
- data/spec/test-xml/objects/release_list.xml +18 -18
- data/spec/test-xml/objects/release_list_empty.xml +4 -4
- data/spec/test-xml/objects/response.xml +39 -0
- data/spec/test-xml/objects/track.xml +33 -33
- data/spec/test-xml/objects/track_chart_item.xml +27 -27
- metadata +10 -5
- data/lib/peachy_patchy.rb +0 -14
- data/lib/sevendigital/version.rb +0 -3
@@ -1,52 +1,88 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require '
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@client
|
11
|
-
@
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
api_request.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
chart
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
response =
|
9
|
-
response.
|
10
|
-
response.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
response =
|
18
|
-
response.
|
19
|
-
response.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
response =
|
27
|
-
response.
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
data/spec/model/artist_spec.rb
CHANGED
@@ -1,122 +1,167 @@
|
|
1
|
-
require "
|
2
|
-
require
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
@artist =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@artist.
|
28
|
-
@artist.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
releases
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
artist =
|
117
|
-
artist.
|
118
|
-
artist.
|
119
|
-
artist.
|
120
|
-
artist
|
121
|
-
|
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
|