7digital 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. data/README.rdoc +7 -0
  2. data/lib/peachy_patchy.rb +14 -0
  3. data/lib/sevendigital.rb +53 -0
  4. data/lib/sevendigital/api_operator.rb +31 -0
  5. data/lib/sevendigital/api_operator_cached.rb +23 -0
  6. data/lib/sevendigital/api_request.rb +24 -0
  7. data/lib/sevendigital/client.rb +124 -0
  8. data/lib/sevendigital/default_configuration.yml +2 -0
  9. data/lib/sevendigital/digestion_tract/api_response_digestor.rb +52 -0
  10. data/lib/sevendigital/digestion_tract/artist_digestor.rb +31 -0
  11. data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +27 -0
  12. data/lib/sevendigital/digestion_tract/digestor.rb +66 -0
  13. data/lib/sevendigital/digestion_tract/format_digestor.rb +21 -0
  14. data/lib/sevendigital/digestion_tract/label_digestor.rb +20 -0
  15. data/lib/sevendigital/digestion_tract/pager_digestor.rb +23 -0
  16. data/lib/sevendigital/digestion_tract/price_digestor.rb +25 -0
  17. data/lib/sevendigital/digestion_tract/release_digestor.rb +52 -0
  18. data/lib/sevendigital/digestion_tract/track_digestor.rb +37 -0
  19. data/lib/sevendigital/management/artist_manager.rb +39 -0
  20. data/lib/sevendigital/management/manager.rb +11 -0
  21. data/lib/sevendigital/management/release_manager.rb +51 -0
  22. data/lib/sevendigital/management/track_manager.rb +18 -0
  23. data/lib/sevendigital/model/api_response.rb +13 -0
  24. data/lib/sevendigital/model/artist.rb +37 -0
  25. data/lib/sevendigital/model/chart_item.rb +9 -0
  26. data/lib/sevendigital/model/format.rb +9 -0
  27. data/lib/sevendigital/model/label.rb +9 -0
  28. data/lib/sevendigital/model/price.rb +11 -0
  29. data/lib/sevendigital/model/release.rb +34 -0
  30. data/lib/sevendigital/model/sevendigital_error.rb +3 -0
  31. data/lib/sevendigital/model/sevendigital_object.rb +51 -0
  32. data/lib/sevendigital/model/track.rb +8 -0
  33. data/lib/sevendigital/pager.rb +17 -0
  34. data/lib/sevendigital/proxy_police.rb +24 -0
  35. data/lib/sevendigital/version.rb +3 -0
  36. data/spec/api_operator_cached_spec.rb +47 -0
  37. data/spec/api_operator_spec.rb +108 -0
  38. data/spec/api_request_spec.rb +27 -0
  39. data/spec/client_spec.rb +46 -0
  40. data/spec/data/config/sevendigital.yml +5 -0
  41. data/spec/data/configuration_env_override.yml +5 -0
  42. data/spec/data/configuration_override.yml +1 -0
  43. data/spec/digestion_tract/api_response_digestor_spec.rb +74 -0
  44. data/spec/digestion_tract/artist_digestor_spec.rb +83 -0
  45. data/spec/digestion_tract/chart_digestor_spec.rb +54 -0
  46. data/spec/digestion_tract/format_digestor_spec.rb +40 -0
  47. data/spec/digestion_tract/label_digestor_spec.rb +35 -0
  48. data/spec/digestion_tract/pager_digestor_spec.rb +52 -0
  49. data/spec/digestion_tract/price_digestor_spec.rb +57 -0
  50. data/spec/digestion_tract/release_digestor_spec.rb +102 -0
  51. data/spec/digestion_tract/track_digestor_spec.rb +107 -0
  52. data/spec/management/artist_manager_spec.rb +108 -0
  53. data/spec/management/release_manager_spec.rb +178 -0
  54. data/spec/management/track_manager_spec.rb +52 -0
  55. data/spec/model/api_response_spec.rb +32 -0
  56. data/spec/model/artist_spec.rb +122 -0
  57. data/spec/model/release_spec.rb +111 -0
  58. data/spec/pager_spec.rb +8 -0
  59. data/spec/proxy_police_spec.rb +49 -0
  60. data/spec/spec_helper.rb +48 -0
  61. data/spec/test-xml/methods/artist/byTag/top.xml +51 -0
  62. data/spec/test-xml/methods/artist/details.xml +10 -0
  63. data/spec/test-xml/methods/artist/releases.xml +545 -0
  64. data/spec/test-xml/methods/artist/similar.xml +40 -0
  65. data/spec/test-xml/methods/artist/toptracks.xml +280 -0
  66. data/spec/test-xml/methods/release/bydate.xml +174 -0
  67. data/spec/test-xml/methods/release/bytag/top.xml +151 -0
  68. data/spec/test-xml/methods/release/chart.xml +182 -0
  69. data/spec/test-xml/methods/release/details.xml +49 -0
  70. data/spec/test-xml/methods/release/recommend.xml +90 -0
  71. data/spec/test-xml/methods/release/tracks.xml +29 -0
  72. data/spec/test-xml/methods/track/chart.xml +150 -0
  73. data/spec/test-xml/methods/track/details.xml +31 -0
  74. data/spec/test-xml/objects/artist.xml +7 -0
  75. data/spec/test-xml/objects/artist_chart_item.xml +8 -0
  76. data/spec/test-xml/objects/artist_list.xml +23 -0
  77. data/spec/test-xml/objects/artist_list_empty.xml +5 -0
  78. data/spec/test-xml/objects/price.xml +8 -0
  79. data/spec/test-xml/objects/release.xml +40 -0
  80. data/spec/test-xml/objects/release_chart_item.xml +34 -0
  81. data/spec/test-xml/objects/release_list.xml +19 -0
  82. data/spec/test-xml/objects/release_list_empty.xml +5 -0
  83. data/spec/test-xml/objects/track.xml +34 -0
  84. data/spec/test-xml/objects/track_chart_item.xml +28 -0
  85. metadata +151 -0
