scrobbler-ng 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/MIT-LICENSE +19 -0
- data/README.rdoc +104 -0
- data/Rakefile +11 -0
- data/VERSION.yml +4 -0
- data/examples/album.rb +19 -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 +165 -0
- data/lib/scrobbler/artist.rb +169 -0
- data/lib/scrobbler/auth.rb +47 -0
- data/lib/scrobbler/base.rb +124 -0
- data/lib/scrobbler/event.rb +105 -0
- data/lib/scrobbler/geo.rb +27 -0
- data/lib/scrobbler/helper/image.rb +52 -0
- data/lib/scrobbler/helper/streamable.rb +40 -0
- data/lib/scrobbler/library.rb +123 -0
- data/lib/scrobbler/playing.rb +49 -0
- data/lib/scrobbler/playlist.rb +45 -0
- data/lib/scrobbler/radio.rb +12 -0
- data/lib/scrobbler/rest.rb +47 -0
- data/lib/scrobbler/scrobble.rb +116 -0
- data/lib/scrobbler/session.rb +9 -0
- data/lib/scrobbler/shout.rb +21 -0
- data/lib/scrobbler/simpleauth.rb +60 -0
- data/lib/scrobbler/tag.rb +113 -0
- data/lib/scrobbler/track.rb +138 -0
- data/lib/scrobbler/user.rb +222 -0
- data/lib/scrobbler/venue.rb +67 -0
- data/lib/scrobbler.rb +34 -0
- data/tasks/jeweler.rake +18 -0
- data/tasks/rdoc.rake +7 -0
- data/tasks/tests.rake +13 -0
- data/tasks/yardoc.rake +8 -0
- data/test/fixtures/xml/album/info.xml +43 -0
- data/test/fixtures/xml/artist/fans.xml +52 -0
- data/test/fixtures/xml/artist/info.xml +58 -0
- data/test/fixtures/xml/artist/similar.xml +1004 -0
- data/test/fixtures/xml/artist/topalbums.xml +61 -0
- data/test/fixtures/xml/artist/toptags.xml +19 -0
- data/test/fixtures/xml/artist/toptracks.xml +62 -0
- data/test/fixtures/xml/auth/session.xml +7 -0
- data/test/fixtures/xml/auth/token.xml +3 -0
- data/test/fixtures/xml/event/attend.xml +3 -0
- data/test/fixtures/xml/event/attendees.xml +53 -0
- data/test/fixtures/xml/event/event.xml +35 -0
- data/test/fixtures/xml/event/shouts.xml +35 -0
- data/test/fixtures/xml/geo/events-distance-p1.xml +151 -0
- data/test/fixtures/xml/geo/events-lat-long.xml +167 -0
- data/test/fixtures/xml/geo/events-p1.xml +152 -0
- data/test/fixtures/xml/geo/events-p2.xml +380 -0
- data/test/fixtures/xml/geo/events-p3.xml +427 -0
- data/test/fixtures/xml/geo/top_artists-p1.xml +76 -0
- data/test/fixtures/xml/geo/top_tracks-p1.xml +77 -0
- data/test/fixtures/xml/library/albums-f30.xml +454 -0
- data/test/fixtures/xml/library/albums-p1.xml +754 -0
- data/test/fixtures/xml/library/albums-p2.xml +754 -0
- data/test/fixtures/xml/library/albums-p3.xml +754 -0
- data/test/fixtures/xml/library/albums-p4.xml +739 -0
- data/test/fixtures/xml/library/albums-p5.xml +754 -0
- data/test/fixtures/xml/library/albums-p6.xml +754 -0
- data/test/fixtures/xml/library/albums-p7.xml +739 -0
- data/test/fixtures/xml/library/albums-p8.xml +724 -0
- data/test/fixtures/xml/library/artists-f30.xml +334 -0
- data/test/fixtures/xml/library/artists-p1.xml +554 -0
- data/test/fixtures/xml/library/artists-p2.xml +554 -0
- data/test/fixtures/xml/library/artists-p3.xml +554 -0
- data/test/fixtures/xml/library/artists-p4.xml +554 -0
- data/test/fixtures/xml/library/artists-p5.xml +554 -0
- data/test/fixtures/xml/library/artists-p6.xml +554 -0
- data/test/fixtures/xml/library/artists-p7.xml +444 -0
- data/test/fixtures/xml/library/tracks-f30.xml +472 -0
- data/test/fixtures/xml/library/tracks-p1.xml +789 -0
- data/test/fixtures/xml/library/tracks-p10.xml +771 -0
- data/test/fixtures/xml/library/tracks-p11.xml +792 -0
- data/test/fixtures/xml/library/tracks-p12.xml +777 -0
- data/test/fixtures/xml/library/tracks-p13.xml +762 -0
- data/test/fixtures/xml/library/tracks-p14.xml +759 -0
- data/test/fixtures/xml/library/tracks-p15.xml +762 -0
- data/test/fixtures/xml/library/tracks-p16.xml +756 -0
- data/test/fixtures/xml/library/tracks-p17.xml +780 -0
- data/test/fixtures/xml/library/tracks-p18.xml +756 -0
- data/test/fixtures/xml/library/tracks-p19.xml +774 -0
- data/test/fixtures/xml/library/tracks-p2.xml +765 -0
- data/test/fixtures/xml/library/tracks-p20.xml +777 -0
- data/test/fixtures/xml/library/tracks-p21.xml +777 -0
- data/test/fixtures/xml/library/tracks-p22.xml +771 -0
- data/test/fixtures/xml/library/tracks-p23.xml +765 -0
- data/test/fixtures/xml/library/tracks-p24.xml +783 -0
- data/test/fixtures/xml/library/tracks-p25.xml +777 -0
- data/test/fixtures/xml/library/tracks-p26.xml +777 -0
- data/test/fixtures/xml/library/tracks-p27.xml +756 -0
- data/test/fixtures/xml/library/tracks-p28.xml +771 -0
- data/test/fixtures/xml/library/tracks-p29.xml +753 -0
- data/test/fixtures/xml/library/tracks-p3.xml +771 -0
- data/test/fixtures/xml/library/tracks-p30.xml +780 -0
- data/test/fixtures/xml/library/tracks-p31.xml +753 -0
- data/test/fixtures/xml/library/tracks-p32.xml +771 -0
- data/test/fixtures/xml/library/tracks-p33.xml +762 -0
- data/test/fixtures/xml/library/tracks-p34.xml +538 -0
- data/test/fixtures/xml/library/tracks-p4.xml +792 -0
- data/test/fixtures/xml/library/tracks-p5.xml +780 -0
- data/test/fixtures/xml/library/tracks-p6.xml +789 -0
- data/test/fixtures/xml/library/tracks-p7.xml +789 -0
- data/test/fixtures/xml/library/tracks-p8.xml +780 -0
- data/test/fixtures/xml/library/tracks-p9.xml +774 -0
- data/test/fixtures/xml/tag/similar.xml +254 -0
- data/test/fixtures/xml/tag/topalbums.xml +805 -0
- data/test/fixtures/xml/tag/topartists.xml +605 -0
- data/test/fixtures/xml/tag/toptags.xml +1254 -0
- data/test/fixtures/xml/tag/toptracks.xml +852 -0
- data/test/fixtures/xml/track/fans.xml +34 -0
- data/test/fixtures/xml/track/info.xml +53 -0
- data/test/fixtures/xml/track/toptags.xml +504 -0
- data/test/fixtures/xml/user/events.xml +401 -0
- data/test/fixtures/xml/user/friends.xml +30 -0
- data/test/fixtures/xml/user/lovedtracks.xml +678 -0
- data/test/fixtures/xml/user/neighbours.xml +23 -0
- data/test/fixtures/xml/user/playlists.xml +61 -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 +124 -0
- data/test/fixtures/xml/user/systemrecs.xml +18 -0
- data/test/fixtures/xml/user/topalbums.xml +61 -0
- data/test/fixtures/xml/user/topartists.xml +41 -0
- data/test/fixtures/xml/user/toptags.xml +44 -0
- data/test/fixtures/xml/user/toptracks.xml +65 -0
- data/test/fixtures/xml/user/weeklyalbumchart.xml +256 -0
- data/test/fixtures/xml/user/weeklyartistchart.xml +220 -0
- data/test/fixtures/xml/user/weeklytrackchart.xml +746 -0
- data/test/fixtures/xml/venue/events.xml +151 -0
- data/test/fixtures/xml/venue/venue.xml +16 -0
- data/test/mocks/rest.rb +212 -0
- data/test/spec_helper.rb +7 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/album_spec.rb +51 -0
- data/test/unit/artist_spec.rb +130 -0
- data/test/unit/auth_spec.rb +36 -0
- data/test/unit/event_spec.rb +109 -0
- data/test/unit/geo_spec.rb +148 -0
- data/test/unit/library_spec.rb +133 -0
- data/test/unit/playing_test.rb +53 -0
- data/test/unit/playlist_spec.rb +25 -0
- data/test/unit/radio_spec.rb +22 -0
- data/test/unit/scrobble_spec.rb +55 -0
- data/test/unit/scrobble_test.rb +69 -0
- data/test/unit/simpleauth_test.rb +45 -0
- data/test/unit/tag_spec.rb +101 -0
- data/test/unit/track_spec.rb +95 -0
- data/test/unit/user_spec.rb +264 -0
- data/test/unit/venue_spec.rb +104 -0
- metadata +253 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Scrobbler::Auth do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@auth = Scrobbler::Auth.new('user')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should implement all methods from the Last.fm 2.0 API' do
|
10
|
+
@auth.should respond_to(:mobile_session)
|
11
|
+
@auth.should respond_to(:session)
|
12
|
+
@auth.should respond_to(:token)
|
13
|
+
@auth.should respond_to(:websession)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be able to start a mobile session'
|
17
|
+
|
18
|
+
it 'should be able to fetch a session key' do
|
19
|
+
session = @auth.session('test123token')
|
20
|
+
session.should be_kind_of(Scrobbler::Session)
|
21
|
+
session.name.should eql('MyLastFMUsername')
|
22
|
+
session.key.should eql('d580d57f32848f5dcf574d1ce18d78b2')
|
23
|
+
session.subscriber.should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should be able to fetch a request token' do
|
27
|
+
@auth.token.should eql('0e6af5cd2fff6b314994af5b0c58ecc1')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should be able to start a web session'
|
31
|
+
|
32
|
+
it 'should be able to get a url for authenticate this service' do
|
33
|
+
@auth.url.should eql('http://www.last.fm/api/auth/?api_key=foo123&token=0e6af5cd2fff6b314994af5b0c58ecc1')
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Scrobbler::Event do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@auth = Scrobbler::Auth.new('user')
|
7
|
+
@session = @auth.session('test123token')
|
8
|
+
@event = Scrobbler::Event.new(328799)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should know its id' do
|
12
|
+
@event.id.should eql(328799)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'should implement the Last.fm 2.0 API method' do
|
16
|
+
[:attend, :attendees, :load_info, :shouts, :share, :shout].each do |method_name|
|
17
|
+
it "'#{method_name}'" do
|
18
|
+
@event.should respond_to(method_name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should set user\'s status for attendace' do
|
24
|
+
@event.attend(@session,1)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'events attendees' do
|
28
|
+
before do
|
29
|
+
@attendees = ["ikea", "Schrollum", "Alpha1", "japps", "Gomhen", "NTG"]
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should have 6 attendees' do
|
33
|
+
@event.attendees.size.should eql 6
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should know it's attendees names" do
|
37
|
+
@event.attendees.collect(&:name).should eql @attendees
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'first attendee' do
|
41
|
+
before do
|
42
|
+
@attendee = @event.attendees.first
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should know it's realname" do
|
46
|
+
@attendee.realname.should eql 'Jane'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should know it's small image" do
|
50
|
+
@attendee.image(:small).should eql 'http://userserve-ak.last.fm/serve/34/17805805.jpg'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should know it's medium image" do
|
54
|
+
@attendee.image(:medium).should eql 'http://userserve-ak.last.fm/serve/64/17805805.jpg'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should know it's large image" do
|
58
|
+
@attendee.image(:large).should eql 'http://userserve-ak.last.fm/serve/126/17805805.jpg'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should know it's large url" do
|
62
|
+
@attendee.url.should eql 'http://www.last.fm/user/ikea'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should be able to load its info' do
|
68
|
+
@event.load_info
|
69
|
+
@event.title.should eql('Philip Glass')
|
70
|
+
@event.artists.should be_kind_of(Array)
|
71
|
+
@event.artists.first.should be_kind_of(Scrobbler::Artist)
|
72
|
+
@event.artists.first.name.should eql('Philip Glass')
|
73
|
+
@event.headliner.should be_kind_of(Scrobbler::Artist)
|
74
|
+
@event.headliner.name.should eql('Philip Glass')
|
75
|
+
@event.venue.should be_kind_of(Scrobbler::Venue)
|
76
|
+
@event.venue.name.should eql('Barbican Centre')
|
77
|
+
@event.venue.city.should eql('London')
|
78
|
+
@event.venue.country.should eql('United Kingdom')
|
79
|
+
@event.venue.street.should eql('Silk Street')
|
80
|
+
@event.venue.postalcode.should eql('EC2Y 8DS')
|
81
|
+
@event.venue.geo_lat.should eql('51.519972')
|
82
|
+
@event.venue.geo_long.should eql('-0.09334')
|
83
|
+
@event.venue.url.should eql('http://www.last.fm/venue/8777860')
|
84
|
+
@event.start_date.should eql(Time.mktime(2008, 6, 12, 19, 30, 00))
|
85
|
+
@event.description.should eql('Nunc vulputate, ante vitae sollicitudin ullamcorper, velit eros ultricies libero.')
|
86
|
+
@event.image(:small).should eql('http://userserve-ak.last.fm/serve/34/320636.jpg')
|
87
|
+
@event.image(:medium).should eql('http://userserve-ak.last.fm/serve/64/320636.jpg')
|
88
|
+
@event.image(:large).should eql('http://userserve-ak.last.fm/serve/126/320636.jpg')
|
89
|
+
@event.url.should eql('http://www.last.fm/event/328799')
|
90
|
+
@event.attendance.should eql(46)
|
91
|
+
@event.reviews.should eql(0)
|
92
|
+
@event.tag.should eql('lastfm:event=328799')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should be able to get its shouts' do
|
96
|
+
@event.shouts.should be_kind_of(Array)
|
97
|
+
@event.shouts.should have(6).items
|
98
|
+
@event.shouts.first.should be_kind_of(Scrobbler::Shout)
|
99
|
+
@event.shouts.first.body.should eql('test')
|
100
|
+
@event.shouts.first.author.should be_kind_of(Scrobbler::User)
|
101
|
+
@event.shouts.first.author.username.should eql('kaypey')
|
102
|
+
@event.shouts.first.date.should eql(Time.mktime(2009, 4, 28, 5, 35, 11))
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should be able to be shared'
|
106
|
+
|
107
|
+
it 'should be able to leave a shout'
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Scrobbler::Geo do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@geo = Scrobbler::Geo.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'should implement the method' do
|
10
|
+
[:events,:top_tracks,:top_artists].each do |method_name|
|
11
|
+
it "'#{method_name}'" do
|
12
|
+
@geo.should respond_to(method_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'finding by location' do
|
18
|
+
before do
|
19
|
+
@event_titles = ['Will and The People','Son Of Dave','Surface Unsigned','Experimental Dental School']
|
20
|
+
@event_ids = [1025661,954053,1005964,909456]
|
21
|
+
@first_atrists_names = ['Will And The People','Carnations','Midwich Cuckoos','NO FLASH']
|
22
|
+
@first_headliner = 'Will And The People'
|
23
|
+
@top_artist_names = ['The Killers','Coldplay','Radiohead','Muse','Franz Ferdinand','U2']
|
24
|
+
@top_track_names = ['Use Somebody','Schwarz zu Blau','Sex on Fire','Alles Neu','Poker Face','Ayo Technology']
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'events in manchester' do
|
28
|
+
before do
|
29
|
+
@events = @geo.events(:location => 'Manchester')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should find 4 events' do
|
33
|
+
@events.size.should eql 4
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have the correct event id's" do
|
37
|
+
@events.collect(&:id).should eql @event_ids
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have the correct event titles' do
|
41
|
+
@events.collect(&:title).should eql @event_titles
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'finding top artists in spain' do
|
46
|
+
before do
|
47
|
+
@top_artists = @geo.top_artists(:location => 'Spain')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should find 6 artists' do
|
51
|
+
@top_artists.size.should eql 6
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should have the correct artist names' do
|
55
|
+
@top_artists.collect(&:name).should eql @top_artist_names
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'finding top tracks in germany' do
|
60
|
+
before do
|
61
|
+
@top_tracks = @geo.top_tracks(:location => 'Germany')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should find 6 top tracks' do
|
65
|
+
@top_tracks.size.should eql 6
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should have the correct top track names' do
|
69
|
+
@top_track_names.should eql @top_tracks.collect(&:name)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
describe 'finding by latitude and longitude' do
|
76
|
+
describe 'events in 40.71417 -74.00639' do
|
77
|
+
before do
|
78
|
+
@events = @geo.events(:lat => 40.71417, :long => -74.00639)
|
79
|
+
@event_ids = [1066470, 990602, 1062713, 1088394]
|
80
|
+
@event_titles = ["We Love Brasil", "Red Bank Jazz and Blues Festival", "Jazz For Young People", "The Paul Green School Of Rock"]
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should find 4 events' do
|
84
|
+
@events.size.should eql 4
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should have the correct event id's" do
|
88
|
+
@events.collect(&:id).should eql @event_ids
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should have the correct event titles' do
|
92
|
+
@events.collect(&:title).should eql @event_titles
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'finding by distance' do
|
98
|
+
describe 'events within 15km' do
|
99
|
+
before do
|
100
|
+
@events = @geo.events(:distance => 15)
|
101
|
+
@event_ids = [926134, 1046018, 1070375, 805363]
|
102
|
+
@event_titles = ["Feast - Picnic by the Lake", "Bootleg Beatles", "The Lucid Dream", "Oasis"]
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should find 4 events' do
|
106
|
+
@events.size.should eql 4
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should have the correct event id's" do
|
110
|
+
@events.collect(&:id).should eql @event_ids
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should have the correct event titles' do
|
114
|
+
@events.collect(&:title).should eql @event_titles
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'pagination' do
|
120
|
+
describe 'page two of events in manchester' do
|
121
|
+
before do
|
122
|
+
@page = @geo.events(:location => 'Manchester', :page => 2)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should have 10 events' do
|
126
|
+
@page.size.should eql(10)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should have the correct title for the first event' do
|
130
|
+
@page.first.title.should eql('New Bruises')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'page three of events in manchester' do
|
135
|
+
before do
|
136
|
+
@page = @geo.events(:location => 'Manchester', :page => 3)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should have 10 events' do
|
140
|
+
@page.size.should eql(10)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should have the correct title for the first event' do
|
144
|
+
@page.first.title.should eql('Saving Aimee')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Scrobbler::Library do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@library = Scrobbler::Library.new('xhochy')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should know its username' do
|
10
|
+
@library.user.should be_kind_of(Scrobbler::User)
|
11
|
+
@library.user.name.should eql('xhochy')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should implement all methods from the Last.fm 2.0 API' do
|
15
|
+
@library.should respond_to(:add_album)
|
16
|
+
@library.should respond_to(:add_artist)
|
17
|
+
@library.should respond_to(:add_track)
|
18
|
+
@library.should respond_to(:albums)
|
19
|
+
@library.should respond_to(:artists)
|
20
|
+
@library.should respond_to(:tracks)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be able to add an album'
|
24
|
+
|
25
|
+
it 'should be able to add an artist'
|
26
|
+
|
27
|
+
it 'should be able to add a track'
|
28
|
+
|
29
|
+
it 'should be able to get its albums' do
|
30
|
+
@library.should have(396).albums
|
31
|
+
first = @library.albums.first
|
32
|
+
first.should be_kind_of Scrobbler::Album
|
33
|
+
first.name.should eql 'Silent Alarm'
|
34
|
+
first.playcount.should eql 1043
|
35
|
+
first.tagcount.should eql 0
|
36
|
+
first.mbid.should eql '7e18e965-cbc7-43d6-9042-daba4f984a34'
|
37
|
+
first.url.should eql 'http://www.last.fm/music/Bloc+Party/Silent+Alarm'
|
38
|
+
first.artist.should be_kind_of Scrobbler::Artist
|
39
|
+
first.artist.name.should eql 'Bloc Party'
|
40
|
+
first.artist.mbid.should eql '8c538f11-c141-4588-8ecb-931083524186'
|
41
|
+
first.artist.url.should eql 'http://www.last.fm/music/Bloc+Party'
|
42
|
+
first.image(:small).should eql 'http://userserve-ak.last.fm/serve/34s/9903887.jpg'
|
43
|
+
first.image(:medium).should eql 'http://userserve-ak.last.fm/serve/64s/9903887.jpg'
|
44
|
+
first.image(:large).should eql 'http://userserve-ak.last.fm/serve/126/9903887.jpg'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should be able to get its 30 most heard albums' do
|
48
|
+
@library.albums(:all => false, :limit => 30).should have(30).items
|
49
|
+
first = @library.albums(:all => false, :limit => 30).first
|
50
|
+
first.should be_kind_of Scrobbler::Album
|
51
|
+
first.name.should eql 'Silent Alarm'
|
52
|
+
first.playcount.should eql 1043
|
53
|
+
first.tagcount.should eql 0
|
54
|
+
first.mbid.should eql '7e18e965-cbc7-43d6-9042-daba4f984a34'
|
55
|
+
first.url.should eql 'http://www.last.fm/music/Bloc+Party/Silent+Alarm'
|
56
|
+
first.artist.should be_kind_of Scrobbler::Artist
|
57
|
+
first.artist.name.should eql 'Bloc Party'
|
58
|
+
first.artist.mbid.should eql '8c538f11-c141-4588-8ecb-931083524186'
|
59
|
+
first.artist.url.should eql 'http://www.last.fm/music/Bloc+Party'
|
60
|
+
first.image(:small).should eql 'http://userserve-ak.last.fm/serve/34s/9903887.jpg'
|
61
|
+
first.image(:medium).should eql 'http://userserve-ak.last.fm/serve/64s/9903887.jpg'
|
62
|
+
first.image(:large).should eql 'http://userserve-ak.last.fm/serve/126/9903887.jpg'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should be able to get its artists' do
|
66
|
+
@library.should have(340).artists
|
67
|
+
first = @library.artists.first
|
68
|
+
first.should be_kind_of Scrobbler::Artist
|
69
|
+
first.name.should eql 'Bloc Party'
|
70
|
+
first.playcount.should eql 2314
|
71
|
+
first.tagcount.should eql 0
|
72
|
+
first.mbid.should eql '8c538f11-c141-4588-8ecb-931083524186'
|
73
|
+
first.url.should eql 'http://www.last.fm/music/Bloc+Party'
|
74
|
+
first.streamable.should be_true
|
75
|
+
first.image(:small).should eql 'http://userserve-ak.last.fm/serve/34/115908.jpg'
|
76
|
+
first.image(:medium).should eql 'http://userserve-ak.last.fm/serve/64/115908.jpg'
|
77
|
+
first.image(:large).should eql 'http://userserve-ak.last.fm/serve/126/115908.jpg'
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should be able to get its 30 most heard artists' do
|
81
|
+
@library.artists(:all => false, :limit => 30).should have(30).items
|
82
|
+
first = @library.artists(:all => false, :limit => 30).first
|
83
|
+
first.should be_kind_of Scrobbler::Artist
|
84
|
+
first.name.should eql 'Bloc Party'
|
85
|
+
first.playcount.should eql 2314
|
86
|
+
first.tagcount.should eql 0
|
87
|
+
first.mbid.should eql '8c538f11-c141-4588-8ecb-931083524186'
|
88
|
+
first.url.should eql 'http://www.last.fm/music/Bloc+Party'
|
89
|
+
first.streamable.should be_true
|
90
|
+
first.image(:small).should eql 'http://userserve-ak.last.fm/serve/34/115908.jpg'
|
91
|
+
first.image(:medium).should eql 'http://userserve-ak.last.fm/serve/64/115908.jpg'
|
92
|
+
first.image(:large).should eql 'http://userserve-ak.last.fm/serve/126/115908.jpg'
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should be able to get its tracks' do
|
96
|
+
@library.should have(1686).tracks
|
97
|
+
first = @library.tracks.first
|
98
|
+
first.should be_kind_of Scrobbler::Track
|
99
|
+
first.name.should eql 'A-Punk'
|
100
|
+
first.playcount.should eql 185
|
101
|
+
first.tagcount.should eql 0
|
102
|
+
first.mbid.should eql ''
|
103
|
+
first.url.should eql 'http://www.last.fm/music/Vampire+Weekend/_/A-Punk'
|
104
|
+
first.streamable.should be_false
|
105
|
+
first.artist.should be_kind_of Scrobbler::Artist
|
106
|
+
first.artist.name.should eql 'Vampire Weekend'
|
107
|
+
first.artist.mbid.should eql 'af37c51c-0790-4a29-b995-456f98a6b8c9'
|
108
|
+
first.artist.url.should eql 'http://www.last.fm/music/Vampire+Weekend'
|
109
|
+
first.image(:small).should eql 'http://userserve-ak.last.fm/serve/34s/10258165.jpg'
|
110
|
+
first.image(:medium).should eql 'http://userserve-ak.last.fm/serve/64s/10258165.jpg'
|
111
|
+
first.image(:large).should eql 'http://userserve-ak.last.fm/serve/126/10258165.jpg'
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should be able to get its 30 most heard tracks' do
|
115
|
+
@library.tracks(:all => false, :limit => 30).should have(30).items
|
116
|
+
first = @library.tracks(:all => false, :limit => 30).first
|
117
|
+
first.should be_kind_of Scrobbler::Track
|
118
|
+
first.name.should eql 'A-Punk'
|
119
|
+
first.playcount.should eql 185
|
120
|
+
first.tagcount.should eql 0
|
121
|
+
first.mbid.should eql ''
|
122
|
+
first.url.should eql 'http://www.last.fm/music/Vampire+Weekend/_/A-Punk'
|
123
|
+
first.streamable.should be_false
|
124
|
+
first.artist.should be_kind_of Scrobbler::Artist
|
125
|
+
first.artist.name.should eql 'Vampire Weekend'
|
126
|
+
first.artist.mbid.should eql 'af37c51c-0790-4a29-b995-456f98a6b8c9'
|
127
|
+
first.artist.url.should eql 'http://www.last.fm/music/Vampire+Weekend'
|
128
|
+
first.image(:small).should eql 'http://userserve-ak.last.fm/serve/34s/10258165.jpg'
|
129
|
+
first.image(:medium).should eql 'http://userserve-ak.last.fm/serve/64s/10258165.jpg'
|
130
|
+
first.image(:large).should eql 'http://userserve-ak.last.fm/serve/126/10258165.jpg'
|
131
|
+
end
|
132
|
+
|
133
|
+
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,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Scrobbler::Playlist do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@playlist = Scrobbler::Playlist.new('lastfm://playlist/album/2026126')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should know its url' do
|
10
|
+
@playlist.url.should eql('lastfm://playlist/album/2026126')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should implement all methods from the Last.fm 2.0 API' do
|
14
|
+
@playlist.should respond_to(:fetch)
|
15
|
+
@playlist.should respond_to(:add_track)
|
16
|
+
Scrobbler::Playlist.should respond_to(:create)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should be able to add a track'
|
20
|
+
|
21
|
+
it 'should be able to create a new'
|
22
|
+
|
23
|
+
it 'should be able to fetch more information'
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Scrobbler::Radio do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@radio = Scrobbler::Radio.new('lastfm://globaltags/disco')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should know its station' do
|
10
|
+
@radio.station.should eql('lastfm://globaltags/disco')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should implement all methods from the Last.fm 2.0 API' do
|
14
|
+
@radio.should respond_to(:tune)
|
15
|
+
@radio.should respond_to(:playlist)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should be able to tune in'
|
19
|
+
|
20
|
+
it 'should be able to fetch the playlist'
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
describe Scrobbler::Scrobble do
|
2
|
+
before do
|
3
|
+
Scrobbler::Scrobble.client_id = 'spec'
|
4
|
+
@user = Scrobbler::User.new('TestUser')
|
5
|
+
@session = Scrobbler::Session.new(:key => 'testKey', :name => 'testName', :subscriber => true)
|
6
|
+
@scrobble = Scrobbler::Scrobble.new(:handshake_on_init => false, :user => @user, :session => @session)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'should implement the method' do
|
10
|
+
[:submit, :now_playing, :handshake].each do |method_name|
|
11
|
+
it "'#{method_name}'" do
|
12
|
+
@scrobble.should respond_to(method_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'doing initialization should require' do
|
18
|
+
it 'a session' do
|
19
|
+
lambda {
|
20
|
+
Scrobbler::Scrobble.new(:session => nil, :user => @user)
|
21
|
+
}.should raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'a user' do
|
25
|
+
lambda {
|
26
|
+
Scrobbler::Scrobble.new(:session => @session, :user => nil)
|
27
|
+
}.should raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'handshaking should provide' do
|
32
|
+
it 'a session id'
|
33
|
+
it 'a now-playing url'
|
34
|
+
it 'a submisson url'
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'handshaking could fail with' do
|
38
|
+
it BadAuthError
|
39
|
+
it BadTimeError
|
40
|
+
it RequestFailedError
|
41
|
+
it ClientBannedError
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'now_playing should work with' do
|
45
|
+
it 'just track and artist'
|
46
|
+
it 'additionally the duration'
|
47
|
+
it 'additionally the album name'
|
48
|
+
it 'additionally the track\'s MusicBrainz id'
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'now_playing could fail with' do
|
52
|
+
it BadSessionError
|
53
|
+
end
|
54
|
+
|
55
|
+
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
|