rockstar 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.gitignore +3 -0
  2. data/History.txt +6 -0
  3. data/MIT-LICENSE +19 -0
  4. data/Manifest +72 -0
  5. data/README.rdoc +140 -0
  6. data/Rakefile +21 -0
  7. data/VERSION +1 -0
  8. data/examples/.gitignore +1 -0
  9. data/examples/album.rb +16 -0
  10. data/examples/artist.rb +17 -0
  11. data/examples/lastfm.yml_example +3 -0
  12. data/examples/scrobble.rb +55 -0
  13. data/examples/tag.rb +20 -0
  14. data/examples/track.rb +14 -0
  15. data/examples/user.rb +18 -0
  16. data/lib/rockstar.rb +39 -0
  17. data/lib/rockstar/album.rb +108 -0
  18. data/lib/rockstar/artist.rb +135 -0
  19. data/lib/rockstar/auth.rb +21 -0
  20. data/lib/rockstar/base.rb +37 -0
  21. data/lib/rockstar/chart.rb +31 -0
  22. data/lib/rockstar/playing.rb +49 -0
  23. data/lib/rockstar/rest.rb +66 -0
  24. data/lib/rockstar/scrobble.rb +67 -0
  25. data/lib/rockstar/session.rb +19 -0
  26. data/lib/rockstar/simpleauth.rb +62 -0
  27. data/lib/rockstar/tag.rb +100 -0
  28. data/lib/rockstar/tokenauth.rb +84 -0
  29. data/lib/rockstar/track.rb +103 -0
  30. data/lib/rockstar/user.rb +194 -0
  31. data/lib/rockstar/version.rb +3 -0
  32. data/rockstar.gemspec +138 -0
  33. data/test/fixtures/xml/album/getinfo_album_Some_Hearts_artist_Carrie_Underwood.xml +63 -0
  34. data/test/fixtures/xml/artist/getsimilar_artist_Metallica.xml +1203 -0
  35. data/test/fixtures/xml/artist/gettopalbums_artist_Metallica.xml +704 -0
  36. data/test/fixtures/xml/artist/gettopfans_artist_Metallica.xml +504 -0
  37. data/test/fixtures/xml/artist/gettoptags_artist_Metallica.xml +403 -0
  38. data/test/fixtures/xml/artist/gettoptracks_artist_Metallica.xml +800 -0
  39. data/test/fixtures/xml/tag/gettopalbums_tag_rock.xml +654 -0
  40. data/test/fixtures/xml/tag/gettopartists_tag_rock.xml +504 -0
  41. data/test/fixtures/xml/tag/gettoptags.xml +1253 -0
  42. data/test/fixtures/xml/tag/gettoptracks_tag_rock.xml +704 -0
  43. data/test/fixtures/xml/track/gettopfans_artist_Carrie_Underwood_track_Before_He_Cheats.xml +504 -0
  44. data/test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Before_He_Cheats.xml +403 -0
  45. data/test/fixtures/xml/track/love_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml +2 -0
  46. data/test/fixtures/xml/user/getfriends_user_jnunemaker.xml +173 -0
  47. data/test/fixtures/xml/user/getinfo_user_jnunemaker.xml +22 -0
  48. data/test/fixtures/xml/user/getinfo_user_oaknd1.xml +22 -0
  49. data/test/fixtures/xml/user/getinfo_user_wharle.xml +22 -0
  50. data/test/fixtures/xml/user/getlovedtracks_user_jnunemaker.xml +775 -0
  51. data/test/fixtures/xml/user/getneighbours_user_jnunemaker.xml +503 -0
  52. data/test/fixtures/xml/user/getrecenttracks_user_jnunemaker.xml +133 -0
  53. data/test/fixtures/xml/user/getrecommendedartists_sk_token_user_jnunemaker.xml +553 -0
  54. data/test/fixtures/xml/user/gettopalbums_user_jnunemaker.xml +704 -0
  55. data/test/fixtures/xml/user/gettopartists_user_jnunemaker.xml +554 -0
  56. data/test/fixtures/xml/user/gettoptags_user_jnunemaker.xml +63 -0
  57. data/test/fixtures/xml/user/gettoptracks_user_jnunemaker.xml +750 -0
  58. data/test/fixtures/xml/user/getweeklyalbumchart_from_1138536002_to_1139140802_user_jnunemaker.xml +143 -0
  59. data/test/fixtures/xml/user/getweeklyalbumchart_from__to__user_jnunemaker.xml +31 -0
  60. data/test/fixtures/xml/user/getweeklyartistchart_from_1138536002_to_1139140802_user_jnunemaker.xml +201 -0
  61. data/test/fixtures/xml/user/getweeklyartistchart_from__to__user_jnunemaker.xml +21 -0
  62. data/test/fixtures/xml/user/getweeklychartlist_user_jnunemaker.xml +232 -0
  63. data/test/fixtures/xml/user/getweeklytrackchart_from_1138536002_to_1139140802_user_jnunemaker.xml +883 -0
  64. data/test/fixtures/xml/user/getweeklytrackchart_from__to__user_jnunemaker.xml +423 -0
  65. data/test/mocks/rest.rb +61 -0
  66. data/test/test_helper.rb +17 -0
  67. data/test/unit/test_album.rb +67 -0
  68. data/test/unit/test_artist.rb +69 -0
  69. data/test/unit/test_chart.rb +35 -0
  70. data/test/unit/test_playing.rb +53 -0
  71. data/test/unit/test_scrobble.rb +69 -0
  72. data/test/unit/test_simpleauth.rb +45 -0
  73. data/test/unit/test_tag.rb +57 -0
  74. data/test/unit/test_tokenauth.rb +45 -0
  75. data/test/unit/test_track.rb +44 -0
  76. data/test/unit/test_user.rb +252 -0
  77. metadata +190 -0
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/rockstar'
3
+ require File.dirname(__FILE__) + '/mocks/rest'
4
+
5
+ class << Test::Unit::TestCase
6
+ def test(name, &block)
7
+ test_name = :"test_#{name.gsub(' ','_')}"
8
+ raise ArgumentError, "#{test_name} is already defined" if self.instance_methods.include? test_name.to_s
9
+ define_method test_name, &block
10
+ end
11
+
12
+ def expect(expected_value, &block)
13
+ define_method :"test_#{caller.first.split("/").last}" do
14
+ assert_equal expected_value, instance_eval(&block)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestAlbum < Test::Unit::TestCase
4
+ def setup
5
+ @album = Rockstar::Album.new('Carrie Underwood', 'Some Hearts')
6
+ end
7
+
8
+ test 'should require the artist name' do
9
+ assert_raises(ArgumentError) { Rockstar::Album.new('', 'Some Hearts') }
10
+ end
11
+
12
+ test 'should require the track name' do
13
+ assert_raises(ArgumentError) { Rockstar::Album.new('Carrie Underwood', '') }
14
+ end
15
+
16
+ test 'should know the artist' do
17
+ assert_equal('Carrie Underwood', @album.artist)
18
+ end
19
+
20
+ test "should know it's name" do
21
+ assert_equal('Some Hearts', @album.name)
22
+ end
23
+
24
+ test 'should be able to load album info' do
25
+ @album.load_info
26
+ assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', @album.url)
27
+ assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), @album.release_date)
28
+ end
29
+
30
+ test 'should be able to find an ablum' do
31
+ album = Rockstar::Album.find('Carrie Underwood', 'Some Hearts')
32
+ assert_equal('Carrie Underwood', album.artist)
33
+ assert_equal('Some Hearts', album.name)
34
+ end
35
+
36
+ test "should be able to find an ablum and load the album's info" do
37
+ album = Rockstar::Album.find('Carrie Underwood', 'Some Hearts', :include_info => true)
38
+ assert_equal('Carrie Underwood', album.artist)
39
+ assert_equal('Some Hearts', album.name)
40
+ assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', album.url)
41
+ assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), album.release_date)
42
+ end
43
+
44
+ test "should be able to include the album's info on initialize" do
45
+ album = Rockstar::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
46
+ assert_equal('Carrie Underwood', album.artist)
47
+ assert_equal('Some Hearts', album.name)
48
+ assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', album.url)
49
+ assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), album.release_date)
50
+ end
51
+
52
+ test 'should have an image method that accepts a type' do
53
+ @album.load_info
54
+ assert_equal('http://userserve-ak.last.fm/serve/34s/34894445.png', @album.image(:small))
55
+ assert_equal('http://userserve-ak.last.fm/serve/64s/34894445.png', @album.image(:medium))
56
+ assert_equal('http://userserve-ak.last.fm/serve/174s/34894445.png', @album.image(:large))
57
+ end
58
+
59
+ test "should raise an argument error when attempting to get an image that doesn't exist" do
60
+ @album.load_info
61
+ assert_raises(ArgumentError) { @album.image(:fake) }
62
+ end
63
+
64
+ test 'should load info when trying to access an image if the info has not been loaded' do
65
+ assert_equal('http://userserve-ak.last.fm/serve/34s/34894445.png', @album.image(:small))
66
+ end
67
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestArtist < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @artist = Rockstar::Artist.new('Metallica')
7
+ end
8
+
9
+ test 'should require name' do
10
+ assert_raises(ArgumentError) { Rockstar::Artist.new('') }
11
+ end
12
+
13
+ test "should know it's name" do
14
+ assert_equal('Metallica', @artist.name)
15
+ end
16
+
17
+ test 'should be able to find similar artists' do
18
+ assert_equal(["Megadeth", "Slayer", "Iron Maiden", "Pantera", "Anthrax", "Sepultura"], @artist.similar.collect(&:name)[0..5])
19
+ first = @artist.similar.first
20
+ assert_equal('Megadeth', first.name)
21
+ assert_equal('a9044915-8be3-4c7e-b11f-9e2d2ea0a91e', first.mbid)
22
+ assert_equal('1', first.match)
23
+ assert_equal('http://www.last.fm/music/Megadeth', first.url)
24
+ assert_equal('http://userserve-ak.last.fm/serve/34/598154.jpg', first.thumbnail)
25
+ assert_equal('http://userserve-ak.last.fm/serve/64/598154.jpg', first.image)
26
+ assert_equal('http://userserve-ak.last.fm/serve/126/598154.jpg', first.images['large'])
27
+ assert_equal('yes', first.streamable)
28
+ end
29
+
30
+ test 'should be able to find top fans' do
31
+ assert_equal(["yIIyIIyIIy", "eliteveritas", "BrandonUCD", "Mithrandir93"], @artist.top_fans.collect(&:username)[0..3])
32
+ first = @artist.top_fans.first
33
+ assert_equal('yIIyIIyIIy', first.username)
34
+ assert_equal('http://www.last.fm/user/yIIyIIyIIy', first.url)
35
+ assert_equal('http://userserve-ak.last.fm/serve/34/40197285.jpg', first.avatar)
36
+ assert_equal('http://userserve-ak.last.fm/serve/34/40197285.jpg', first.images['small'])
37
+ assert_equal('http://userserve-ak.last.fm/serve/64/40197285.jpg', first.images['medium'])
38
+ assert_equal('http://userserve-ak.last.fm/serve/126/40197285.jpg', first.images['large'])
39
+ assert_equal('http://userserve-ak.last.fm/serve/252/40197285.jpg', first.images['extralarge'])
40
+ assert_equal('707560000', first.weight)
41
+ end
42
+
43
+ test 'should be able to find top tracks' do
44
+ assert_equal(['Nothing Else Matters', 'Enter Sandman', 'One', 'Master Of Puppets'], @artist.top_tracks.collect(&:name)[0..3])
45
+ first = @artist.top_tracks.first
46
+ assert_equal('Nothing Else Matters', first.name)
47
+ assert_equal('', first.mbid)
48
+ assert_equal('http://www.last.fm/music/Metallica/_/Nothing+Else+Matters', first.url)
49
+ end
50
+
51
+ test 'should be able to find top albums' do
52
+ assert_equal(["Master Of Puppets", "Death Magnetic", "Ride The Lightning"], @artist.top_albums.collect(&:name)[0..2])
53
+ first = @artist.top_albums.first
54
+ assert_equal('Master Of Puppets', first.name)
55
+ assert_equal('fed37cfc-2a6d-4569-9ac0-501a7c7598eb', first.mbid)
56
+ assert_equal('http://www.last.fm/music/Metallica/Master+Of+Puppets', first.url)
57
+ assert_equal('http://userserve-ak.last.fm/serve/34s/8622967.jpg', first.image(:small))
58
+ assert_equal('http://userserve-ak.last.fm/serve/64s/8622967.jpg', first.image(:medium))
59
+ assert_equal('http://userserve-ak.last.fm/serve/126/8622967.jpg', first.image(:large))
60
+ end
61
+
62
+ test 'should be able to find top tags' do
63
+ assert_equal(['thrash metal', 'metal', 'heavy metal'], @artist.top_tags.collect(&:name)[0..2])
64
+ first = @artist.top_tags.first
65
+ assert_equal('thrash metal', first.name)
66
+ assert_equal('100', first.count)
67
+ assert_equal('http://www.last.fm/tag/thrash%20metal', first.url)
68
+ end
69
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestChart < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @chart = Rockstar::Chart.new('1108296002', '1108900802')
7
+ end
8
+
9
+ test 'should require from' do
10
+ assert_raise(ArgumentError) { Rockstar::Chart.new('', '1108900802') }
11
+ end
12
+
13
+ test 'should require to' do
14
+ assert_raise(ArgumentError) { Rockstar::Chart.new('1108296002', '') }
15
+ end
16
+
17
+ test 'should be able to parse to and from that are unix timestamp strings' do
18
+ chart = Rockstar::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 = Rockstar::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 = Rockstar::Chart.new(Time.at(1108296002), Time.at(1108900802))
31
+ assert_equal(1108296002, chart.from)
32
+ assert_equal(1108900802, chart.to)
33
+ end
34
+
35
+ 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 = Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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 = Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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) { Rockstar::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
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestSimpleAuth < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @auth = Rockstar::SimpleAuth.new(:user => 'chunky', :password => 'bacon')
7
+ end
8
+
9
+ test 'should require a user' do
10
+ assert_raises(ArgumentError) { Rockstar::SimpleAuth.new(:password => 'bacon') }
11
+ end
12
+
13
+ test 'should require a password' do
14
+ assert_raises(ArgumentError) { Rockstar::SimpleAuth.new(:user => 'chunky') }
15
+ end
16
+
17
+ test 'should have the right client id' do
18
+ assert_equal('rbs', @auth.client_id)
19
+ end
20
+
21
+ test 'should have the right version' do
22
+ assert_equal(Rockstar::Version, @auth.client_ver)
23
+ end
24
+
25
+ test 'should handshake successfully' do
26
+ @auth.handshake!
27
+ assert_equal('OK', @auth.status)
28
+ end
29
+
30
+ test 'should get a session id' do
31
+ @auth.handshake!
32
+ assert_equal('17E61E13454CDD8B68E8D7DEEEDF6170', @auth.session_id)
33
+ end
34
+
35
+ test 'should get a now playing url' do
36
+ @auth.handshake!
37
+ assert_equal('http://62.216.251.203:80/nowplaying', @auth.now_playing_url)
38
+ end
39
+
40
+ test 'should get a submission url' do
41
+ @auth.handshake!
42
+ assert_equal('http://62.216.251.205:80/protocol_1.2', @auth.submission_url)
43
+ end
44
+
45
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestTag < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @tag = Rockstar::Tag.new('rock')
7
+ end
8
+
9
+ test 'should be able to find the top tags for the entire system' do
10
+ assert_equal(250, Rockstar::Tag.top_tags.size)
11
+ assert_equal('rock', Rockstar::Tag.top_tags.first.name)
12
+ assert_equal('2920270', Rockstar::Tag.top_tags.first.count)
13
+ assert_equal('http://www.last.fm/tag/rock', Rockstar::Tag.top_tags.first.url)
14
+ end
15
+
16
+ test 'should require name' do
17
+ assert_raise(ArgumentError) { Rockstar::Tag.new('') }
18
+ end
19
+
20
+ test 'should have name' do
21
+ assert_equal('rock', @tag.name)
22
+ end
23
+
24
+ test 'should be able to find top artists for a tag' do
25
+ assert_equal(50, @tag.top_artists.size)
26
+ assert_equal('The Beatles', @tag.top_artists.first.name)
27
+ assert_equal('yes', @tag.top_artists.first.streamable)
28
+ assert_equal('b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d', @tag.top_artists.first.mbid)
29
+ assert_equal('http://www.last.fm/music/The+Beatles', @tag.top_artists.first.url)
30
+ assert_equal('http://userserve-ak.last.fm/serve/34/4069917.jpg', @tag.top_artists.first.thumbnail)
31
+ assert_equal('http://userserve-ak.last.fm/serve/64/4069917.jpg', @tag.top_artists.first.image)
32
+ end
33
+
34
+ test 'should be able to find top albums for a tag' do
35
+ assert_equal(50, @tag.top_albums.size)
36
+ assert_equal('Stadium Arcadium', @tag.top_albums.first.name)
37
+ assert_equal('Red Hot Chili Peppers', @tag.top_albums.first.artist)
38
+ assert_equal('8bfac288-ccc5-448d-9573-c33ea2aa5c30', @tag.top_albums.first.artist_mbid)
39
+ assert_equal('http://www.last.fm/music/Red+Hot+Chili+Peppers/Stadium+Arcadium', @tag.top_albums.first.url)
40
+ assert_equal('http://userserve-ak.last.fm/serve/34s/8810061.jpg', @tag.top_albums.first.image(:small))
41
+ assert_equal('http://userserve-ak.last.fm/serve/64s/8810061.jpg', @tag.top_albums.first.image(:medium))
42
+ assert_equal('http://userserve-ak.last.fm/serve/126/8810061.jpg', @tag.top_albums.first.image(:large))
43
+ end
44
+
45
+ test 'should be able to find top tracks for a tag' do
46
+ assert_equal(50, @tag.top_tracks.size)
47
+ first = @tag.top_tracks.first
48
+ assert_equal('Californication', first.name)
49
+ assert_equal('yes', first.streamable)
50
+ assert_equal('Red Hot Chili Peppers', first.artist)
51
+ assert_equal('8bfac288-ccc5-448d-9573-c33ea2aa5c30', first.artist_mbid)
52
+ assert_equal('http://www.last.fm/music/Red+Hot+Chili+Peppers/_/Californication', first.url)
53
+ assert_equal('http://userserve-ak.last.fm/serve/34s/42739473.png', first.thumbnail)
54
+ assert_equal('http://userserve-ak.last.fm/serve/64s/42739473.png', first.image)
55
+ end
56
+
57
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class TestTokenAuth < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Rockstar.lastfm = {"api_secret" => 'secret', "api_key" => 'api'}
7
+ @auth = Rockstar::TokenAuth.new(:username => 'chunky', :token => 'bacon')
8
+ end
9
+
10
+ test 'should require a user' do
11
+ assert_raises(ArgumentError) { Rockstar::SimpleAuth.new(:token => 'bacon') }
12
+ end
13
+
14
+ test 'should require a password' do
15
+ assert_raises(ArgumentError) { Rockstar::SimpleAuth.new(:user => 'chunky') }
16
+ end
17
+
18
+ test 'should have the right client id' do
19
+ assert_equal('rbs', @auth.client_id)
20
+ end
21
+
22
+ test 'should have the right version' do
23
+ assert_equal(Rockstar::Version, @auth.client_ver)
24
+ end
25
+
26
+ test 'should handshake successfully' do
27
+ @auth.handshake!
28
+ assert_equal('OK', @auth.status)
29
+ end
30
+
31
+ test 'should get a session id' do
32
+ @auth.handshake!
33
+ assert_equal('17E61E13454CDD8B68E8D7DEEEDF6170', @auth.session_id)
34
+ end
35
+
36
+ test 'should get a now playing url' do
37
+ @auth.handshake!
38
+ assert_equal('http://62.216.251.203:80/nowplaying', @auth.now_playing_url)
39
+ end
40
+
41
+ test 'should get a submission url' do
42
+ @auth.handshake!
43
+ assert_equal('http://62.216.251.205:80/protocol_1.2', @auth.submission_url)
44
+ end
45
+ end