jonaustin-rockstar 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +8 -0
  3. data/Gemfile +10 -0
  4. data/Gemfile.lock +62 -0
  5. data/History.txt +6 -0
  6. data/MIT-LICENSE +19 -0
  7. data/Manifest +72 -0
  8. data/README.md +173 -0
  9. data/Rakefile +32 -0
  10. data/VERSION +1 -0
  11. data/examples/.gitignore +1 -0
  12. data/examples/album.rb +16 -0
  13. data/examples/artist.rb +25 -0
  14. data/examples/geo.rb +60 -0
  15. data/examples/lastfm.yml_example +3 -0
  16. data/examples/scrobble.rb +45 -0
  17. data/examples/tag.rb +20 -0
  18. data/examples/track.rb +14 -0
  19. data/examples/user.rb +18 -0
  20. data/lib/rockstar.rb +46 -0
  21. data/lib/rockstar/album.rb +104 -0
  22. data/lib/rockstar/artist.rb +183 -0
  23. data/lib/rockstar/auth.rb +38 -0
  24. data/lib/rockstar/base.rb +48 -0
  25. data/lib/rockstar/chart.rb +31 -0
  26. data/lib/rockstar/event.rb +73 -0
  27. data/lib/rockstar/geo.rb +47 -0
  28. data/lib/rockstar/library.rb +13 -0
  29. data/lib/rockstar/metro.rb +26 -0
  30. data/lib/rockstar/rest.rb +66 -0
  31. data/lib/rockstar/session.rb +19 -0
  32. data/lib/rockstar/tag.rb +100 -0
  33. data/lib/rockstar/track.rb +265 -0
  34. data/lib/rockstar/user.rb +205 -0
  35. data/lib/rockstar/venue.rb +59 -0
  36. data/lib/rockstar/version.rb +3 -0
  37. data/rockstar.gemspec +176 -0
  38. data/test/fixtures/xml/album/getinfo_album_Radio_Retalation_artist_Thievery_Corporation.xml +21 -0
  39. data/test/fixtures/xml/album/getinfo_album_Some_Hearts_artist_Carrie_Underwood.xml +63 -0
  40. data/test/fixtures/xml/artist/getevents_artist_Metallica.xml +1064 -0
  41. data/test/fixtures/xml/artist/getimages_artist_Metallica_page_2.xml +1074 -0
  42. data/test/fixtures/xml/artist/getinfo_artist_Metallica.xml +115 -0
  43. data/test/fixtures/xml/artist/getinfo_mbid_65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab.xml +115 -0
  44. data/test/fixtures/xml/artist/getsimilar_artist_Metallica.xml +1203 -0
  45. data/test/fixtures/xml/artist/gettopalbums_artist_Metallica.xml +704 -0
  46. data/test/fixtures/xml/artist/gettopfans_artist_Metallica.xml +504 -0
  47. data/test/fixtures/xml/artist/gettoptags_artist_Metallica.xml +403 -0
  48. data/test/fixtures/xml/artist/gettoptracks_artist_Metallica.xml +800 -0
  49. data/test/fixtures/xml/geo/getevents_location_london.xml +531 -0
  50. data/test/fixtures/xml/geo/getmetros_country_germany.xml +44 -0
  51. data/test/fixtures/xml/geo/gettopartists_country_spain_limit_50_page_.xml +561 -0
  52. data/test/fixtures/xml/geo/gettoptracks_country_spain_limit_50_page_.xml +1004 -0
  53. data/test/fixtures/xml/library/getalbums_user_jnunemaker.xml +704 -0
  54. data/test/fixtures/xml/library/getartists_user_jnunemaker.xml +554 -0
  55. data/test/fixtures/xml/tag/gettopalbums_tag_rock.xml +654 -0
  56. data/test/fixtures/xml/tag/gettopartists_tag_rock.xml +504 -0
  57. data/test/fixtures/xml/tag/gettoptags.xml +1253 -0
  58. data/test/fixtures/xml/tag/gettoptracks_tag_rock.xml +704 -0
  59. data/test/fixtures/xml/track/getinfo_artist_Carrie_Underwood_track_Before_He_Cheats.xml +55 -0
  60. data/test/fixtures/xml/track/getinfo_artist_Karrie_Underwood_track_Before_He_Cheats.xml +55 -0
  61. data/test/fixtures/xml/track/getsimilar_artist_Carrie_Underwood_limit_10_track_Before_He_Cheats.xml +185 -0
  62. data/test/fixtures/xml/track/gettopfans_artist_Carrie_Underwood_track_Before_He_Cheats.xml +504 -0
  63. data/test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Before_He_Cheats.xml +403 -0
  64. data/test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Wasted.xml +405 -0
  65. data/test/fixtures/xml/track/love_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml +2 -0
  66. data/test/fixtures/xml/track/updatenowplaying_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml +10 -0
  67. data/test/fixtures/xml/user/getevents_sk_token_user_bodot.xml +513 -0
  68. data/test/fixtures/xml/user/getfriends_user_jnunemaker.xml +173 -0
  69. data/test/fixtures/xml/user/getinfo_user_jnunemaker.xml +22 -0
  70. data/test/fixtures/xml/user/getinfo_user_oaknd1.xml +22 -0
  71. data/test/fixtures/xml/user/getinfo_user_wharle.xml +22 -0
  72. data/test/fixtures/xml/user/getlovedtracks_user_jnunemaker.xml +775 -0
  73. data/test/fixtures/xml/user/getneighbours_user_jnunemaker.xml +503 -0
  74. data/test/fixtures/xml/user/getrecenttracks_user_jnunemaker.xml +133 -0
  75. data/test/fixtures/xml/user/getrecommendedartists_sk_token_user_jnunemaker.xml +553 -0
  76. data/test/fixtures/xml/user/gettopalbums_user_jnunemaker.xml +704 -0
  77. data/test/fixtures/xml/user/gettopartists_period_3month_user_jnunemaker.xml +710 -0
  78. data/test/fixtures/xml/user/gettopartists_period_overall_user_jnunemaker.xml +554 -0
  79. data/test/fixtures/xml/user/gettoptags_user_jnunemaker.xml +63 -0
  80. data/test/fixtures/xml/user/gettoptracks_user_jnunemaker.xml +750 -0
  81. data/test/fixtures/xml/user/getweeklyalbumchart_from_1138536002_to_1139140802_user_jnunemaker.xml +143 -0
  82. data/test/fixtures/xml/user/getweeklyalbumchart_from__to__user_jnunemaker.xml +31 -0
  83. data/test/fixtures/xml/user/getweeklyartistchart_from_1138536002_to_1139140802_user_jnunemaker.xml +201 -0
  84. data/test/fixtures/xml/user/getweeklyartistchart_from__to__user_jnunemaker.xml +21 -0
  85. data/test/fixtures/xml/user/getweeklychartlist_user_jnunemaker.xml +232 -0
  86. data/test/fixtures/xml/user/getweeklytrackchart_from_1138536002_to_1139140802_user_jnunemaker.xml +883 -0
  87. data/test/fixtures/xml/user/getweeklytrackchart_from__to__user_jnunemaker.xml +423 -0
  88. data/test/fixtures/xml/venue/getevents_venue_8807850.xml +280 -0
  89. data/test/fixtures/xml/venue/search_country__limit__page__venue_country_DE_venue_cotton.xml +72 -0
  90. data/test/mocks/rest.rb +50 -0
  91. data/test/test_helper.rb +18 -0
  92. data/test/unit/test_album.rb +76 -0
  93. data/test/unit/test_artist.rb +123 -0
  94. data/test/unit/test_chart.rb +35 -0
  95. data/test/unit/test_geo.rb +51 -0
  96. data/test/unit/test_library.rb +65 -0
  97. data/test/unit/test_rockstar.rb +15 -0
  98. data/test/unit/test_tag.rb +57 -0
  99. data/test/unit/test_track.rb +93 -0
  100. data/test/unit/test_user.rb +309 -0
  101. data/test/unit/test_venue.rb +20 -0
  102. metadata +243 -0
