titanous-scrobbler 0.2.2
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.
- data/History.txt +3 -0
 - data/MIT-LICENSE +19 -0
 - data/Manifest +67 -0
 - data/README.rdoc +107 -0
 - data/Rakefile +36 -0
 - data/examples/album.rb +17 -0
 - data/examples/artist.rb +13 -0
 - data/examples/scrobble.rb +31 -0
 - data/examples/tag.rb +11 -0
 - data/examples/track.rb +6 -0
 - data/examples/user.rb +14 -0
 - data/lib/scrobbler/album.rb +143 -0
 - data/lib/scrobbler/artist.rb +127 -0
 - data/lib/scrobbler/base.rb +29 -0
 - data/lib/scrobbler/chart.rb +31 -0
 - data/lib/scrobbler/playing.rb +49 -0
 - data/lib/scrobbler/rest.rb +47 -0
 - data/lib/scrobbler/scrobble.rb +66 -0
 - data/lib/scrobbler/simpleauth.rb +59 -0
 - data/lib/scrobbler/tag.rb +104 -0
 - data/lib/scrobbler/track.rb +96 -0
 - data/lib/scrobbler/user.rb +192 -0
 - data/lib/scrobbler/version.rb +3 -0
 - data/lib/scrobbler.rb +20 -0
 - data/scrobbler.gemspec +41 -0
 - data/setup.rb +1585 -0
 - data/test/fixtures/xml/album/info.xml +70 -0
 - data/test/fixtures/xml/artist/fans.xml +18 -0
 - data/test/fixtures/xml/artist/similar.xml +39 -0
 - data/test/fixtures/xml/artist/topalbums.xml +36 -0
 - data/test/fixtures/xml/artist/toptags.xml +18 -0
 - data/test/fixtures/xml/artist/toptracks.xml +27 -0
 - data/test/fixtures/xml/tag/topalbums.xml +39 -0
 - data/test/fixtures/xml/tag/topartists.xml +39 -0
 - data/test/fixtures/xml/tag/toptags.xml +252 -0
 - data/test/fixtures/xml/tag/toptracks.xml +30 -0
 - data/test/fixtures/xml/track/fans.xml +28 -0
 - data/test/fixtures/xml/track/toptags.xml +33 -0
 - data/test/fixtures/xml/user/friends.xml +21 -0
 - data/test/fixtures/xml/user/neighbours.xml +18 -0
 - data/test/fixtures/xml/user/profile.xml +12 -0
 - data/test/fixtures/xml/user/recentbannedtracks.xml +24 -0
 - data/test/fixtures/xml/user/recentlovedtracks.xml +24 -0
 - data/test/fixtures/xml/user/recenttracks.xml +27 -0
 - data/test/fixtures/xml/user/systemrecs.xml +18 -0
 - data/test/fixtures/xml/user/topalbums.xml +42 -0
 - data/test/fixtures/xml/user/topartists.xml +30 -0
 - data/test/fixtures/xml/user/toptags.xml +18 -0
 - data/test/fixtures/xml/user/toptracks.xml +27 -0
 - data/test/fixtures/xml/user/weeklyalbumchart.xml +35 -0
 - data/test/fixtures/xml/user/weeklyalbumchart_from_1138536002_to_1139140802.xml +35 -0
 - data/test/fixtures/xml/user/weeklyartistchart.xml +38 -0
 - data/test/fixtures/xml/user/weeklyartistchart_from_1138536002_to_1139140802.xml +59 -0
 - data/test/fixtures/xml/user/weeklychartlist.xml +74 -0
 - data/test/fixtures/xml/user/weeklytrackchart.xml +35 -0
 - data/test/fixtures/xml/user/weeklytrackchart_from_1138536002_to_1139140802.xml +35 -0
 - data/test/mocks/rest.rb +50 -0
 - data/test/test_helper.rb +17 -0
 - data/test/unit/album_test.rb +86 -0
 - data/test/unit/artist_test.rb +82 -0
 - data/test/unit/chart_test.rb +34 -0
 - data/test/unit/playing_test.rb +53 -0
 - data/test/unit/scrobble_test.rb +69 -0
 - data/test/unit/simpleauth_test.rb +45 -0
 - data/test/unit/tag_test.rb +65 -0
 - data/test/unit/track_test.rb +42 -0
 - data/test/unit/user_test.rb +291 -0
 - metadata +172 -0
 
