xhochy-scrobbler 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/History.txt +5 -0
  2. data/MIT-LICENSE +19 -0
  3. data/Manifest +65 -0
  4. data/README.rdoc +114 -0
  5. data/Rakefile +36 -0
  6. data/examples/album.rb +17 -0
  7. data/examples/artist.rb +13 -0
  8. data/examples/scrobble.rb +31 -0
  9. data/examples/tag.rb +11 -0
  10. data/examples/track.rb +6 -0
  11. data/examples/user.rb +14 -0
  12. data/lib/scrobbler.rb +22 -0
  13. data/lib/scrobbler/album.rb +140 -0
  14. data/lib/scrobbler/artist.rb +134 -0
  15. data/lib/scrobbler/base.rb +82 -0
  16. data/lib/scrobbler/chart.rb +31 -0
  17. data/lib/scrobbler/playing.rb +49 -0
  18. data/lib/scrobbler/rest.rb +47 -0
  19. data/lib/scrobbler/scrobble.rb +66 -0
  20. data/lib/scrobbler/search.rb +60 -0
  21. data/lib/scrobbler/simpleauth.rb +59 -0
  22. data/lib/scrobbler/tag.rb +93 -0
  23. data/lib/scrobbler/track.rb +89 -0
  24. data/lib/scrobbler/user.rb +173 -0
  25. data/lib/scrobbler/version.rb +3 -0
  26. data/scrobbler.gemspec +41 -0
  27. data/setup.rb +1585 -0
  28. data/test/fixtures/xml/album/info.xml +43 -0
  29. data/test/fixtures/xml/artist/fans.xml +52 -0
  30. data/test/fixtures/xml/artist/similar.xml +1004 -0
  31. data/test/fixtures/xml/artist/topalbums.xml +61 -0
  32. data/test/fixtures/xml/artist/toptags.xml +19 -0
  33. data/test/fixtures/xml/artist/toptracks.xml +62 -0
  34. data/test/fixtures/xml/search/album.xml +241 -0
  35. data/test/fixtures/xml/search/artist.xml +215 -0
  36. data/test/fixtures/xml/search/track.xml +209 -0
  37. data/test/fixtures/xml/tag/topalbums.xml +805 -0
  38. data/test/fixtures/xml/tag/topartists.xml +605 -0
  39. data/test/fixtures/xml/tag/toptags.xml +1254 -0
  40. data/test/fixtures/xml/tag/toptracks.xml +852 -0
  41. data/test/fixtures/xml/track/fans.xml +34 -0
  42. data/test/fixtures/xml/track/toptags.xml +33 -0
  43. data/test/fixtures/xml/user/friends.xml +30 -0
  44. data/test/fixtures/xml/user/neighbours.xml +23 -0
  45. data/test/fixtures/xml/user/profile.xml +12 -0
  46. data/test/fixtures/xml/user/recentbannedtracks.xml +24 -0
  47. data/test/fixtures/xml/user/recentlovedtracks.xml +24 -0
  48. data/test/fixtures/xml/user/recenttracks.xml +47 -0
  49. data/test/fixtures/xml/user/systemrecs.xml +18 -0
  50. data/test/fixtures/xml/user/topalbums.xml +61 -0
  51. data/test/fixtures/xml/user/topartists.xml +41 -0
  52. data/test/fixtures/xml/user/toptags.xml +44 -0
  53. data/test/fixtures/xml/user/toptracks.xml +65 -0
  54. data/test/mocks/rest.rb +102 -0
  55. data/test/test_helper.rb +20 -0
  56. data/test/unit/album_test.rb +73 -0
  57. data/test/unit/artist_test.rb +106 -0
  58. data/test/unit/chart_test.rb +34 -0
  59. data/test/unit/playing_test.rb +53 -0
  60. data/test/unit/scrobble_test.rb +69 -0
  61. data/test/unit/search_test.rb +55 -0
  62. data/test/unit/simpleauth_test.rb +45 -0
  63. data/test/unit/tag_test.rb +58 -0
  64. data/test/unit/track_test.rb +37 -0
  65. data/test/unit/user_test.rb +201 -0
  66. metadata +175 -0