@@ -0,0 +1,72 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <results for="cotton" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
4
+ <opensearch:Query role="request" searchTerms="cotton" startPage="1" />
5
+ <opensearch:totalResults>3</opensearch:totalResults>
6
+ <opensearch:startIndex>0</opensearch:startIndex>
7
+ <opensearch:itemsPerPage>50</opensearch:itemsPerPage><venuematches>
8
+ <venue>
9
+ <id>8891678</id>
10
+ <name>Cotton Club</name>
11
+ <location>
12
+ <city>Hamburg</city>
13
+ <country>Germany</country>
14
+ <street>Alter Steinweg 10</street>
15
+ <postalcode>20459</postalcode>
16
+ <geo:point>
17
+ <geo:lat>53.550374</geo:lat>
18
+ <geo:long>9.98205</geo:long>
19
+ </geo:point>
20
+ </location>
21
+ <url>http://www.last.fm/venue/8891678+Cotton+Club</url>
22
+ <website>http://www.cotton-club.de/</website>
23
+ <phonenumber>+49 (0)40 343878</phonenumber>
24
+ <image size="small"></image>
25
+ <image size="medium"></image>
26
+ <image size="large"></image>
27
+ <image size="extralarge"></image>
28
+ <image size="mega"></image>
29
+ </venue> <venue>
30
+ <id>9036090</id>
31
+ <name>Cotton Club</name>
32
+ <location>
33
+ <city>Künzelsau</city>
34
+ <country>Germany</country>
35
+ <street></street>
36
+ <postalcode></postalcode>
37
+ <geo:point>
38
+ <geo:lat>49.280909</geo:lat>
39
+ <geo:long>9.690339</geo:long>
40
+ </geo:point>
41
+ </location>
42
+ <url>http://www.last.fm/venue/9036090+Cotton+Club</url>
43
+ <website></website>
44
+ <phonenumber></phonenumber>
45
+ <image size="small"></image>
46
+ <image size="medium"></image>
47
+ <image size="large"></image>
48
+ <image size="extralarge"></image>
49
+ <image size="mega"></image>
50
+ </venue> <venue>
51
+ <id>9087817</id>
52
+ <name>CottonClub</name>
53
+ <location>
54
+ <city>Kaiserslautern</city>
55
+ <country>Germany</country>
56
+ <street></street>
57
+ <postalcode></postalcode>
58
+ <geo:point>
59
+ <geo:lat>49.44702</geo:lat>
60
+ <geo:long>7.756832</geo:long>
61
+ </geo:point>
62
+ </location>
63
+ <url>http://www.last.fm/venue/9087817+CottonClub</url>
64
+ <website></website>
65
+ <phonenumber></phonenumber>
66
+ <image size="small"></image>
67
+ <image size="medium"></image>
68
+ <image size="large"></image>
69
+ <image size="extralarge"></image>
70
+ <image size="mega"></image>
71
+ </venue></venuematches>
72
+ </results></lfm>
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../../lib/rockstar/rest'
2
+ require 'digest/md5'
3
+
4
+ module Rockstar
5
+ module REST
6
+ class Connection
7
+
8
+ def flatten(arg)
9
+ if arg.class == Hash
10
+ return arg.keys.sort_by{|a|a.to_s}.collect { |k| "%s_%s" % [k.to_s, flatten(arg[k])] }.join("_").gsub(" ", "_")
11
+ end
12
+ arg.to_s
13
+ end
14
+
15
+ # reads xml fixture file instead of hitting up the internets
16
+ def request(resource, method = "get", args = {}, sign_request=false)
17
+ @now_playing_url = 'http://62.216.251.203:80/nowplaying'
18
+ @submission_url = 'http://62.216.251.205:80/protocol_1.2'
19
+ @session_id = '17E61E13454CDD8B68E8D7DEEEDF6170'
20
+
21
+ if @base_url == Rockstar::API_URL + Rockstar::API_VERSION + "/"
22
+ folder, file = resource.downcase.split(".")
23
+
24
+ query = ""
25
+ if args.size > 0
26
+ query = "_" + flatten(args)
27
+ end
28
+
29
+ file = File.dirname(__FILE__) + "/../fixtures/xml/#{folder}/#{file}#{query}.xml"
30
+
31
+ if (!File.exists? file)
32
+ puts "Mock file not found : #{file}"
33
+ else
34
+ File.read(file)
35
+ end
36
+ elsif @base_url == @now_playing_url
37
+ if args[:s] == @session_id && args.length == 7 && ![args[:a], args[:t], args[:b], args[:n]].any?(&:blank?)
38
+ 'OK'
39
+ end
40
+ elsif @base_url == @submission_url
41
+ if args[:s] == @session_id && args.length == 10 &&
42
+ ![args['a[0]'], args['t[0]'], args['i[0]'], args['o[0]'], args['l[0]'], args['b[0]']].any?(&:blank?)
43
+ 'OK'
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+
3
+ require File.expand_path('../../lib/rockstar', __FILE__)
4
+ require File.expand_path('..//mocks/rest', __FILE__)
5
+
6
+ class << Test::Unit::TestCase
7
+ def test(name, &block)
8
+ test_name = :"test_#{name.gsub(' ','_')}"
9
+ raise ArgumentError, "#{test_name} is already defined" if self.instance_methods.include? test_name.to_s
10
+ define_method test_name, &block
11
+ end
12
+
13
+ def expect(expected_value, &block)
14
+ define_method :"test_#{caller.first.split("/").last}" do
15
+ assert_equal expected_value, instance_eval(&block)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path('../../test_helper.rb', __FILE__)
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
+ assert_match(/debut album from fourth-season American Idol winner/, @album.summary)
29
+ end
30
+
31
+ test 'should be able to find an ablum' do
32
+ album = Rockstar::Album.find('Carrie Underwood', 'Some Hearts')
33
+ assert_equal('Carrie Underwood', album.artist)
34
+ assert_equal('Some Hearts', album.name)
35
+ end
36
+
37
+ test "should be able to find an ablum and load the album's info" do
38
+ album = Rockstar::Album.find('Carrie Underwood', 'Some Hearts', :include_info => true)
39
+ assert_equal('Carrie Underwood', album.artist)
40
+ assert_equal('Some Hearts', album.name)
41
+ assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', album.url)
42
+ assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), album.release_date)
43
+ assert_match(/debut album from fourth-season American Idol winner/, album.summary)
44
+ end
45
+
46
+ test "should be able to request detailed album info on initialize" do
47
+ album = Rockstar::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
48
+ assert_equal('Carrie Underwood', album.artist)
49
+ assert_equal('Some Hearts', album.name)
50
+ assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', album.url)
51
+ assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), album.release_date)
52
+ assert_match(/debut album from fourth-season American Idol winner/, album.summary)
53
+ end
54
+
55
+ test 'should have an image method that accepts a type' do
56
+ @album.load_info
57
+ assert_equal('http://userserve-ak.last.fm/serve/34s/34894445.png', @album.image(:small))
58
+ assert_equal('http://userserve-ak.last.fm/serve/64s/34894445.png', @album.image(:medium))
59
+ assert_equal('http://userserve-ak.last.fm/serve/174s/34894445.png', @album.image(:large))
60
+ end
61
+
62
+ test "should raise an argument error when attempting to get an image that doesn't exist" do
63
+ @album.load_info
64
+ assert_raises(ArgumentError) { @album.image(:fake) }
65
+ end
66
+
67
+ test 'should load info when trying to access an image if the info has not been loaded' do
68
+ assert_equal('http://userserve-ak.last.fm/serve/34s/34894445.png', @album.image(:small))
69
+ end
70
+
71
+ test 'should parse empty album' do
72
+ album = Rockstar::Album.new('Thievery Corporation', 'Radio Retalation')
73
+ album.load_info
74
+ assert_nil album.summary
75
+ end
76
+ end
@@ -0,0 +1,123 @@
1
+ require File.expand_path('../../test_helper.rb', __FILE__)
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 load artist info" do
18
+ @artist.load_info
19
+ assert_equal("http://www.last.fm/music/Metallica", @artist.url)
20
+ assert_equal("65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab", @artist.mbid)
21
+ assert_match(/an American metal band formed in 1981/, @artist.summary)
22
+ end
23
+
24
+ test "should load artist info when initialized" do
25
+ artist = Rockstar::Artist.new("Metallica", :include_info => true)
26
+ assert_equal("http://www.last.fm/music/Metallica", artist.url)
27
+ assert_equal("65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab", artist.mbid)
28
+ assert_match(/an American metal band formed in 1981/, artist.summary)
29
+ assert_equal("http://userserve-ak.last.fm/serve/64/3679639.jpg", artist.images['medium'])
30
+ assert_equal("http://userserve-ak.last.fm/serve/64/3679639.jpg", artist.images['medium'])
31
+ end
32
+
33
+ test 'should return the default artist profile image' do
34
+ assert_equal("http://userserve-ak.last.fm/serve/64/3679639.jpg", @artist.image)
35
+ assert_equal("thrash metal", @artist.tags.first)
36
+ end
37
+
38
+ test 'should load additional user images' do
39
+ images = @artist.user_images(:page => 2)
40
+ assert_equal("http://userserve-ak.last.fm/serve/126/3679639.jpg", images[0]['large'])
41
+ assert_equal("http://userserve-ak.last.fm/serve/252/13440.jpg", images[1]['extralarge'])
42
+ end
43
+
44
+ test 'should be able to find similar artists' do
45
+ assert_equal(["Megadeth", "Slayer", "Iron Maiden", "Pantera", "Anthrax", "Sepultura"], @artist.similar.collect(&:name)[0..5])
46
+ first = @artist.similar.first
47
+ assert_equal('Megadeth', first.name)
48
+ assert_equal('a9044915-8be3-4c7e-b11f-9e2d2ea0a91e', first.mbid)
49
+ assert_equal('1', first.match)
50
+ assert_equal('http://www.last.fm/music/Megadeth', first.url)
51
+ assert_equal('http://userserve-ak.last.fm/serve/34/598154.jpg', first.thumbnail)
52
+ assert_equal('http://userserve-ak.last.fm/serve/64/598154.jpg', first.image)
53
+ assert_equal('http://userserve-ak.last.fm/serve/126/598154.jpg', first.images['large'])
54
+ assert_equal('yes', first.streamable)
55
+ end
56
+
57
+ test 'should be able to find top fans' do
58
+ assert_equal(["yIIyIIyIIy", "eliteveritas", "BrandonUCD", "Mithrandir93"], @artist.top_fans.collect(&:username)[0..3])
59
+ first = @artist.top_fans.first
60
+ assert_equal('yIIyIIyIIy', first.username)
61
+ assert_equal('http://www.last.fm/user/yIIyIIyIIy', first.url)
62
+ assert_equal('http://userserve-ak.last.fm/serve/34/40197285.jpg', first.avatar)
63
+ assert_equal('http://userserve-ak.last.fm/serve/34/40197285.jpg', first.images['small'])
64
+ assert_equal('http://userserve-ak.last.fm/serve/64/40197285.jpg', first.images['medium'])
65
+ assert_equal('http://userserve-ak.last.fm/serve/126/40197285.jpg', first.images['large'])
66
+ assert_equal('http://userserve-ak.last.fm/serve/252/40197285.jpg', first.images['extralarge'])
67
+ assert_equal('707560000', first.weight)
68
+ end
69
+
70
+ test 'should be able to find top tracks' do
71
+ assert_equal(['Nothing Else Matters', 'Enter Sandman', 'One', 'Master Of Puppets'], @artist.top_tracks.collect(&:name)[0..3])
72
+ first = @artist.top_tracks.first
73
+ assert_equal('Nothing Else Matters', first.name)
74
+ assert_equal('', first.mbid)
75
+ assert_equal('http://www.last.fm/music/Metallica/_/Nothing+Else+Matters', first.url)
76
+ end
77
+
78
+ test 'should be able to find top albums' do
79
+ assert_equal(["Master Of Puppets", "Death Magnetic", "Ride The Lightning"], @artist.top_albums.collect(&:name)[0..2])
80
+ first = @artist.top_albums.first
81
+ assert_equal('Master Of Puppets', first.name)
82
+ assert_equal('fed37cfc-2a6d-4569-9ac0-501a7c7598eb', first.mbid)
83
+ assert_equal('http://www.last.fm/music/Metallica/Master+Of+Puppets', first.url)
84
+ assert_equal('http://userserve-ak.last.fm/serve/34s/8622967.jpg', first.image(:small))
85
+ assert_equal('http://userserve-ak.last.fm/serve/64s/8622967.jpg', first.image(:medium))
86
+ assert_equal('http://userserve-ak.last.fm/serve/126/8622967.jpg', first.image(:large))
87
+ end
88
+
89
+ test 'should be able to find top tags' do
90
+ assert_equal(['thrash metal', 'metal', 'heavy metal'], @artist.top_tags.collect(&:name)[0..2])
91
+ first = @artist.top_tags.first
92
+ assert_equal('thrash metal', first.name)
93
+ assert_equal('100', first.count)
94
+ assert_equal('http://www.last.fm/tag/thrash%20metal', first.url)
95
+ end
96
+
97
+ test 'should be able to find upcoming events' do
98
+ events = @artist.events
99
+ assert_equal(14, events.length)
100
+ assert_equal('The Big Four - Metallica, Slayer, Megadeth, Anthrax', events.first.title)
101
+ assert_equal('07/02/11', events.first.start_date.strftime("%D"))
102
+ end
103
+
104
+ test 'should load artist by mbid' do
105
+ artist = Rockstar::Artist.new(nil,
106
+ :mbid => "65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab",
107
+ :include_info => true)
108
+ assert_equal("Metallica", artist.name)
109
+ assert_equal("http://www.last.fm/music/Metallica", artist.url)
110
+ assert_equal("http://www.last.fm/music/Metallica", artist.url)
111
+ assert_equal("65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab", artist.mbid)
112
+ assert_match(/an American metal band formed in 1981/, artist.summary)
113
+ end
114
+
115
+ test 'should use last.fm artist name for returned artist name' do
116
+ artist = Rockstar::Artist.new('metallica', :include_info => true)
117
+ assert_equal("Metallica", artist.name)
118
+ assert_equal("http://www.last.fm/music/Metallica", artist.url)
119
+ assert_equal("http://www.last.fm/music/Metallica", artist.url)
120
+ assert_equal("65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab", artist.mbid)
121
+ assert_match(/an American metal band formed in 1981/, artist.summary)
122
+ end
123
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path('../../test_helper.rb', __FILE__)
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,51 @@
1
+ require File.expand_path('../../test_helper.rb', __FILE__)
2
+
3
+ class TestGeo < Test::Unit::TestCase
4
+
5
+ test "should get events in london" do
6
+ geo = Rockstar::Geo.new
7
+ events = geo.events({:location => 'london'})
8
+
9
+ assert_equal(10, events.size)
10
+ assert_equal("Basement Scam", events.first.title)
11
+ assert_equal("Buffalo Bar", events.first.venue.name)
12
+ assert_equal("London", events.first.venue.city)
13
+ end
14
+
15
+ test "get cities for a country" do
16
+ geo = Rockstar::Geo.new
17
+
18
+ metros = geo.metros("germany")
19
+ assert_equal(10, metros.size)
20
+ assert_equal("Bremen", metros.first.name)
21
+ assert_equal("Germany", metros.first.country)
22
+ end
23
+
24
+ test "should get top artists for a country" do
25
+ limit = 50 #the mock resultset has 50 in so just fake this
26
+
27
+ geo = Rockstar::Geo.new
28
+
29
+ artists = geo.topartists("spain", limit)
30
+ assert_equal(limit, artists.size)
31
+ assert_equal("Muse", artists.first.name)
32
+ assert_equal("1695c115-bf3f-4014-9966-2b0c50179193", artists.first.mbid)
33
+ assert_equal('1736', artists.first.listenercount)
34
+
35
+ end
36
+
37
+ test "should get top tracks for a country" do
38
+ limit = 50 #the mock resultset has 50 in so just fake this
39
+
40
+ geo = Rockstar::Geo.new
41
+
42
+ tracks = geo.toptracks("spain", limit)
43
+ assert_equal(limit, tracks.size)
44
+ assert_equal("Diamonds", tracks.first.name)
45
+ assert_equal("Rihanna", tracks.first.artist)
46
+ assert_equal("f281056d-5696-43d0-bb2e-61677ef65309", tracks.first.mbid)
47
+
48
+ end
49
+
50
+
51
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../../test_helper.rb', __FILE__)
3
+
4
+ class TestLibrary < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @library = Rockstar::Library.new
8
+ @user = Rockstar::User.new('jnunemaker')
9
+ end
10
+
11
+ test "should be able to get a user's library artists" do
12
+ assert_equal(50, @library.artists(false, { :user => @user.username }).size)
13
+ first = @library.artists(false, { :user => @user.username }).first
14
+ assert_equal('Taylor Swift', first.name)
15
+ assert_equal('20244d07-534f-4eff-b4d4-930878889970', first.mbid)
16
+ assert_equal('1392', first.playcount)
17
+ assert_equal('1', first.rank)
18
+ assert_equal('http://www.last.fm/music/Taylor+Swift', first.url)
19
+ assert_equal('http://userserve-ak.last.fm/serve/34/30883349.png', first.thumbnail)
20
+ assert_equal('http://userserve-ak.last.fm/serve/64/30883349.png', first.image)
21
+ end
22
+
23
+ test "should be able to get a user's library artists via wrapper" do
24
+ assert_equal(50, @user.artists.size)
25
+ first = @user.artists.first
26
+ assert_equal('Taylor Swift', first.name)
27
+ assert_equal('20244d07-534f-4eff-b4d4-930878889970', first.mbid)
28
+ assert_equal('1392', first.playcount)
29
+ assert_equal('1', first.rank)
30
+ assert_equal('http://www.last.fm/music/Taylor+Swift', first.url)
31
+ assert_equal('http://userserve-ak.last.fm/serve/34/30883349.png', first.thumbnail)
32
+ assert_equal('http://userserve-ak.last.fm/serve/64/30883349.png', first.image)
33
+ end
34
+
35
+ test "should be able to get a user's library albums" do
36
+ assert_equal(50, @library.albums(false, { :user => @user.username }).size)
37
+ first = @library.albums(false, { :user => @user.username }).first
38
+ assert_equal('Dwight Yoakam', first.artist)
39
+ assert_equal('0fb711af-c7ba-4bdc-b0b6-b8495fc0a590', first.artist_mbid)
40
+ assert_equal('The Very Best of Dwight Yoakam', first.name)
41
+ assert_equal('b6a051b4-1a1e-4c33-a1e5-0ea6e920a13f', first.mbid)
42
+ assert_equal('560', first.playcount)
43
+ assert_equal('1', first.rank)
44
+ assert_equal('http://www.last.fm/music/Dwight+Yoakam/The+Very+Best+of+Dwight+Yoakam', first.url)
45
+ assert_equal('http://userserve-ak.last.fm/serve/34s/8725405.jpg', first.image(:small))
46
+ assert_equal('http://userserve-ak.last.fm/serve/64s/8725405.jpg', first.image(:medium))
47
+ assert_equal('http://userserve-ak.last.fm/serve/126/8725405.jpg', first.image(:large))
48
+ end
49
+
50
+ test "should be able to get a user's library albums via wrapper" do
51
+ assert_equal(50, @user.albums.size)
52
+ first = @user.albums.first
53
+ assert_equal('Dwight Yoakam', first.artist)
54
+ assert_equal('0fb711af-c7ba-4bdc-b0b6-b8495fc0a590', first.artist_mbid)
55
+ assert_equal('The Very Best of Dwight Yoakam', first.name)
56
+ assert_equal('b6a051b4-1a1e-4c33-a1e5-0ea6e920a13f', first.mbid)
57
+ assert_equal('560', first.playcount)
58
+ assert_equal('1', first.rank)
59
+ assert_equal('http://www.last.fm/music/Dwight+Yoakam/The+Very+Best+of+Dwight+Yoakam', first.url)
60
+ assert_equal('http://userserve-ak.last.fm/serve/34s/8725405.jpg', first.image(:small))
61
+ assert_equal('http://userserve-ak.last.fm/serve/64s/8725405.jpg', first.image(:medium))
62
+ assert_equal('http://userserve-ak.last.fm/serve/126/8725405.jpg', first.image(:large))
63
+ end
64
+
65
+ end