| 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <?xml version="1.0" encoding="UTF-8"?>
         
     | 
| 
      
 2 
     | 
    
         
            +
            <weeklytrackchart user="jnunemaker" from="1138536002" to="1139140802">
         
     | 
| 
      
 3 
     | 
    
         
            +
            	<track>
         
     | 
| 
      
 4 
     | 
    
         
            +
            		<artist mbid="8b477559-946e-4ef2-9fe1-446cff8fdd79">Natasha Bedingfield</artist>
         
     | 
| 
      
 5 
     | 
    
         
            +
            		<name>Unwritten</name>
         
     | 
| 
      
 6 
     | 
    
         
            +
            		<mbid></mbid>
         
     | 
| 
      
 7 
     | 
    
         
            +
            		<chartposition>1</chartposition>
         
     | 
| 
      
 8 
     | 
    
         
            +
            		<playcount>8</playcount>
         
     | 
| 
      
 9 
     | 
    
         
            +
            		<url>http://www.last.fm/music/Natasha+Bedingfield/_/Unwritten</url>
         
     | 
| 
      
 10 
     | 
    
         
            +
            	</track>
         
     | 
| 
      
 11 
     | 
    
         
            +
            	<track>
         
     | 
| 
      
 12 
     | 
    
         
            +
            		<artist mbid="d43d12a1-2dc9-4257-a2fd-0a3bb1081b86">Johnny Cash</artist>
         
     | 
| 
      
 13 
     | 
    
         
            +
            		<name>Hurt</name>
         
     | 
| 
      
 14 
     | 
    
         
            +
            		<mbid></mbid>
         
     | 
| 
      
 15 
     | 
    
         
            +
            		<chartposition>2</chartposition>
         
     | 
| 
      
 16 
     | 
    
         
            +
            		<playcount>6</playcount>
         
     | 
| 
      
 17 
     | 
    
         
            +
            		<url>http://www.last.fm/music/Johnny+Cash/_/Hurt</url>
         
     | 
| 
      
 18 
     | 
    
         
            +
            	</track>
         
     | 
| 
      
 19 
     | 
    
         
            +
            	<track>
         
     | 
| 
      
 20 
     | 
    
         
            +
            		<artist mbid="ba853904-ae25-4ebb-89d6-c44cfbd71bd2">Blur</artist>
         
     | 
| 
      
 21 
     | 
    
         
            +
            		<name>Song 2</name>
         
     | 
| 
      
 22 
     | 
    
         
            +
            		<mbid></mbid>
         
     | 
| 
      
 23 
     | 
    
         
            +
            		<chartposition>3</chartposition>
         
     | 
| 
      
 24 
     | 
    
         
            +
            		<playcount>4</playcount>
         
     | 
| 
      
 25 
     | 
    
         
            +
            		<url>http://www.last.fm/music/Blur/_/Song+2</url>
         
     | 
| 
      
 26 
     | 
    
         
            +
            	</track>
         
     | 
| 
      
 27 
     | 
    
         
            +
            	<track>
         
     | 
| 
      
 28 
     | 
    
         
            +
            		<artist mbid="bc710bcf-8815-42cf-bad2-3f1d12246aeb">Nickelback</artist>
         
     | 
| 
      
 29 
     | 
    
         
            +
            		<name>Photograph</name>
         
     | 
| 
      
 30 
     | 
    
         
            +
            		<mbid></mbid>
         
     | 
| 
      
 31 
     | 
    
         
            +
            		<chartposition>3</chartposition>
         
     | 
| 
      
 32 
     | 
    
         
            +
            		<playcount>4</playcount>
         
     | 
| 
      
 33 
     | 
    
         
            +
            		<url>http://www.last.fm/music/Nickelback/_/Photograph</url>
         
     | 
| 
      
 34 
     | 
    
         
            +
            	</track>
         
     | 
