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,107 +1,105 @@
|
|
1
|
-
#
|
2
|
-
require '
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
track
|
37
|
-
track.id.should ==
|
38
|
-
track.
|
39
|
-
track.artist.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
track
|
49
|
-
track.
|
50
|
-
track.
|
51
|
-
track.
|
52
|
-
track.artist.
|
53
|
-
track.
|
54
|
-
track.
|
55
|
-
track.
|
56
|
-
track.
|
57
|
-
track.
|
58
|
-
track.
|
59
|
-
track.
|
60
|
-
track.
|
61
|
-
track.price.
|
62
|
-
track.price.
|
63
|
-
track.price.
|
64
|
-
track.price.
|
65
|
-
track.price.
|
66
|
-
track.
|
67
|
-
track
|
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
|
-
tracks
|
97
|
-
tracks[
|
98
|
-
tracks[
|
99
|
-
tracks
|
100
|
-
tracks
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
require 'date'
|
3
|
+
require File.join(File.dirname(__FILE__), %w[../spec_helper])
|
4
|
+
|
5
|
+
describe "TrackDigestor" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@track_digestor = Sevendigital::TrackDigestor.new(Sevendigital::Client.new(nil))
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not digest from invalid xml but throw up (exception)" do
|
12
|
+
|
13
|
+
xml_response = <<XML
|
14
|
+
<artist id="123">
|
15
|
+
<name>expected artist name</name>
|
16
|
+
</artist>
|
17
|
+
XML
|
18
|
+
|
19
|
+
running {@track_digestor.from_xml(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should digest track xml and populate minimum available properties" do
|
23
|
+
|
24
|
+
xml_response = <<XML
|
25
|
+
<track id="123">
|
26
|
+
<title>expected track title</title>
|
27
|
+
<artist id="345">
|
28
|
+
<name>expected artist name</name>
|
29
|
+
<appearsAs>expected displayed artist name</appearsAs>
|
30
|
+
</artist>
|
31
|
+
</track>
|
32
|
+
XML
|
33
|
+
|
34
|
+
track = @track_digestor.from_xml(xml_response)
|
35
|
+
track.id.should == 123
|
36
|
+
track.title.should == "expected track title"
|
37
|
+
track.artist.id.should == 345
|
38
|
+
track.artist.name.should == "expected artist name"
|
39
|
+
track.artist.appears_as == "expected displayed artist name"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should digest track xml and populate all available properties" do
|
43
|
+
|
44
|
+
xml_response = load_sample_object_xml("track")
|
45
|
+
|
46
|
+
track = @track_digestor.from_xml(xml_response)
|
47
|
+
track.id.should == 1628015
|
48
|
+
track.title.should == "Burning"
|
49
|
+
track.version.should == ""
|
50
|
+
track.artist.id.should == 29755
|
51
|
+
track.artist.name.should == "The Whitest Boy Alive"
|
52
|
+
track.artist.appears_as.should == "The Whitest Boy Alive"
|
53
|
+
track.track_number.should == 1
|
54
|
+
track.duration.should == 189
|
55
|
+
track.explicit_content.should == false
|
56
|
+
track.isrc.should == "DED620600065"
|
57
|
+
track.release.id.should == 155408
|
58
|
+
track.release.title.should == "Dreams"
|
59
|
+
track.price.currency_code.should == :GBP
|
60
|
+
track.price.currency_symbol.should == "£"
|
61
|
+
track.price.value.should == 0.79
|
62
|
+
track.price.formatted_price.should == "£0.79"
|
63
|
+
track.price.rrp.should == 0.79
|
64
|
+
track.price.formatted_rrp.should == "£0.79"
|
65
|
+
track.price.on_sale.should == false
|
66
|
+
track.url.should == "http://www.7digital.com/artists/the-whitest-boy-alive/dreams-1/01-Burning/?partner=123"
|
67
|
+
track
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should digest xml containing list of tracks and return an array" do
|
71
|
+
|
72
|
+
xml_response = <<XML
|
73
|
+
<results>
|
74
|
+
<page>1</page>
|
75
|
+
<pageSize>2</pageSize>
|
76
|
+
<totalItems>50</totalItems>
|
77
|
+
<track id="123">
|
78
|
+
<title>expected track title</title>
|
79
|
+
<artist id="345">
|
80
|
+
<name>expected artist name</name>
|
81
|
+
<appearsAs>expected displayed artist name</appearsAs>
|
82
|
+
</artist>
|
83
|
+
</track>
|
84
|
+
<track id="456">
|
85
|
+
<title>expected track title</title>
|
86
|
+
<artist id="789">
|
87
|
+
<name>expected artist name</name>
|
88
|
+
<appearsAs>expected displayed artist name</appearsAs>
|
89
|
+
</artist>
|
90
|
+
</track>
|
91
|
+
</results>
|
92
|
+
XML
|
93
|
+
|
94
|
+
tracks = @track_digestor.list_from_xml(xml_response, :results)
|
95
|
+
tracks[0].id.should == 123
|
96
|
+
tracks[0].artist.id.should == 345
|
97
|
+
tracks[1].id.should == 456
|
98
|
+
tracks[1].artist.id.should == 789
|
99
|
+
tracks.size.should == 2
|
100
|
+
tracks.total_entries.should == 50
|
101
|
+
|
102
|
+
|
103
|
+
end
|
104
|
+
|
107
105
|
end
|
@@ -1,108 +1,129 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@client
|
8
|
-
@
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
api_request.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
artist
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
api_request.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
releases
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
api_request.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
tracks
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
api_request.
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
artists
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
.
|
94
|
-
.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
api_request.
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
releases
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
1
|
+
require File.join(File.dirname(__FILE__), %w[../spec_helper])
|
2
|
+
|
3
|
+
describe "ArtistManager" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = stub(Sevendigital::Client)
|
7
|
+
@client.stub!(:operator).and_return(mock(Sevendigital::ApiOperator))
|
8
|
+
@artist_manager = Sevendigital::ArtistManager.new(@client)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "get_details should call artist/details api method and return digested artist" do
|
12
|
+
an_artist_id = 123
|
13
|
+
an_artist = Sevendigital::Artist.new(@client)
|
14
|
+
an_api_response = fake_api_response("release/details")
|
15
|
+
|
16
|
+
mock_client_digestor(@client, :artist_digestor) \
|
17
|
+
.should_receive(:from_xml).with(an_api_response.content.artist).and_return(an_artist)
|
18
|
+
|
19
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
20
|
+
api_request.api_method.should == "artist/details"
|
21
|
+
api_request.parameters[:artistId].should == an_artist_id
|
22
|
+
an_api_response
|
23
|
+
}
|
24
|
+
|
25
|
+
artist = @artist_manager.get_details(an_artist_id)
|
26
|
+
artist.should == an_artist
|
27
|
+
end
|
28
|
+
|
29
|
+
it "get_releases should call artist/releases api method and return list of digested releases" do
|
30
|
+
an_artist_id = 123
|
31
|
+
a_list_of_releases = [Sevendigital::Release.new(@client), Sevendigital::Release.new(@client)]
|
32
|
+
an_api_response = fake_api_response("artist/releases")
|
33
|
+
|
34
|
+
mock_client_digestor(@client, :release_digestor) \
|
35
|
+
.should_receive(:list_from_xml).with(an_api_response.content.releases).and_return(a_list_of_releases)
|
36
|
+
|
37
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
38
|
+
api_request.api_method.should == "artist/releases"
|
39
|
+
api_request.parameters[:artistId].should == an_artist_id
|
40
|
+
an_api_response
|
41
|
+
}
|
42
|
+
|
43
|
+
releases = @artist_manager.get_releases(an_artist_id)
|
44
|
+
releases.should == a_list_of_releases
|
45
|
+
end
|
46
|
+
|
47
|
+
it "get_top_tracks should call artist/toptracks method and digest the returned list of tracks" do
|
48
|
+
an_artist_id = 123
|
49
|
+
a_top_tracks_list = [Sevendigital::Track.new(@client)]
|
50
|
+
an_api_response = fake_api_response("artist/toptracks")
|
51
|
+
|
52
|
+
mock_client_digestor(@client, :track_digestor) \
|
53
|
+
.should_receive(:list_from_xml).with(an_api_response.content.tracks).and_return(a_top_tracks_list)
|
54
|
+
|
55
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
56
|
+
api_request.api_method.should == "artist/toptracks"
|
57
|
+
api_request.parameters[:artistId].should == an_artist_id
|
58
|
+
an_api_response
|
59
|
+
}
|
60
|
+
|
61
|
+
tracks = @artist_manager.get_top_tracks(an_artist_id)
|
62
|
+
tracks.should == a_top_tracks_list
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
it "get_similar should call artist/similar method and digest the returned list of artists" do
|
67
|
+
an_artist_id = 123
|
68
|
+
a_similar_artists_list = [Sevendigital::Artist.new(@client), Sevendigital::Artist.new(@client)]
|
69
|
+
an_api_response = fake_api_response("artist/similar")
|
70
|
+
|
71
|
+
mock_client_digestor(@client, :artist_digestor) \
|
72
|
+
.should_receive(:list_from_xml).with(an_api_response.content.artists).and_return(a_similar_artists_list)
|
73
|
+
|
74
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
75
|
+
api_request.api_method.should == "artist/similar"
|
76
|
+
api_request.parameters[:artistId].should == an_artist_id
|
77
|
+
an_api_response
|
78
|
+
}
|
79
|
+
|
80
|
+
artists = @artist_manager.get_similar(an_artist_id)
|
81
|
+
artists.should == a_similar_artists_list
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
it "get_top_by_tag should call artist/byTag/top api method and digest the nested artist list from response" do
|
86
|
+
|
87
|
+
tags = "alternative-indie"
|
88
|
+
api_response = fake_api_response("artist/byTag/top")
|
89
|
+
a_release_list = []
|
90
|
+
|
91
|
+
mock_client_digestor(@client, :artist_digestor) \
|
92
|
+
.should_receive(:nested_list_from_xml) \
|
93
|
+
.with(api_response.content.tagged_results, :tagged_item, :tagged_results) \
|
94
|
+
.and_return(a_release_list)
|
95
|
+
|
96
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
97
|
+
api_request.api_method.should == "artist/byTag/top"
|
98
|
+
api_request.parameters[:tags].should == tags
|
99
|
+
api_response
|
100
|
+
}
|
101
|
+
|
102
|
+
releases = @artist_manager.get_top_by_tag(tags)
|
103
|
+
releases.should == a_release_list
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
it "search should call artist/search api method and digest the nested artist list from response" do
|
108
|
+
|
109
|
+
query = "radiohead"
|
110
|
+
api_response = fake_api_response("artist/search")
|
111
|
+
an_artist_list = []
|
112
|
+
|
113
|
+
mock_client_digestor(@client, :artist_digestor) \
|
114
|
+
.should_receive(:nested_list_from_xml) \
|
115
|
+
.with(api_response.content.search_results, :search_result, :search_results) \
|
116
|
+
.and_return(an_artist_list)
|
117
|
+
|
118
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
119
|
+
api_request.api_method.should == "artist/search"
|
120
|
+
api_request.parameters[:q].should == query
|
121
|
+
api_response
|
122
|
+
}
|
123
|
+
|
124
|
+
artists = @artist_manager.search(query)
|
125
|
+
artists.should == an_artist_list
|
126
|
+
|
127
|
+
end
|
128
|
+
|
108
129
|
end
|
@@ -1,178 +1,222 @@
|
|
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
|
-
api_request.
|
45
|
-
api_request.parameters[:
|
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 "
|
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
|
-
api_request.
|
104
|
-
api_request.parameters[:
|
105
|
-
api_response
|
106
|
-
}
|
107
|
-
|
108
|
-
tracks = @release_manager.
|
109
|
-
tracks.should ==
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
it "get_by_date should call release/tracks with
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
api_request.
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
.with(api_response.content.
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
api_request.
|
146
|
-
api_request.parameters
|
147
|
-
api_response
|
148
|
-
}
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
api_response = fake_api_response("release/
|
159
|
-
a_release_list = []
|
160
|
-
|
161
|
-
mock_client_digestor(@client, :release_digestor) \
|
162
|
-
.should_receive(:nested_list_from_xml) \
|
163
|
-
.with(api_response.content.
|
164
|
-
.and_return(a_release_list)
|
165
|
-
|
166
|
-
@client.operator.should_receive(:call_api) { |api_request|
|
167
|
-
api_request.api_method.should == "release/
|
168
|
-
api_request.parameters[:
|
169
|
-
api_response
|
170
|
-
}
|
171
|
-
|
172
|
-
releases = @release_manager.
|
173
|
-
releases.should == a_release_list
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
|
-
|
178
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'date'
|
3
|
+
require File.join(File.dirname(__FILE__), %w[../spec_helper])
|
4
|
+
|
5
|
+
describe "ReleaseManager" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
|
9
|
+
@client = stub(Sevendigital::Client)
|
10
|
+
@client.stub!(:operator).and_return(mock(Sevendigital::ApiOperator))
|
11
|
+
@release_manager = Sevendigital::ReleaseManager.new(@client)
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should get release by release id" do
|
16
|
+
expected_release_id = 123
|
17
|
+
api_response = fake_api_response("release/details")
|
18
|
+
a_release = Sevendigital::Release.new(@client)
|
19
|
+
|
20
|
+
mock_client_digestor(@client, :release_digestor) \
|
21
|
+
.should_receive(:from_xml).with(api_response.content.release).and_return(a_release)
|
22
|
+
|
23
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
24
|
+
api_request.api_method.should == "release/details"
|
25
|
+
api_request.parameters[:releaseId].should == expected_release_id
|
26
|
+
api_response
|
27
|
+
}
|
28
|
+
|
29
|
+
@release_manager.get_details(expected_release_id).should == a_release
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
it "get_tracks should call release/tracks api method and digest the track list from response" do
|
34
|
+
expected_options = {:page_size => 20}
|
35
|
+
a_release_id = 123
|
36
|
+
api_response = fake_api_response("release/tracks")
|
37
|
+
a_track_list = []
|
38
|
+
|
39
|
+
mock_client_digestor(@client, :track_digestor) \
|
40
|
+
.should_receive(:list_from_xml).with(api_response.content.tracks).and_return(a_track_list)
|
41
|
+
|
42
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
43
|
+
api_request.api_method.should == "release/tracks"
|
44
|
+
api_request.parameters[:releaseId].should == a_release_id
|
45
|
+
api_request.parameters[:pageSize].should == 20
|
46
|
+
api_response
|
47
|
+
}
|
48
|
+
|
49
|
+
tracks = @release_manager.get_tracks(a_release_id, expected_options)
|
50
|
+
tracks.should == a_track_list
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
it "get_tracks should call use page size 100 by default" do
|
55
|
+
|
56
|
+
a_release_id = 123
|
57
|
+
api_response = fake_api_response("release/tracks")
|
58
|
+
a_track_list = []
|
59
|
+
|
60
|
+
mock_client_digestor(@client, :track_digestor) \
|
61
|
+
.should_receive(:list_from_xml).with(api_response.content.tracks).and_return(a_track_list)
|
62
|
+
|
63
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
64
|
+
api_request.api_method.should == "release/tracks"
|
65
|
+
api_request.parameters[:releaseId].should == a_release_id
|
66
|
+
api_request.parameters[:pageSize].should == 100
|
67
|
+
api_response
|
68
|
+
}
|
69
|
+
|
70
|
+
tracks = @release_manager.get_tracks(a_release_id)
|
71
|
+
tracks.should == a_track_list
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
it "get_chart should call release/chart api method and digest the release list from response" do
|
77
|
+
|
78
|
+
api_response = fake_api_response("release/chart")
|
79
|
+
a_chart = []
|
80
|
+
|
81
|
+
mock_client_digestor(@client, :chart_item_digestor) \
|
82
|
+
.should_receive(:list_from_xml).with(api_response.content.chart).and_return(a_chart)
|
83
|
+
|
84
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
85
|
+
api_request.api_method.should == "release/chart"
|
86
|
+
api_response
|
87
|
+
}
|
88
|
+
|
89
|
+
chart = @release_manager.get_chart
|
90
|
+
chart.should == a_chart
|
91
|
+
end
|
92
|
+
|
93
|
+
it "get_latest should call release/tracks api method and digest the track list from response" do
|
94
|
+
|
95
|
+
a_release_id = 123
|
96
|
+
api_response = fake_api_response("release/tracks")
|
97
|
+
a_track_list = []
|
98
|
+
|
99
|
+
mock_client_digestor(@client, :track_digestor) \
|
100
|
+
.should_receive(:list_from_xml).with(api_response.content.tracks).and_return(a_track_list)
|
101
|
+
|
102
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
103
|
+
api_request.api_method.should == "release/tracks"
|
104
|
+
api_request.parameters[:releaseId].should == a_release_id
|
105
|
+
api_response
|
106
|
+
}
|
107
|
+
|
108
|
+
tracks = @release_manager.get_tracks(a_release_id)
|
109
|
+
tracks.should == a_track_list
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
it "get_by_date should call release/tracks with supplied parameters and digest the release list from response" do
|
114
|
+
|
115
|
+
from_date = DateTime.new(2010, 01, 01)
|
116
|
+
to_date = DateTime.new(2010, 05, 01)
|
117
|
+
api_response = fake_api_response("release/bydate")
|
118
|
+
a_release_list = []
|
119
|
+
|
120
|
+
mock_client_digestor(@client, :release_digestor) \
|
121
|
+
.should_receive(:list_from_xml).with(api_response.content.releases).and_return(a_release_list)
|
122
|
+
|
123
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
124
|
+
api_request.api_method.should == "release/byDate"
|
125
|
+
api_request.parameters[:fromDate].should == from_date.strftime("%Y%m%d")
|
126
|
+
api_request.parameters[:toDate].should == to_date.strftime("%Y%m%d")
|
127
|
+
api_response
|
128
|
+
}
|
129
|
+
|
130
|
+
tracks = @release_manager.get_by_date(from_date, to_date)
|
131
|
+
tracks.should == a_release_list
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
it "get_by_date should call release/tracks with no parameters and digest the release list from response" do
|
136
|
+
|
137
|
+
api_response = fake_api_response("release/bydate")
|
138
|
+
a_release_list = []
|
139
|
+
|
140
|
+
mock_client_digestor(@client, :release_digestor) \
|
141
|
+
.should_receive(:list_from_xml).with(api_response.content.releases).and_return(a_release_list)
|
142
|
+
|
143
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
144
|
+
api_request.api_method.should == "release/byDate"
|
145
|
+
api_request.parameters.has_key?(:fromDate).should == false
|
146
|
+
api_request.parameters.has_key?(:toDate).should == false
|
147
|
+
api_response
|
148
|
+
}
|
149
|
+
|
150
|
+
tracks = @release_manager.get_by_date
|
151
|
+
tracks.should == a_release_list
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
it "get_recommendations should call release/recommend api method and digest the nested release list from response" do
|
156
|
+
|
157
|
+
a_release_id = 123
|
158
|
+
api_response = fake_api_response("release/recommend")
|
159
|
+
a_release_list = []
|
160
|
+
|
161
|
+
mock_client_digestor(@client, :release_digestor) \
|
162
|
+
.should_receive(:nested_list_from_xml) \
|
163
|
+
.with(api_response.content.recommendations, :recommended_item, :recommendations) \
|
164
|
+
.and_return(a_release_list)
|
165
|
+
|
166
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
167
|
+
api_request.api_method.should == "release/recommend"
|
168
|
+
api_request.parameters[:releaseId].should == a_release_id
|
169
|
+
api_response
|
170
|
+
}
|
171
|
+
|
172
|
+
releases = @release_manager.get_recommendations(a_release_id)
|
173
|
+
releases.should == a_release_list
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
it "get_top_by_tag should call release/byTag/top api method and digest the nested release list from response" do
|
178
|
+
|
179
|
+
tags = "alternative-indie"
|
180
|
+
api_response = fake_api_response("release/byTag/top")
|
181
|
+
a_release_list = []
|
182
|
+
|
183
|
+
mock_client_digestor(@client, :release_digestor) \
|
184
|
+
.should_receive(:nested_list_from_xml) \
|
185
|
+
.with(api_response.content.tagged_results, :tagged_item, :tagged_results) \
|
186
|
+
.and_return(a_release_list)
|
187
|
+
|
188
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
189
|
+
api_request.api_method.should == "release/byTag/top"
|
190
|
+
api_request.parameters[:tags].should == tags
|
191
|
+
api_response
|
192
|
+
}
|
193
|
+
|
194
|
+
releases = @release_manager.get_top_by_tag(tags)
|
195
|
+
releases.should == a_release_list
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
it "search should call release/search api method and digest the nested release list from response" do
|
200
|
+
|
201
|
+
query = "radiohead"
|
202
|
+
api_response = fake_api_response("release/search")
|
203
|
+
a_release_list = []
|
204
|
+
|
205
|
+
mock_client_digestor(@client, :release_digestor) \
|
206
|
+
.should_receive(:nested_list_from_xml) \
|
207
|
+
.with(api_response.content.search_results, :search_result, :search_results) \
|
208
|
+
.and_return(a_release_list)
|
209
|
+
|
210
|
+
@client.operator.should_receive(:call_api) { |api_request|
|
211
|
+
api_request.api_method.should == "release/search"
|
212
|
+
api_request.parameters[:q].should == query
|
213
|
+
api_response
|
214
|
+
}
|
215
|
+
|
216
|
+
releases = @release_manager.search(query)
|
217
|
+
releases.should == a_release_list
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
end
|