@@ -0,0 +1,102 @@
1
+ require File.dirname(__FILE__) + '/../../lib/scrobbler/rest'
2
+ require 'digest/md5'
3
+
4
+ module Scrobbler
5
+ module REST
6
+ class Connection
7
+ # reads xml fixture file instead of hitting up the internets
8
+ def request(resource, method = "get", args = nil)
9
+ @now_playing_url = 'http://62.216.251.203:80/nowplaying'
10
+ @submission_url = 'http://62.216.251.205:80/protocol_1.2'
11
+ @session_id = '17E61E13454CDD8B68E8D7DEEEDF6170'
12
+
13
+ if @base_url == Scrobbler::API_URL
14
+ pieces = resource.split('/')
15
+ pieces.shift
16
+ api_version = pieces.shift
17
+ if api_version == "1.0"
18
+ folder = pieces.shift
19
+ file = pieces.last[0, pieces.last.index('.xml')]
20
+ base_pieces = pieces.last.split('?')
21
+
22
+ file = if base_pieces.size > 1
23
+ # if query string params are in resource they are underscore separated for filenames
24
+ base_pieces.last.split('&').inject("#{file}_") { |str, pair| str << pair.split('=').join('_') + '_'; str }.chop!
25
+ else
26
+ file
27
+ end
28
+
29
+ File.read(File.dirname(__FILE__) + "/../fixtures/xml/#{folder}/#{file}.xml")
30
+ elsif api_version == "2.0"
31
+ method_pieces = pieces.last.split('&')
32
+ api_method = method_pieces.shift
33
+ if api_method == '?method=artist.search'
34
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/search/artist.xml")
35
+ elsif api_method == '?method=album.search'
36
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/search/album.xml")
37
+ elsif api_method == '?method=track.search'
38
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/search/track.xml")
39
+ elsif pieces.last =~ /[?&]method=album\.getinfo/
40
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/album/info.xml")
41
+ elsif pieces.last =~ /[?&]method=artist\.gettoptags/
42
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/artist/toptags.xml")
43
+ elsif pieces.last =~ /[?&]method=artist\.gettopfans/
44
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/artist/fans.xml")
45
+ elsif pieces.last =~ /[?&]method=artist\.gettoptracks/
46
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/artist/toptracks.xml")
47
+ elsif pieces.last =~ /[?&]method=artist\.gettopalbums/
48
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/artist/topalbums.xml")
49
+ elsif pieces.last =~ /[?&]method=artist\.getsimilar/
50
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/artist/similar.xml")
51
+ elsif pieces.last =~ /[?&]method=tag\.gettoptracks/
52
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/tag/toptracks.xml")
53
+ elsif pieces.last =~ /[?&]method=tag\.gettopartists/
54
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/tag/topartists.xml")
55
+ elsif pieces.last =~ /[?&]method=tag\.gettopalbums/
56
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/tag/topalbums.xml")
57
+ elsif pieces.last =~ /[?&]method=track\.gettoptags/
58
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/track/toptags.xml")
59
+ elsif pieces.last =~ /[?&]method=track\.gettopfans/
60
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/track/fans.xml")
61
+ elsif pieces.last =~ /[?&]method=user\.gettopartists/
62
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/user/topartists.xml")
63
+ elsif pieces.last =~ /[?&]method=user\.gettopalbums/
64
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/user/topalbums.xml")
65
+ elsif pieces.last =~ /[?&]method=user\.gettoptracks/
66
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/user/toptracks.xml")
67
+ elsif pieces.last =~ /[?&]method=user\.getfriends/
68
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/user/friends.xml")
69
+ elsif pieces.last =~ /[?&]method=user\.gettoptags/
70
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/user/toptags.xml")
71
+ elsif pieces.last =~ /[?&]method=user\.getneighbours/
72
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/user/neighbours.xml")
73
+ elsif pieces.last =~ /[?&]method=user\.getrecenttracks/
74
+ return File.read(File.dirname(__FILE__) + "/../fixtures/xml/user/recenttracks.xml")
75
+ else
76
+ throw Exception.new("Illegal or unsupported Last.FM method called")
77
+ end
78
+ end
79
+ elsif @base_url == Scrobbler::AUTH_URL
80
+ if args[:hs] == "true" && args[:p] == Scrobbler::AUTH_VER.to_s && args[:c] == 'rbs' &&
81
+ args[:v] == Scrobbler::Version.to_s && args[:u] == 'chunky' && !args[:t].blank? &&
82
+ args[:a] == Digest::MD5.hexdigest('7813258ef8c6b632dde8cc80f6bda62f' + args[:t])
83
+
84
+ "OK\n#{@session_id}\n#{@now_playing_url}\n#{@submission_url}"
85
+ end
86
+ elsif @base_url == @now_playing_url
87
+ if args[:s] == @session_id && ![args[:a], args[:t], args[:b], args[:n]].any?(&:blank?)
88
+ 'OK'
89
+ end
90
+ elsif @base_url == @submission_url
91
+ if args[:s] == @session_id &&
92
+ ![args['a[0]'], args['t[0]'], args['i[0]'], args['o[0]'], args['l[0]'], args['b[0]']].any?(&:blank?)
93
+ 'OK'
94
+ end
95
+ elsif @base_url == @scrobbler_api_url_v2
96
+ File.read(File.dirname(__FILE__) + "/../fixtures/xml/search/album.xml")
97
+ end
98
+
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,20 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/scrobbler'
3
+ require File.dirname(__FILE__) + '/mocks/rest'
4
+
5
+ # To test the 2.0 API, we do not need a valid key
6
+ Scrobbler::Base.api_key = 'foo123'
7
+
8
+ class << Test::Unit::TestCase
9
+ def test(name, &block)
10
+ test_name = :"test_#{name.gsub(' ','_')}"
11
+ raise ArgumentError, "#{test_name} is already defined" if self.instance_methods.include? test_name.to_s
12
+ define_method test_name, &block
13
+ end
14
+
15
+ def expect(expected_value, &block)
16
+ define_method :"test_#{caller.first.split("/").last}" do
17
+ assert_equal expected_value, instance_eval(&block)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,73 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestAlbum < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @album = Scrobbler::Album.new('Carrie Underwood', 'Some Hearts')
7
+ end
8
+
9
+ # @apiversion 2.0
10
+ test 'should require the artist name' do
11
+ assert_raises(ArgumentError) { Scrobbler::Album.new('', 'Some Hearts') }
12
+ end
13
+
14
+ test 'should require the track name' do
15
+ assert_raises(ArgumentError) { Scrobbler::Album.new('Carrie Underwood', '') }
16
+ end
17
+
18
+ test 'should know the artist' do
19
+ assert_equal('Carrie Underwood', @album.artist)
20
+ end
21
+
22
+ test "should know it's name" do
23
+ assert_equal('Some Hearts', @album.name)
24
+ end
25
+
26
+ test 'should be able to load album info' do
27
+ @album.load_info
28
+ assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', @album.url)
29
+ assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), @album.release_date)
30
+ end
31
+
32
+ test 'should be able to find an ablum' do
33
+ album = Scrobbler::Album.find('Carrie Underwood', 'Some Hearts')
34
+ assert_equal('Carrie Underwood', album.artist)
35
+ assert_equal('Some Hearts', album.name)
36
+ end
37
+
38
+ test "should be able to find an ablum and load the album's info" do
39
+ album = Scrobbler::Album.find('Carrie Underwood', 'Some Hearts', :include_info => true)
40
+ assert_equal('Carrie Underwood', album.artist)
41
+ assert_equal('Some Hearts', album.name)
42
+ assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', album.url)
43
+ assert_equal(131312, album.listeners)
44
+ assert_equal(2096260, album.playcount)
45
+ assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), album.release_date)
46
+ assert_equal(["country", "albums i own", "pop", "country pop", "american idol"], album.top_tags.collect(&:name))
47
+ end
48
+
49
+ test "should be able to include the album's info on initialize" do
50
+ album = Scrobbler::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
51
+ assert_equal('Carrie Underwood', album.artist)
52
+ assert_equal('Some Hearts', album.name)
53
+ assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', album.url)
54
+ assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), album.release_date)
55
+ end
56
+
57
+ test 'should have an image method that accepts a type' do
58
+ @album.load_info
59
+ assert_equal('http://userserve-ak.last.fm/serve/34s/19874169.jpg', @album.image(:small))
60
+ assert_equal('http://userserve-ak.last.fm/serve/64s/19874169.jpg', @album.image(:medium))
61
+ assert_equal('http://userserve-ak.last.fm/serve/174s/19874169.jpg', @album.image(:large))
62
+ assert_equal('http://userserve-ak.last.fm/serve/300x300/19874169.jpg', @album.image(:extralarge))
63
+ end
64
+
65
+ test "should raise an argument error when attempting to get an image that doesn't exist" do
66
+ @album.load_info
67
+ assert_raises(ArgumentError) { @album.image(:fake) }
68
+ end
69
+
70
+ test 'should load info when trying to access an image if the info has not been loaded' do
71
+ assert_equal('http://userserve-ak.last.fm/serve/34s/19874169.jpg', @album.image(:small))
72
+ end
73
+ end
@@ -0,0 +1,106 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestArtist < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @artist = Scrobbler::Artist.new('Metallica')
7
+
8
+ @similar_artists = ["Megadeth", "Pantera", "Slayer", "Iron Maiden",
9
+ "Anthrax", "Machine Head", "Sepultura", "Motörhead", "Testament",
10
+ "Trivium", "Black Sabbath", "Exodus", "Ozzy Osbourne", "AC/DC",
11
+ "Kreator", "Black Label Society", "Guns N' Roses", "System of a Down",
12
+ "Judas Priest", "Soulfly", "Godsmack", "Children of Bodom", "Slipknot",
13
+ "Disturbed", "Hunter", "Apocalyptica", "Iced Earth", "Annihilator",
14
+ "Rammstein", "KoЯn", "Death Angel", "In Flames", "Lamb of God", "Overkill",
15
+ "Diamond Head", "Damageplan", "Acid Drinkers", "Beatallica", "Stone Sour",
16
+ "Metal Church", "MD.45", "Volbeat", "HammerFall","Black Tide",
17
+ "Rage Against the Machine", "Manowar", "Probot", "Bullet For My Valentine",
18
+ "Flotsam and Jetsam", "Dio", "Roadrunner United", "Venom", "Arch Enemy",
19
+ "Mercyful Fate", "Nuclear Assault", "Destruction", "Blind Guardian",
20
+ "Sacred Reich", "Bruce Dickinson", "Turbo", "Static-X", "Helloween",
21
+ "Zakk Wylde", "Avenged Sevenfold", "W.A.S.P.", "Kat", "Skid Row",
22
+ "DevilDriver", "Danzig", "Heathen", "Mokoma", "Lordi", "Shadows Fall",
23
+ "Chimaira", "Whiplash", "Mudvayne", "Onslaught", "Sodom", "Rage",
24
+ "Forbidden", "Evile", "Savatage", "Scorpions", "DragonForce",
25
+ "Axel Rudi Pell", "Rob Zombie", "Killswitch Engage", "Sebastian Bach",
26
+ "Saxon", "Cavalera Conspiracy", "Voivod", "Drowning Pool",
27
+ "Fear Factory", "Mötley Crüe", "Prong", "Kotiteollisuus", "Stone",
28
+ "Fozzy", "Yngwie Malmsteen", "Deep Purple"]
29
+ @top_albums = ["Master of Puppets", "Metallica", "Ride the Lightning", "Reload"]
30
+ @top_fans = ["Slide15", "Air_Force", "Evile9", "thy_satan", "Aiham", "Quugel"]
31
+ @top_tracks = ['Nothing Else Matters', 'Enter Sandman',
32
+ 'The Day That Never Comes', 'One']
33
+ end
34
+
35
+ # @apiversion 2.0
36
+ test 'should require name' do
37
+ assert_raises(ArgumentError) { Scrobbler::Artist.new('') }
38
+ end
39
+
40
+ # @apiversion 2.0
41
+ test "should know it's name" do
42
+ assert_equal('Metallica', @artist.name)
43
+ end
44
+
45
+ test 'should have the correct ical path to current events' do
46
+ assert_equal('http://ws.audioscrobbler.com/2.0/artist/Metallica/events.ics', @artist.current_events(:ical))
47
+ end
48
+
49
+ test 'should have the correct rss path to current events' do
50
+ assert_equal('http://ws.audioscrobbler.com/2.0/artist/Metallica/events.rss', @artist.current_events(:rss))
51
+ end
52
+
53
+ # @apiversion 2.0
54
+ test 'should be able to find similar artists' do
55
+ assert_equal(@similar_artists, @artist.similar.collect(&:name))
56
+ first = @artist.similar.first
57
+ assert_equal('Megadeth', first.name)
58
+ assert_equal('a9044915-8be3-4c7e-b11f-9e2d2ea0a91e', first.mbid)
59
+ assert_equal('100', first.match)
60
+ assert_equal('www.last.fm/music/Megadeth', first.url)
61
+ assert_equal('http://userserve-ak.last.fm/serve/34/8422011.jpg', first.image(:small))
62
+ assert_equal('http://userserve-ak.last.fm/serve/64/8422011.jpg', first.image(:medium))
63
+ assert_equal('http://userserve-ak.last.fm/serve/126/8422011.jpg', first.image(:large))
64
+ assert_equal('yes', first.streamable)
65
+ end
66
+
67
+ # @apiversion 2.0
68
+ test 'should be able to find top fans' do
69
+ assert_equal(@top_fans, @artist.top_fans.collect(&:username))
70
+ first = @artist.top_fans.first
71
+ assert_equal('Slide15', first.username)
72
+ assert_equal('http://www.last.fm/user/Slide15', first.url)
73
+ assert_equal('http://userserve-ak.last.fm/serve/34/4477633.jpg', first.avatar)
74
+ assert_equal('265440672', first.weight)
75
+ end
76
+
77
+ # @apiversion 2.0
78
+ test 'should be able to find top tracks' do
79
+ assert_equal(@top_tracks, @artist.top_tracks.collect(&:name))
80
+ first = @artist.top_tracks.first
81
+ assert_equal('Nothing Else Matters', first.name)
82
+ assert_equal('', first.mbid)
83
+ assert_equal('http://www.last.fm/music/Metallica/_/Nothing+Else+Matters', first.url)
84
+ end
85
+
86
+ # @apiversion 2.0
87
+ test 'should be able to find top albums' do
88
+ assert_equal(@top_albums, @artist.top_albums.collect(&:name))
89
+ first = @artist.top_albums.first
90
+ assert_equal('Master of Puppets', first.name)
91
+ assert_equal('fed37cfc-2a6d-4569-9ac0-501a7c7598eb', first.mbid)
92
+ assert_equal('http://www.last.fm/music/Metallica/Master+of+Puppets', first.url)
93
+ assert_equal('http://userserve-ak.last.fm/serve/34s/8622967.jpg', first.image(:small))
94
+ assert_equal('http://userserve-ak.last.fm/serve/64s/8622967.jpg', first.image(:medium))
95
+ assert_equal('http://userserve-ak.last.fm/serve/126/8622967.jpg', first.image(:large))
96
+ end
97
+
98
+ # @apiversion 2.0
99
+ test 'should be able to find top tags' do
100
+ assert_equal(['metal', 'thrash metal', 'heavy metal'], @artist.top_tags.collect(&:name))
101
+ first = @artist.top_tags.first
102
+ assert_equal('metal', first.name)
103
+ assert_equal('100', first.count)
104
+ assert_equal('http://www.last.fm/tag/metal', first.url)
105
+ end
106
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestChart < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @chart = Scrobbler::Chart.new('1108296002', '1108900802')
7
+ end
8
+
9
+ test 'should require from' do
10
+ assert_raise(ArgumentError) { Scrobbler::Chart.new('', '1108900802') }
11
+ end
12
+
13
+ test 'should require to' do
14
+ assert_raise(ArgumentError) { Scrobbler::Chart.new('1108296002', '') }
15
+ end
16
+
17
+ test 'should be able to parse to and from that are unix timestamp strings' do
18
+ chart = Scrobbler::Chart.new('1108296002', '1108900802')
19
+ assert_equal(1108296002, chart.from)
20
+ assert_equal(1108900802, chart.to)
21
+ end
22
+
23
+ test 'should be able to parse to and from that are unix timestamp fixnums' do
24
+ chart = Scrobbler::Chart.new(1108296002, 1108900802)
25
+ assert_equal(1108296002, chart.from)
26
+ assert_equal(1108900802, chart.to)
27
+ end
28
+
29
+ test 'should be able to parse to and from that are times' do
30
+ chart = Scrobbler::Chart.new(Time.at(1108296002), Time.at(1108900802))
31
+ assert_equal(1108296002, chart.from)
32
+ assert_equal(1108900802, chart.to)
33
+ end
34
+ end
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestPlaying < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @session_id = '17E61E13454CDD8B68E8D7DEEEDF6170'
7
+ @now_playing_url = 'http://62.216.251.203:80/nowplaying'
8
+ @artist = 'Anberlin'
9
+ @track = 'A Day Late'
10
+ @album = 'Never Take Friendship Personal'
11
+
12
+ @playing = Scrobbler::Playing.new(:session_id => @session_id, :now_playing_url => @now_playing_url,
13
+ :artist => @artist, :track => @track, :album => @album, :length => 214,
14
+ :track_number => 5)
15
+ end
16
+
17
+ test 'should require a session id' do
18
+ assert_raises(ArgumentError) { Scrobbler::Playing.new(
19
+ :now_playing_url => @now_playing_url, :artist => @artist, :track => @track,
20
+ :album => @album, :length => 214, :track_number => 5) }
21
+ end
22
+
23
+ test 'should require a now playing url' do
24
+ assert_raises(ArgumentError) { Scrobbler::Playing.new(
25
+ :session_id => @session_id, :artist => @artist, :track => @track,
26
+ :album => @album, :length => 214, :track_number => 5) }
27
+ end
28
+
29
+ test 'should require an artist' do
30
+ assert_raises(ArgumentError) { Scrobbler::Playing.new(
31
+ :session_id => @session_id, :now_playing_url => @now_playing_url,
32
+ :track => @track, :album => @album, :length => 214, :track_number => 5) }
33
+ end
34
+
35
+ test 'should require a track' do
36
+ assert_raises(ArgumentError) { Scrobbler::Playing.new(
37
+ :session_id => @session_id, :now_playing_url => @now_playing_url,
38
+ :artist => @artist, :album => @album, :length => 214, :track_number => 5) }
39
+ end
40
+
41
+ test 'should require a length greater than 30 seconds' do
42
+ assert_raises(ArgumentError) { Scrobbler::Playing.new(
43
+ :session_id => @session_id, :now_playing_url => @now_playing_url,
44
+ :artist => @artist, :track => @track, :album => @album, :length => 29,
45
+ :track_number => 5) }
46
+ end
47
+
48
+ test 'should submit successfully' do
49
+ @playing.submit!
50
+ assert_equal('OK', @playing.status)
51
+ end
52
+
53
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestScrobble < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @session_id = '17E61E13454CDD8B68E8D7DEEEDF6170'
7
+ @submission_url = 'http://62.216.251.205:80/protocol_1.2'
8
+ @artist = 'Coldplay'
9
+ @name = 'Viva La Vida'
10
+
11
+ @scrobble = Scrobbler::Scrobble.new(:session_id => @session_id, :submission_url => @submission_url,
12
+ :artist => @artist, :track => @name, :album => @name, :time => Time.new,
13
+ :length => 244, :track_number => 7)
14
+ end
15
+
16
+ test 'should require a session id' do
17
+ assert_raises(ArgumentError) { Scrobbler::Scrobble.new(:submission_url => @submission_url,
18
+ :artist => @artist, :track => @name, :album => @name, :time => Time.new,
19
+ :length => 244, :track_number => 7) }
20
+ end
21
+
22
+ test 'should require a submission url' do
23
+ assert_raises(ArgumentError) { Scrobbler::Scrobble.new(:session_id => @session_id,
24
+ :artist => @artist, :track => @name, :album => @name, :time => Time.new,
25
+ :length => 244, :track_number => 7) }
26
+ end
27
+
28
+ test 'should require an artist' do
29
+ assert_raises(ArgumentError) { Scrobbler::Scrobble.new(:session_id => @session_id, :submission_url => @submission_url,
30
+ :track => @name, :album => @name, :time => Time.new,
31
+ :length => 244, :track_number => 7) }
32
+ end
33
+
34
+ test 'should require a track' do
35
+ assert_raises(ArgumentError) { Scrobbler::Scrobble.new(:session_id => @session_id, :submission_url => @submission_url,
36
+ :artist => @artist, :album => @name, :time => Time.new,
37
+ :length => 244, :track_number => 7) }
38
+ end
39
+
40
+ test 'should require a Time object' do
41
+ assert_raises(ArgumentError) { Scrobbler::Scrobble.new(:session_id => @session_id, :submission_url => @submission_url,
42
+ :artist => @artist, :track => @name, :album => @name, :time => 'chunky_bacon',
43
+ :length => 244, :track_number => 7) }
44
+ end
45
+
46
+ test 'should require a valid source' do
47
+ assert_raises(ArgumentError) { Scrobbler::Scrobble.new(:session_id => @session_id, :submission_url => @submission_url,
48
+ :artist => @artist, :track => @name, :album => @name, :time => Time.new,
49
+ :length => 244, :track_number => 7, :source => 'Z') }
50
+ end
51
+
52
+ test 'should require a length if source is set to P' do
53
+ assert_raises(ArgumentError) { Scrobbler::Scrobble.new(:session_id => @session_id, :submission_url => @submission_url,
54
+ :artist => @artist, :track => @name, :album => @name, :time => Time.new,
55
+ :track_number => 7, :source => 'P') }
56
+ end
57
+
58
+ test 'should require a length greater than 30 if source is set to P' do
59
+ assert_raises(ArgumentError) { Scrobbler::Scrobble.new(:session_id => @session_id, :submission_url => @submission_url,
60
+ :artist => @artist, :track => @name, :album => @name, :time => Time.new,
61
+ :length => 29, :track_number => 7, :source => 'P') }
62
+ end
63
+
64
+ test 'should submit successfully' do
65
+ @scrobble.submit!
66
+ assert_equal('OK', @scrobble.status)
67
+ end
68
+
69
+ end