| 
      
 35 
     | 
    
         
            +
            </weeklytrackchart>
         
     | 
    
        data/test/mocks/rest.rb
    ADDED
    
    | 
         @@ -0,0 +1,50 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
                	    pieces.shift
         
     | 
| 
      
 17 
     | 
    
         
            +
                	    folder = pieces.shift
         
     | 
| 
      
 18 
     | 
    
         
            +
                	    file   = pieces.last[0, pieces.last.index('.xml')]
         
     | 
| 
      
 19 
     | 
    
         
            +
                	    base_pieces = pieces.last.split('?')
         
     | 
| 
      
 20 
     | 
    
         
            +
              	    
         
     | 
| 
      
 21 
     | 
    
         
            +
                	    file = if base_pieces.size > 1
         
     | 
| 
      
 22 
     | 
    
         
            +
                	      # if query string params are in resource they are underscore separated for filenames
         
     | 
| 
      
 23 
     | 
    
         
            +
                	      base_pieces.last.split('&').inject("#{file}_") { |str, pair| str << pair.split('=').join('_') + '_'; str }.chop!
         
     | 
| 
      
 24 
     | 
    
         
            +
              	      else
         
     | 
| 
      
 25 
     | 
    
         
            +
              	        file
         
     | 
| 
      
 26 
     | 
    
         
            +
                      end
         
     | 
| 
      
 27 
     | 
    
         
            +
              	    
         
     | 
| 
      
 28 
     | 
    
         
            +
                	    File.read(File.dirname(__FILE__) + "/../fixtures/xml/#{folder}/#{file}.xml")
         
     | 
| 
      
 29 
     | 
    
         
            +
              	    elsif @base_url == Scrobbler::AUTH_URL
         
     | 
| 
      
 30 
     | 
    
         
            +
                      if args[:hs] == "true" && args[:p] == Scrobbler::AUTH_VER.to_s && args[:c] == 'rbs' &&
         
     | 
| 
      
 31 
     | 
    
         
            +
                         args[:v] == Scrobbler::Version.to_s && args[:u] == 'chunky' && !args[:t].blank? &&
         
     | 
| 
      
 32 
     | 
    
         
            +
                         args[:a] == Digest::MD5.hexdigest('7813258ef8c6b632dde8cc80f6bda62f' + args[:t])
         
     | 
| 
      
 33 
     | 
    
         
            +
                        
         
     | 
| 
      
 34 
     | 
    
         
            +
                        "OK\n#{@session_id}\n#{@now_playing_url}\n#{@submission_url}"
         
     | 
| 
      
 35 
     | 
    
         
            +
                      end
         
     | 
| 
      
 36 
     | 
    
         
            +
                    elsif @base_url == @now_playing_url
         
     | 
| 
      
 37 
     | 
    
         
            +
                      if args[:s] == @session_id && ![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 && 
         
     | 
| 
      
 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
         
     | 
    
        data/test/test_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../lib/scrobbler'
         
     | 
| 
      
 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,86 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
              test 'should require the artist name' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                assert_raises(ArgumentError) { Scrobbler::Album.new('', 'Some Hearts') }
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
              
         
     | 
| 
      
 13 
     | 
    
         
            +
              test 'should require the track name' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                assert_raises(ArgumentError) { Scrobbler::Album.new('Carrie Underwood', '') }
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
              test 'should know the artist' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal('Carrie Underwood', @album.artist)
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
              test "should know it's name" do
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_equal('Some Hearts', @album.name)
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
              test 'should have correct api path' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                assert_equal("/1.0/album/Carrie+Underwood/Some+Hearts", @album.api_path)
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
              
         
     | 
| 
      
 29 
     | 
    
         
            +
              test 'should be able to load album info' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                @album.load_info
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert_equal('18589', @album.reach)
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', @album.url)
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), @album.release_date)
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_equal(14, @album.tracks.size)
         
     | 
| 
      
 35 
     | 
    
         
            +
                assert_equal('Wasted', @album.tracks.first.name)
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Carrie+Underwood/_/Wasted', @album.tracks.first.url)
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_equal('6738', @album.tracks.first.reach)
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
              
         
     | 
