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,107 +1,105 @@
1
- # encoding: UTF-8
2
- require 'spec'
3
- require 'date'
4
- require File.join(File.dirname(__FILE__), %w[../spec_helper])
5
- require "sevendigital"
6
-
7
- describe "TrackDigestor" do
8
-
9
- before do
10
- @track_digestor = Sevendigital::TrackDigestor.new(Sevendigital::Client.new(nil))
11
- end
12
-
13
- it "should not digest from invalid xml but throw up (exception)" do
14
-
15
- xml_response = <<XML
16
- <artist id="123">
17
- <name>expected artist name</name>
18
- </artist>
19
- XML
20
-
21
- running {@track_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
22
- end
23
-
24
- it "should digest track xml and populate minimum available properties" do
25
-
26
- xml_response = <<XML
27
- <track id="123">
28
- <title>expected track title</title>
29
- <artist id="345">
30
- <name>expected artist name</name>
31
- <appearsAs>expected displayed artist name</appearsAs>
32
- </artist>
33
- </track>
34
- XML
35
-
36
- track = @track_digestor.from_xml(xml_response)
37
- track.id.should == 123
38
- track.title.should == "expected track title"
39
- track.artist.id.should == 345
40
- track.artist.name.should == "expected artist name"
41
- track.artist.appears_as == "expected displayed artist name"
42
- end
43
-
44
- it "should digest track xml and populate all available properties" do
45
-
46
- xml_response = load_sample_object_xml("track")
47
-
48
- track = @track_digestor.from_xml(xml_response)
49
- track.id.should == 1628015
50
- track.title.should == "Burning"
51
- track.version.should == ""
52
- track.artist.id.should == 29755
53
- track.artist.name.should == "The Whitest Boy Alive"
54
- track.artist.appears_as.should == "The Whitest Boy Alive"
55
- track.track_number.should == 1
56
- track.duration.should == 189
57
- track.explicit_content.should == false
58
- track.isrc.should == "DED620600065"
59
- track.release.id.should == 155408
60
- track.release.title.should == "Dreams"
61
- track.price.currency_code.should == :GBP
62
- track.price.currency_symbol.should == "£"
63
- track.price.value.should == 0.79
64
- track.price.formatted_price.should == "£0.79"
65
- track.price.rrp.should == 0.79
66
- track.price.formatted_rrp.should == "£0.79"
67
- track.price.on_sale.should == false
68
- track.url.should == "http://www.7digital.com/artists/the-whitest-boy-alive/dreams-1/01-Burning/?partner=123"
69
- track
70
- end
71
-
72
- it "should digest xml containing list of tracks and return an array" do
73
-
74
- xml_response = <<XML
75
- <results>
76
- <page>1</page>
77
- <pageSize>2</pageSize>
78
- <totalItems>50</totalItems>
79
- <track id="123">
80
- <title>expected track title</title>
81
- <artist id="345">
82
- <name>expected artist name</name>
83
- <appearsAs>expected displayed artist name</appearsAs>
84
- </artist>
85
- </track>
86
- <track id="456">
87
- <title>expected track title</title>
88
- <artist id="789">
89
- <name>expected artist name</name>
90
- <appearsAs>expected displayed artist name</appearsAs>
91
- </artist>
92
- </track>
93
- </results>
94
- XML
95
-
96
- tracks = @track_digestor.list_from_xml(xml_response, :results)
97
- tracks[0].id.should == 123
98
- tracks[0].artist.id.should == 345
99
- tracks[1].id.should == 456
100
- tracks[1].artist.id.should == 789
101
- tracks.size.should == 2
102
- tracks.total_entries.should == 50
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 "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
-
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 '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
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