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,5 +1,5 @@
1
- common:
2
- api_url: test-yml-rails-common.7digital.com
3
-
4
- development:
5
- api_url: test-yml-development.7digital.com
1
+ common:
2
+ api_url: test-yml-rails-common.7digital.com
3
+
4
+ development:
5
+ api_url: test-yml-development.7digital.com
@@ -1,5 +1,5 @@
1
- common:
2
- api_url: test-yml-common.7digital.com
3
-
4
- development:
5
- api_url: test-yml-development.7digital.com
1
+ common:
2
+ api_url: test-yml-common.7digital.com
3
+
4
+ development:
5
+ api_url: test-yml-development.7digital.com
@@ -1,74 +1,78 @@
1
- require 'spec'
2
- require File.join(File.dirname(__FILE__), %w[../spec_helper])
3
-
4
-
5
- describe "ApiResponseDigestor" do
6
-
7
- before do
8
- @api_response_digestor = Sevendigital::ApiResponseDigestor.new(nil)
9
- end
10
-
11
- it "should create a response with body from http ok response" do
12
-
13
- stub_http_response = stub(Net::HTTPSuccess)
14
- stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(true)
15
- stub_http_response.stub!(:body).and_return('<response status="ok"></response>')
16
-
17
- response = @api_response_digestor.from_http_response(stub_http_response)
18
- response.error_code.should == 0
19
- end
20
-
21
- it "should create an error response from http non-ok response" do
22
- expected_message = 'Authorisation failed'
23
- expected_error_code = 401
24
-
25
- stub_http_response = stub(Net::HTTPSuccess)
26
- stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(false)
27
- stub_http_response.stub!(:code).and_return(expected_error_code.to_s)
28
- stub_http_response.stub!(:body).and_return(expected_message)
29
-
30
- response = @api_response_digestor.from_http_response(stub_http_response)
31
- response.error_code.should == 401
32
- response.error_message.should == expected_message
33
-
34
- end
35
-
36
-
37
-
38
- it "should create a response with body from xml ok response" do
39
-
40
- xml_response = <<XML
41
- <response status="ok"><test></test></response>
42
- XML
43
- response = @api_response_digestor.from_xml(xml_response)
44
- response.error_code.should == 0
45
- response.content.test.should_not == nil
46
- response.content.nothing.should == nil
47
- end
48
-
49
-
50
- it "should create a response with error details from xml error response" do
51
-
52
- xml_response = '<response status="error"><error code="1000"><errorMessage>expected error message</errorMessage></error></response>'
53
- response = @api_response_digestor.from_xml(xml_response)
54
- response.error_code.should == 1000
55
- response.error_message.should == 'expected error message'
56
- end
57
-
58
- it "should create a response with error details from invalid xml response" do
59
-
60
- xml_response = '<wrongresponse status="ok"><test /></wrongresponse>'
61
- response = @api_response_digestor.from_xml(xml_response)
62
- response.error_code.should == 10000
63
- response.error_message.should == 'Invalid 7digital API response'
64
- end
65
-
66
- it "should create a response with error details from valid xml response with invalid status" do
67
-
68
- xml_response = '<response status="unkown"><test></test></response>'
69
- response = @api_response_digestor.from_xml(xml_response)
70
- response.error_code.should == 10000
71
- response.error_message.should == 'Invalid 7digital API response'
72
- end
73
-
74
- end
1
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
2
+
3
+ describe "ApiResponseDigestor" do
4
+
5
+ before do
6
+ @api_response_digestor = Sevendigital::ApiResponseDigestor.new(nil)
7
+ end
8
+
9
+ it "should create a response with body from http ok response" do
10
+
11
+ stub_http_response = stub(Net::HTTPSuccess)
12
+ stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(true)
13
+ stub_http_response.stub!(:body).and_return('<response status="ok"></response>')
14
+
15
+ response = @api_response_digestor.from_http_response(stub_http_response)
16
+ response.error_code.should == 0
17
+ end
18
+
19
+ it "should create an error response from http non-ok response" do
20
+ expected_message = 'Authorisation failed'
21
+ expected_error_code = 401
22
+
23
+ stub_http_response = stub(Net::HTTPSuccess)
24
+ stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(false)
25
+ stub_http_response.stub!(:code).and_return(expected_error_code.to_s)
26
+ stub_http_response.stub!(:body).and_return(expected_message)
27
+
28
+ response = @api_response_digestor.from_http_response(stub_http_response)
29
+ response.error_code.should == 401
30
+ response.error_message.should == expected_message
31
+
32
+ end
33
+
34
+
35
+
36
+ it "should create a response with body from xml ok response" do
37
+
38
+ xml_response = <<XML
39
+ <response status="ok"><test>aaa</test></response>
40
+ XML
41
+ response = @api_response_digestor.from_xml(xml_response)
42
+ response.error_code.should == 0
43
+ response.content.test.should_not == nil
44
+ response.content.nothing.should == nil
45
+ end
46
+
47
+
48
+ it "should create a response with error details from xml error response" do
49
+
50
+ xml_response = '<response status="error"><error code="1000"><errorMessage>expected error message</errorMessage></error></response>'
51
+ response = @api_response_digestor.from_xml(xml_response)
52
+ response.error_code.should == 1000
53
+ response.error_message.should == 'expected error message'
54
+ end
55
+
56
+ it "should create a response with error details from invalid xml response" do
57
+
58
+ xml_response = '<wrongresponse status="ok"><test /></wrongresponse>'
59
+ response = @api_response_digestor.from_xml(xml_response)
60
+ response.error_code.should == 10000
61
+ response.error_message.should == 'Invalid 7digital API response'
62
+
63
+ xml_response = '<response><test /></response>'
64
+ response = @api_response_digestor.from_xml(xml_response)
65
+ response.error_code.should == 10000
66
+ response.error_message.should == 'Invalid 7digital API response'
67
+ end
68
+
69
+
70
+ it "should create a response with error details from valid xml response with invalid status" do
71
+
72
+ xml_response = '<response status="unkown"><test></test></response>'
73
+ response = @api_response_digestor.from_xml(xml_response)
74
+ response.error_code.should == 10000
75
+ response.error_message.should == 'Invalid 7digital API response'
76
+ end
77
+
78
+ end
@@ -1,83 +1,82 @@
1
- require "spec"
2
- require "sevendigital"
3
-
4
- describe "ArtistDigestor" do
5
-
6
- before do
7
- @artist_digestor = Sevendigital::ArtistDigestor.new(Sevendigital::Client.new(nil))
8
- end
9
-
10
- it "should not digest from invalid xml but throw up (exception)" do
11
-
12
- xml_response = <<XML
13
- <release id="123">
14
- <name>expected artist name</name>
15
- </release>
16
- XML
17
-
18
- running {@artist_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
19
-
20
- end
21
-
22
- it "should digest artist xml and populate minimum available properties" do
23
-
24
- xml_response = <<XML
25
- <artist id="123">
26
- <name>expected artist name</name>
27
- </artist>
28
- XML
29
-
30
- artist = @artist_digestor.from_xml(xml_response)
31
- artist.id.should == 123
32
- artist.name.should == "expected artist name"
33
- end
34
-
35
- it "should digest artist xml and populate all available properties" do
36
-
37
- xml_response = load_sample_object_xml("artist")
38
-
39
- artist = @artist_digestor.from_xml(xml_response)
40
- artist.id.should == 123
41
- artist.name.should == "The Expected Artist"
42
- artist.sort_name.should == "Expected Artist, The"
43
- artist.appears_as.should == "The E.A."
44
- artist.image.should == "http://somewhere.com/tea.jpg"
45
- artist.url.should == "http://7digital.com/artists/tea?partner=1"
46
- end
47
-
48
- it "should digest xml containing list of artists and return a paginated array" do
49
-
50
- xml_response = load_sample_object_xml("artist_list")
51
-
52
- artists = @artist_digestor.list_from_xml(xml_response, :artists)
53
- artists[0].id.should == 14
54
- artists[1].id.should == 20
55
- artists[2].id.should == 106
56
- artists.size.should == 3
57
- artists.total_entries.should == 26
58
-
59
- end
60
-
61
- it "should digest xml containing empty list of releases and return an empty paginated array" do
62
-
63
- xml_response = load_sample_object_xml("artist_list_empty")
64
-
65
- artists = @artist_digestor.list_from_xml(xml_response, :artists)
66
- artists.size.should == 0
67
- artists.total_entries.should == 0
68
-
69
- end
70
-
71
- it "should not digest list from invalid xml but throw up (exception)" do
72
-
73
- xml_response = <<XML
74
- <release id="123">
75
- <name>expected artist name</name>
76
- </release>
77
- XML
78
-
79
- running {@artist_digestor.list_from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
80
-
81
- end
82
-
1
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
2
+
3
+ describe "ArtistDigestor" do
4
+
5
+ before do
6
+ @artist_digestor = Sevendigital::ArtistDigestor.new(Sevendigital::Client.new(nil))
7
+ end
8
+
9
+ it "should not digest from invalid xml but throw up (exception)" do
10
+
11
+ xml_response = <<XML
12
+ <release id="123">
13
+ <name>expected artist name</name>
14
+ </release>
15
+ XML
16
+
17
+ running {@artist_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
18
+
19
+ end
20
+
21
+ it "should digest artist xml and populate minimum available properties" do
22
+
23
+ xml_response = <<XML
24
+ <artist id="123">
25
+ <name>expected artist name</name>
26
+ </artist>
27
+ XML
28
+
29
+ artist = @artist_digestor.from_xml(xml_response)
30
+ artist.id.should == 123
31
+ artist.name.should == "expected artist name"
32
+ end
33
+
34
+ it "should digest artist xml and populate all available properties" do
35
+
36
+ xml_response = load_sample_object_xml("artist")
37
+
38
+ artist = @artist_digestor.from_xml(xml_response)
39
+ artist.id.should == 123
40
+ artist.name.should == "The Expected Artist"
41
+ artist.sort_name.should == "Expected Artist, The"
42
+ artist.appears_as.should == "The E.A."
43
+ artist.image.should == "http://somewhere.com/tea.jpg"
44
+ artist.url.should == "http://7digital.com/artists/tea?partner=1"
45
+ end
46
+
47
+ it "should digest xml containing list of artists and return a paginated array" do
48
+
49
+ xml_response = load_sample_object_xml("artist_list")
50
+
51
+ artists = @artist_digestor.list_from_xml(xml_response, :artists)
52
+ artists[0].id.should == 14
53
+ artists[1].id.should == 20
54
+ artists[2].id.should == 106
55
+ artists.size.should == 3
56
+ artists.total_entries.should == 26
57
+
58
+ end
59
+
60
+ it "should digest xml containing empty list of releases and return an empty paginated array" do
61
+
62
+ xml_response = load_sample_object_xml("artist_list_empty")
63
+
64
+ artists = @artist_digestor.list_from_xml(xml_response, :artists)
65
+ artists.size.should == 0
66
+ artists.total_entries.should == 0
67
+
68
+ end
69
+
70
+ it "should not digest list from invalid xml but throw up (exception)" do
71
+
72
+ xml_response = <<XML
73
+ <release id="123">
74
+ <name>expected artist name</name>
75
+ </release>
76
+ XML
77
+
78
+ running {@artist_digestor.list_from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
79
+
80
+ end
81
+
83
82
  end
@@ -1,54 +1,53 @@
1
- require "spec"
2
- require "sevendigital"
3
-
4
- describe "ChartItemDigestor" do
5
-
6
- before do
7
- @chart_item_digestor = Sevendigital::ChartItemDigestor.new(Sevendigital::Client.new(nil))
8
- end
9
-
10
- it "should not digest from invalid xml but throw up (exception)" do
11
-
12
- xml_response = <<XML
13
- <release id="123">
14
- <name>expected artist name</name>
15
- </release>
16
- XML
17
-
18
- running {@chart_item_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
19
- end
20
-
21
- it "should digest artist chart item" do
22
- xml_response = load_sample_object_xml("artist_chart_item")
23
-
24
- chart_item = @chart_item_digestor.from_xml(xml_response)
25
- chart_item.position.should == 2
26
- chart_item.change.should == :up
27
- chart_item.item.id.should == 33154
28
- chart_item.item.class.should == Sevendigital::Artist
29
- end
30
-
31
-
32
- it "should digest release chart item" do
33
- xml_response = load_sample_object_xml("release_chart_item")
34
-
35
- chart_item = @chart_item_digestor.from_xml(xml_response)
36
- chart_item.position.should == 1
37
- chart_item.change.should == :up
38
- chart_item.item.id.should == 932151
39
- chart_item.item.class.should == Sevendigital::Release
40
- end
41
-
42
- it "should digest track chart item" do
43
-
44
- xml_response = load_sample_object_xml("track_chart_item")
45
-
46
- chart_item = @chart_item_digestor.from_xml(xml_response)
47
- chart_item.position.should == 99
48
- chart_item.change.should == :down
49
- chart_item.item.id.should == 2825304
50
- chart_item.item.class.should == Sevendigital::Track
51
- end
52
-
53
-
1
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
2
+
3
+ describe "ChartItemDigestor" do
4
+
5
+ before do
6
+ @chart_item_digestor = Sevendigital::ChartItemDigestor.new(Sevendigital::Client.new(nil))
7
+ end
8
+
9
+ it "should not digest from invalid xml but throw up (exception)" do
10
+
11
+ xml_response = <<XML
12
+ <release id="123">
13
+ <name>expected artist name</name>
14
+ </release>
15
+ XML
16
+
17
+ running {@chart_item_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
18
+ end
19
+
20
+ it "should digest artist chart item" do
21
+ xml_response = load_sample_object_xml("artist_chart_item")
22
+
23
+ chart_item = @chart_item_digestor.from_xml(xml_response)
24
+ chart_item.position.should == 2
25
+ chart_item.change.should == :up
26
+ chart_item.item.id.should == 33154
27
+ chart_item.item.class.should == Sevendigital::Artist
28
+ end
29
+
30
+
31
+ it "should digest release chart item" do
32
+ xml_response = load_sample_object_xml("release_chart_item")
33
+
34
+ chart_item = @chart_item_digestor.from_xml(xml_response)
35
+ chart_item.position.should == 1
36
+ chart_item.change.should == :up
37
+ chart_item.item.id.should == 932151
38
+ chart_item.item.class.should == Sevendigital::Release
39
+ end
40
+
41
+ it "should digest track chart item" do
42
+
43
+ xml_response = load_sample_object_xml("track_chart_item")
44
+
45
+ chart_item = @chart_item_digestor.from_xml(xml_response)
46
+ chart_item.position.should == 99
47
+ chart_item.change.should == :down
48
+ chart_item.item.id.should == 2825304
49
+ chart_item.item.class.should == Sevendigital::Track
50
+ end
51
+
52
+
54
53
  end
@@ -1,40 +1,39 @@
1
- require "spec"
2
- require "sevendigital"
3
-
4
- describe "FormatDigestor" do
5
-
6
- before do
7
- @format_digestor = Sevendigital::FormatDigestor.new(nil)
8
- end
9
-
10
- it "should not digest from invalid xml but throw up (exception)" do
11
-
12
- xml_response = <<XML
13
- <zzz id="17">
14
- <fileFormat>MP3</fileFormat>
15
- <bitRate>320</bitRate>
16
- <drmFree>True</drmFree>
17
- </zzz>
18
- XML
19
-
20
- running {@format_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
21
- end
22
-
23
- it "should parse from xml and populate all properties" do
24
-
25
- xml_response = <<XML
26
- <format id="17">
27
- <fileFormat>MP3</fileFormat>
28
- <bitRate>320</bitRate>
29
- <drmFree>True</drmFree>
30
- </format>
31
- XML
32
-
33
- format = @format_digestor.from_xml(xml_response)
34
- format.id.should == 17
35
- format.file_format.should == :MP3
36
- format.bit_rate.should == 320
37
- format.drm_free.should == true
38
- end
39
-
1
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
2
+
3
+ describe "FormatDigestor" do
4
+
5
+ before do
6
+ @format_digestor = Sevendigital::FormatDigestor.new(nil)
7
+ end
8
+
9
+ it "should not digest from invalid xml but throw up (exception)" do
10
+
11
+ xml_response = <<XML
12
+ <zzz id="17">
13
+ <fileFormat>MP3</fileFormat>
14
+ <bitRate>320</bitRate>
15
+ <drmFree>True</drmFree>
16
+ </zzz>
17
+ XML
18
+
19
+ running {@format_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
20
+ end
21
+
22
+ it "should parse from xml and populate all properties" do
23
+
24
+ xml_response = <<XML
25
+ <format id="17">
26
+ <fileFormat>MP3</fileFormat>
27
+ <bitRate>320</bitRate>
28
+ <drmFree>True</drmFree>
29
+ </format>
30
+ XML
31
+
32
+ format = @format_digestor.from_xml(xml_response)
33
+ format.id.should == 17
34
+ format.file_format.should == :MP3
35
+ format.bit_rate.should == 320
36
+ format.drm_free.should == true
37
+ end
38
+
40
39
  end