| 
      
 40 
     | 
    
         
            +
              test 'should be able to find an ablum' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                album = Scrobbler::Album.find('Carrie Underwood', 'Some Hearts')
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_equal('Carrie Underwood', album.artist)
         
     | 
| 
      
 43 
     | 
    
         
            +
                assert_equal('Some Hearts', album.name)
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
              
         
     | 
| 
      
 46 
     | 
    
         
            +
              test "should be able to find an ablum and load the album's info" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                album = Scrobbler::Album.find('Carrie Underwood', 'Some Hearts', :include_info => true)
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal('Carrie Underwood', album.artist)
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal('Some Hearts', album.name)
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_equal('18589', album.reach)
         
     | 
| 
      
 51 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', album.url)
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), album.release_date)
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
              
         
     | 
| 
      
 55 
     | 
    
         
            +
              test "should be able to include the album's info on initialize" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                album = Scrobbler::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
         
     | 
| 
      
 57 
     | 
    
         
            +
                assert_equal('Carrie Underwood', album.artist)
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal('Some Hearts', album.name)
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert_equal('18589', album.reach)
         
     | 
| 
      
 60 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Carrie+Underwood/Some+Hearts', album.url)
         
     | 
| 
      
 61 
     | 
    
         
            +
                assert_equal(Time.mktime(2005, 11, 15, 00, 00, 00), album.release_date)
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
              
         
     | 
| 
      
 64 
     | 
    
         
            +
              test 'should load info when trying to access tracks if info has not been loaded' do
         
     | 
| 
      
 65 
     | 
    
         
            +
                assert_equal(14, @album.tracks.size)
         
     | 
| 
      
 66 
     | 
    
         
            +
                assert_equal('Wasted', @album.tracks.first.name)
         
     | 
| 
      
 67 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Carrie+Underwood/_/Wasted', @album.tracks.first.url)
         
     | 
| 
      
 68 
     | 
    
         
            +
                assert_equal('6738', @album.tracks.first.reach)
         
     | 
| 
      
 69 
     | 
    
         
            +
              end
         
     | 
| 
      
 70 
     | 
    
         
            +
              
         
     | 
| 
      
 71 
     | 
    
         
            +
              test 'should have an image method that accepts a type' do
         
     | 
| 
      
 72 
     | 
    
         
            +
                @album.load_info
         
     | 
| 
      
 73 
     | 
    
         
            +
                assert_equal('http://images.amazon.com/images/P/B000BGR18W.01.MZZZZZZZ.jpg', @album.image(:small))
         
     | 
| 
      
 74 
     | 
    
         
            +
                assert_equal('http://images.amazon.com/images/P/B000BGR18W.01.MZZZZZZZ.jpg', @album.image(:medium))
         
     | 
| 
      
 75 
     | 
    
         
            +
                assert_equal('http://images.amazon.com/images/P/B000BGR18W.01.MZZZZZZZ.jpg', @album.image(:large))
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
              
         
     | 
| 
      
 78 
     | 
    
         
            +
              test "should raise an argument error when attempting to get an image that doesn't exist" do
         
     | 
| 
      
 79 
     | 
    
         
            +
                @album.load_info
         
     | 
| 
      
 80 
     | 
    
         
            +
                assert_raises(ArgumentError) { @album.image(:fake) }
         
     | 
| 
      
 81 
     | 
    
         
            +
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
              
         
     | 
| 
      
 83 
     | 
    
         
            +
              test 'should load info when trying to access an image if the info has not been loaded' do
         
     | 
| 
      
 84 
     | 
    
         
            +
                assert_equal('http://images.amazon.com/images/P/B000BGR18W.01.MZZZZZZZ.jpg', @album.image(:small))
         
     | 
| 
      
 85 
     | 
    
         
            +
              end
         
     | 
| 
      
 86 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,82 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
              
         
     | 