@@ -0,0 +1,54 @@
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
+
54
+ end
@@ -0,0 +1,40 @@
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
+
40
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec'
2
+ require "sevendigital"
3
+
4
+ describe "LabelDigestor" do
5
+
6
+ before do
7
+ @label_digestor = Sevendigital::LabelDigestor.new(nil)
8
+ end
9
+
10
+
11
+ it "should not digest from invalid xml but throw up (exception)" do
12
+
13
+ xml_response = <<XML
14
+ <release id="123">
15
+ <name>expected artist name</name>
16
+ </release>
17
+ XML
18
+
19
+ running {@label_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
20
+ end
21
+
22
+ it "should digest label xml and populate all properties" do
23
+
24
+ xml_response = <<XML
25
+ <label id="123">
26
+ <name>expected label name</name>
27
+ </label>
28
+ XML
29
+
30
+ label = @label_digestor.from_xml(xml_response)
31
+ label.id.should == 123
32
+ label.name.should == "expected label name"
33
+ end
34
+
35
+ end
@@ -0,0 +1,52 @@
1
+ require "spec"
2
+ require "sevendigital"
3
+
4
+ describe "PagerDigestor" do
5
+
6
+ before do
7
+ @pager_digestor = Sevendigital::PagerDigestor.new(nil)
8
+ end
9
+
10
+
11
+ it "should not digest from invalid xml but throw up (exception)" do
12
+
13
+ xml_response = <<XML
14
+ <release id="123">
15
+ <name>expected artist name</name>
16
+ </release>
17
+ XML
18
+
19
+ running {@pager_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
20
+ end
21
+
22
+ it "should not digest if paging info is missing from xml but spit out nil" do
23
+
24
+ xml_response = <<XML
25
+ <results id="123">
26
+ <page>3</page>
27
+ <totalItems>99</totalItems>
28
+ <pageSizeElementMissing>22</pageSizeElementMissing>
29
+ </results>
30
+ XML
31
+
32
+ pager = @pager_digestor.from_xml(xml_response, :results)
33
+ pager.should == nil
34
+ end
35
+
36
+ it "should digest from xml and populate all properties" do
37
+
38
+ xml_response = <<XML
39
+ <pager a="b">
40
+ <page>3</page>
41
+ <totalItems>99</totalItems>
42
+ <pageSize>22</pageSize>
43
+ </pager>
44
+ XML
45
+
46
+ pager = @pager_digestor.from_xml(xml_response, :pager)
47
+ pager.page.should == 3
48
+ pager.page_size.should == 22
49
+ pager.total_items.should == 99
50
+ end
51
+
52
+ end
@@ -0,0 +1,57 @@
1
+ require "spec"
2
+ require "sevendigital"
3
+
4
+ describe "PriceDigestor" do
5
+
6
+ before do
7
+ @price_digestor = Sevendigital::PriceDigestor.new(nil)
8
+ end
9
+
10
+ it "should not digest from invalid xml but throw up (exception)" do
11
+
12
+ xml_response = <<XML
13
+ <xxx>
14
+ <currency code="XXX">X</currency>
15
+ </xxx>
16
+ XML
17
+
18
+ running {@price_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
19
+ end
20
+
21
+ it "should parse from xml and populate minimum available properties" do
22
+
23
+ xml_response = <<XML
24
+ <price>
25
+ <currency code="GBP">£</currency>
26
+ <value>1.79</value>
27
+ <formattedPrice>£1.79</formattedPrice>
28
+ <onSale>true</onSale>
29
+ </price>
30
+ XML
31
+
32
+ price = @price_digestor.from_xml(xml_response)
33
+ price.currency_code.should == :GBP
34
+ price.currency_symbol.should == "£"
35
+ price.value.should == 1.79
36
+ price.formatted_price.should == "£1.79"
37
+ price.rrp.should == nil
38
+ price.formatted_rrp.should == nil
39
+ price.on_sale.should == true
40
+
41
+ end
42
+
43
+ it "should parse from xml and populate all properties" do
44
+
45
+ xml_response = load_sample_object_xml("price")
46
+
47
+ price = @price_digestor.from_xml(xml_response)
48
+ price.currency_code.should == :GBP
49
+ price.currency_symbol.should == "£"
50
+ price.value.should == 1.79
51
+ price.formatted_price.should == "£1.79"
52
+ price.rrp.should == 1.99
53
+ price.formatted_rrp.should == "£1.99"
54
+ price.on_sale.should == true
55
+ end
56
+
57
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec'
2
+ require 'date'
3
+ require File.join(File.dirname(__FILE__), %w[../spec_helper])
4
+ require "sevendigital"
5
+
6
+ describe "ReleaseDigestor" do
7
+
8
+ before do
9
+ @release_digestor = Sevendigital::ReleaseDigestor.new(Sevendigital::Client.new(nil))
10
+ end
11
+
12
+ it "should not digest from invalid xml but throw up (exception)" do
13
+
14
+ xml_response = <<XML
15
+ <artist id="123">
16
+ <name>expected artist name</name>
17
+ </artist>
18
+ XML
19
+
20
+ running {@release_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
21
+ end
22
+
23
+ it "should digest release xml and populate minimum available properties" do
24
+
25
+ xml_response = <<XML
26
+ <release id="123">
27
+ <title>expected release title</title>
28
+ <artist id="345">
29
+ <name>expected artist name</name>
30
+ <appearsAs>expected displayed artist name</appearsAs>
31
+ </artist>
32
+ </release>
33
+ XML
34
+
35
+ release = @release_digestor.from_xml(xml_response)
36
+ release.id.should == 123
37
+ release.title.should == "expected release title"
38
+ release.artist.id.should == 345
39
+ release.artist.name.should == "expected artist name"
40
+ release.artist.appears_as == "expected displayed artist name"
41
+ end
42
+
43
+ it "should digest release xml and populate all available properties" do
44
+
45
+ xml_response = load_sample_object_xml("release")
46
+
47
+ release = @release_digestor.from_xml(xml_response)
48
+
49
+ release.id.should == 155408
50
+ release.title.should == "Dreams"
51
+ release.version.should == "UK"
52
+ release.type.should == :album
53
+ release.barcode.should == "00602517512078"
54
+ release.year.should == 2007
55
+ release.explicit_content.should == false
56
+ release.artist.id.should == 29755
57
+ release.artist.name.should == "The Whitest Boy Alive"
58
+ release.artist.appears_as.should == "The Whitest Boy Alive"
59
+ release.release_date.should == DateTime.new(2007,10,22,0,0,0, 1.quo(24))
60
+ release.added_date.should == DateTime.new(2007,10,11,11,18,29, 0)
61
+ release.price.currency_code.should == :GBP
62
+ release.price.currency_symbol.should == "£"
63
+ release.price.value.should == 5
64
+ release.price.formatted_price.should == "£5.00"
65
+ release.price.rrp.should == 7.79
66
+ release.price.formatted_rrp.should == "£7.79"
67
+ release.price.on_sale.should == true
68
+ release.formats.size.should == 2
69
+ release.formats[0].id.should == 17
70
+ release.formats[1].id.should == 1
71
+ release.label.id.should == 40
72
+ release.label.name.should == "Universal-Island Records Ltd."
73
+ release.image.should == "http://cdn.7static.com/static/img/sleeveart/00/001/554/0000155408_50.jpg"
74
+ release.url.should == "http://www.7digital.com/artists/the-whitest-boy-alive/dreams-(1)/?partner=123"
75
+ release
76
+ end
77
+
78
+ it "should digest xml containing list of releases and return a paginated array" do
79
+
80
+ xml_response = load_sample_object_xml("release_list")
81
+
82
+ releases = @release_digestor.list_from_xml(xml_response, :results)
83
+ releases[0].id.should == 123
84
+ releases[0].artist.id.should == 345
85
+ releases[1].id.should == 456
86
+ releases[1].artist.id.should == 789
87
+ releases.size.should == 2
88
+ releases.total_entries.should == 50
89
+
90
+ end
91
+
92
+ it "should digest xml containing empty list of releases and return an empty paginated array" do
93
+
94
+ xml_response = load_sample_object_xml("release_list_empty")
95
+
96
+ releases = @release_digestor.list_from_xml(xml_response, :results)
97
+ releases.size.should == 0
98
+ releases.total_entries.should == 0
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,107 @@
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
+
107
+ end