| 
      
 9 
     | 
    
         
            +
              test 'should require name' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                assert_raises(ArgumentError) { Scrobbler::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 have the correct api_path' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal('/1.0/artist/Metallica', @artist.api_path)
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
              test 'should escape api path' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_equal('/1.0/artist/Carrie+Underwood', Scrobbler::Artist.new('Carrie Underwood').api_path)
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
              test 'should have the correct ical path to current events' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                assert_equal('http://ws.audioscrobbler.com/1.0/artist/Metallica/events.ics', @artist.current_events(:ical))
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              test 'should have the correct rss path to current events' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                assert_equal('http://ws.audioscrobbler.com/1.0/artist/Metallica/events.rss', @artist.current_events(:rss))
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
              
         
     | 
| 
      
 33 
     | 
    
         
            +
              test 'should be able to find similar artists' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_equal(['Iron Maiden', 'System of a Down', "Guns N' Roses", 'Rammstein'], @artist.similar.collect(&:name))
         
     | 
| 
      
 35 
     | 
    
         
            +
                first = @artist.similar.first
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal('Iron Maiden', first.name)
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_equal('ca891d65-d9b0-4258-89f7-e6ba29d83767', first.mbid)
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_equal('100', first.match)
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Iron+Maiden', first.url)
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal('http://static3.last.fm/storable/image/177412/small.jpg', first.thumbnail)
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal('http://panther1.last.fm/proposedimages/sidebar/6/1000107/528560.jpg', first.image)
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_equal('yes', first.streamable)
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
              
         
     | 
| 
      
 45 
     | 
    
         
            +
              test 'should be able to find top fans' do
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_equal(%w{Kikoin Chrisis92 delekt0r}, @artist.top_fans.collect(&:username))
         
     | 
| 
      
 47 
     | 
    
         
            +
                first = @artist.top_fans.first
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal('Kikoin', first.username)
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal('http://www.last.fm/user/Kikoin/', first.url)
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_equal('http://panther1.last.fm/avatar/621340085aed19b9ab77a0f8c575758a.gif', first.avatar)
         
     | 
| 
      
 51 
     | 
    
         
            +
                assert_equal('6081000', first.weight)
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
              
         
     | 
| 
      
 54 
     | 
    
         
            +
              test 'should be able to find top tracks' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert_equal(['Nothing Else Matters', 'Enter Sandman', 'Master of Puppets', 'One'], @artist.top_tracks.collect(&:name))
         
     | 
| 
      
 56 
     | 
    
         
            +
                first = @artist.top_tracks.first
         
     | 
| 
      
 57 
     | 
    
         
            +
                assert_equal('Nothing Else Matters', first.name)
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal('', first.mbid)
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Metallica/_/Nothing+Else+Matters', first.url)
         
     | 
| 
      
 60 
     | 
    
         
            +
                assert_equal('59135', first.reach)
         
     | 
| 
      
 61 
     | 
    
         
            +
              end
         
     | 
| 
      
 62 
     | 
    
         
            +
              
         
     | 
| 
      
 63 
     | 
    
         
            +
              test 'should be able to find top albums' do
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert_equal(['Master of Puppets', 'Metallica', 'Reload'], @artist.top_albums.collect(&:name))
         
     | 
| 
      
 65 
     | 
    
         
            +
                first = @artist.top_albums.first
         
     | 
| 
      
 66 
     | 
    
         
            +
                assert_equal('Master of Puppets', first.name)
         
     | 
| 
      
 67 
     | 
    
         
            +
                assert_equal('fed37cfc-2a6d-4569-9ac0-501a7c7598eb', first.mbid)
         
     | 
| 
      
 68 
     | 
    
         
            +
                assert_equal('65717', first.reach)
         
     | 
| 
      
 69 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Metallica/Master+of+Puppets', first.url)
         
     | 
| 
      
 70 
     | 
    
         
            +
                assert_equal('http://cdn.last.fm/coverart/50x50/1411810.jpg', first.image(:small))
         
     | 
| 
      
 71 
     | 
    
         
            +
                assert_equal('http://cdn.last.fm/coverart/130x130/1411810.jpg', first.image(:medium))
         
     | 
| 
      
 72 
     | 
    
         
            +
                assert_equal('http://panther1.last.fm/coverart/130x130/1411810.jpg', first.image(:large))    
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
              
         
     | 
| 
      
 75 
     | 
    
         
            +
              test 'should be able to find top tags' do
         
     | 
| 
      
 76 
     | 
    
         
            +
                assert_equal(['metal', 'thrash metal', 'heavy metal'], @artist.top_tags.collect(&:name))
         
     | 
| 
      
 77 
     | 
    
         
            +
                first = @artist.top_tags.first
         
     | 
| 
      
 78 
     | 
    
         
            +
                assert_equal('metal', first.name)
         
     | 
| 
      
 79 
     | 
    
         
            +
                assert_equal('100', first.count)
         
     | 
| 
      
 80 
     | 
    
         
            +
                assert_equal('http://www.last.fm/tag/metal', first.url)
         
     | 
| 
      
 81 
     | 
    
         
            +
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
            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
         
     | 
| 
         @@ -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 = Scrobbler::SimpleAuth.new(:user => 'chunky', :password => 'bacon')
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
              
         
     | 
| 
      
 9 
     | 
    
         
            +
              test 'should require a user' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                assert_raises(ArgumentError) { Scrobbler::SimpleAuth.new(:password => 'bacon') }
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
              
         
     | 
| 
      
 13 
     | 
    
         
            +
              test 'should require a password' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                assert_raises(ArgumentError) { Scrobbler::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(Scrobbler::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,65 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper.rb'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class TestTag < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 5 
     | 
    
         
            +
                @tag = Scrobbler::Tag.new('rock')
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
              
         
     | 
| 
      
 8 
     | 
    
         
            +
              test 'should be able to find the top tags for the entire system' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                assert_equal(249, Scrobbler::Tag.top_tags.size)
         
     | 
| 
      
 10 
     | 
    
         
            +
                assert_equal('rock', Scrobbler::Tag.top_tags.first.name)
         
     | 
| 
      
 11 
     | 
    
         
            +
                assert_equal('878660', Scrobbler::Tag.top_tags.first.count)
         
     | 
| 
      
 12 
     | 
    
         
            +
                assert_equal('http://www.last.fm/tag/rock', Scrobbler::Tag.top_tags.first.url)
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
              
         
     | 
| 
      
 15 
     | 
    
         
            +
              test 'should require name' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                assert_raise(ArgumentError) { Scrobbler::Tag.new('') }
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
              
         
     | 
| 
      
 19 
     | 
    
         
            +
              test 'should have name' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal('rock', @tag.name)
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
              
         
     | 
| 
      
 23 
     | 
    
         
            +
              test 'should have api path' do
         
     | 
| 
      
 24 
     | 
    
         
            +
                assert_equal('/1.0/tag/rock', @tag.api_path)
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
              
         
     | 
| 
      
 27 
     | 
    
         
            +
              test 'should escape api path' do
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal('/1.0/tag/rock+and+roll', Scrobbler::Tag.new('rock and roll').api_path)
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
              
         
     | 
| 
      
 31 
     | 
    
         
            +
              test 'should be able to find top artists for a tag' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert_equal(6, @tag.top_artists.size)
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal('Red Hot Chili Peppers', @tag.top_artists.first.name)
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_equal('5740', @tag.top_artists.first.count)
         
     | 
| 
      
 35 
     | 
    
         
            +
                assert_equal('yes', @tag.top_artists.first.streamable)
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal('8bfac288-ccc5-448d-9573-c33ea2aa5c30', @tag.top_artists.first.mbid)
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Red+Hot+Chili+Peppers', @tag.top_artists.first.url)
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_equal('http://static3.last.fm/storable/image/184200/small.jpg', @tag.top_artists.first.thumbnail)
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert_equal('http://panther1.last.fm/proposedimages/sidebar/6/1274/552019.jpg', @tag.top_artists.first.image)
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
              
         
     | 
| 
      
 42 
     | 
    
         
            +
              test 'should be able to find top albums for a tag' do
         
     | 
| 
      
 43 
     | 
    
         
            +
                assert_equal(3, @tag.top_albums.size)
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_equal('Californication', @tag.top_albums.first.name)
         
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal('Red Hot Chili Peppers', @tag.top_albums.first.artist)
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_equal('8bfac288-ccc5-448d-9573-c33ea2aa5c30', @tag.top_albums.first.artist_mbid)
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Red+Hot+Chili+Peppers/Californication', @tag.top_albums.first.url)
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal('http://panther1.last.fm/coverart/50x50/4791.jpg', @tag.top_albums.first.image(:small))
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal('http://cdn.last.fm/coverart/130x130/4791.jpg', @tag.top_albums.first.image(:medium))
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_equal('http://cdn.last.fm/coverart/300x300/4791.jpg', @tag.top_albums.first.image(:large))
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
              
         
     | 
| 
      
 53 
     | 
    
         
            +
              test 'should be able to find top tracks for a tag' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                assert_equal(3, @tag.top_tracks.size)
         
     | 
| 
      
 55 
     | 
    
         
            +
                first = @tag.top_tracks.first
         
     | 
| 
      
 56 
     | 
    
         
            +
                assert_equal('Once Upon a Time', first.name)
         
     | 
| 
      
 57 
     | 
    
         
            +
                assert_equal('1076', first.count)
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal('no', first.streamable)
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert_equal('Frank Zappa', first.artist)
         
     | 
| 
      
 60 
     | 
    
         
            +
                assert_equal('e20747e7-55a4-452e-8766-7b985585082d', first.artist_mbid)
         
     | 
| 
      
 61 
     | 
    
         
            +
                assert_equal('http://www.last.fm/music/Frank+Zappa/_/Once+Upon+a+Time', first.url)
         
     | 
| 
      
 62 
     | 
    
         
            +
                assert_equal('http://ec1.images-amazon.com/images/P/B0000009TN.01._SCMZZZZZZZ_.jpg', first.thumbnail)
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert_equal('http://ec1.images-amazon.com/images/P/B0000009TN.01._SCMZZZZZZZ_.jpg', first.image)
         
     | 
| 
      
 64 
     | 
    
         
            +
              end
         
     | 
| 
      
 65 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper.rb'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class TestTrack < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 5 
     | 
    
         
            +
                @track = Scrobbler::Track.new('Carrie Underwood', 'Before He Cheats')
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
              
         
     | 
| 
      
 8 
     | 
    
         
            +
              test 'should require the artist name' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                assert_raises(ArgumentError) { Scrobbler::Track.new('', 'Before He Cheats') }
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
              
         
     | 
| 
      
 12 
     | 
    
         
            +
              test 'should require the track name' do
         
     | 
| 
      
 13 
     | 
    
         
            +
                assert_raises(ArgumentError) { Scrobbler::Track.new('Carrie Underwood', '') }
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
              
         
     | 
| 
      
 16 
     | 
    
         
            +
              test "should know the artist" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_equal('Carrie Underwood', @track.artist)
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
              
         
     | 
| 
      
 20 
     | 
    
         
            +
              test 'should know the name' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert_equal('Before He Cheats', @track.name)
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
              
         
     | 
| 
      
 24 
     | 
    
         
            +
              test 'should have api path' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                assert_equal('/1.0/track/Carrie+Underwood/Before+He+Cheats', @track.api_path)
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
              
         
     | 
| 
      
 28 
     | 
    
         
            +
              test 'should have fans' do
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal(5, @track.fans.size)
         
     | 
| 
      
 30 
     | 
    
         
            +
                assert_equal('frozenice', @track.fans.first.username)
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert_equal('http://www.last.fm/user/frozenice/', @track.fans.first.url)
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert_equal('http://panther1.last.fm/avatar/54e8d2cafc363336e15fef0a48d30706.jpg', @track.fans.first.avatar)
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal('909', @track.fans.first.weight)
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
              
         
     | 
| 
      
 36 
     | 
    
         
            +
              test 'should have top tags' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_equal(6, @track.tags.size)
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_equal('country', @track.tags.first.name)
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert_equal('100', @track.tags.first.count)
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal('http://www.last.fm/tag/country', @track.tags.first.url)
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     |