rockstar 0.3.0

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.
Files changed (77) hide show
  1. data/.gitignore +3 -0
  2. data/History.txt +6 -0
  3. data/MIT-LICENSE +19 -0
  4. data/Manifest +72 -0
  5. data/README.rdoc +140 -0
  6. data/Rakefile +21 -0
  7. data/VERSION +1 -0
  8. data/examples/.gitignore +1 -0
  9. data/examples/album.rb +16 -0
  10. data/examples/artist.rb +17 -0
  11. data/examples/lastfm.yml_example +3 -0
  12. data/examples/scrobble.rb +55 -0
  13. data/examples/tag.rb +20 -0
  14. data/examples/track.rb +14 -0
  15. data/examples/user.rb +18 -0
  16. data/lib/rockstar.rb +39 -0
  17. data/lib/rockstar/album.rb +108 -0
  18. data/lib/rockstar/artist.rb +135 -0
  19. data/lib/rockstar/auth.rb +21 -0
  20. data/lib/rockstar/base.rb +37 -0
  21. data/lib/rockstar/chart.rb +31 -0
  22. data/lib/rockstar/playing.rb +49 -0
  23. data/lib/rockstar/rest.rb +66 -0
  24. data/lib/rockstar/scrobble.rb +67 -0
  25. data/lib/rockstar/session.rb +19 -0
  26. data/lib/rockstar/simpleauth.rb +62 -0
  27. data/lib/rockstar/tag.rb +100 -0
  28. data/lib/rockstar/tokenauth.rb +84 -0
  29. data/lib/rockstar/track.rb +103 -0
  30. data/lib/rockstar/user.rb +194 -0
  31. data/lib/rockstar/version.rb +3 -0
  32. data/rockstar.gemspec +138 -0
  33. data/test/fixtures/xml/album/getinfo_album_Some_Hearts_artist_Carrie_Underwood.xml +63 -0
  34. data/test/fixtures/xml/artist/getsimilar_artist_Metallica.xml +1203 -0
  35. data/test/fixtures/xml/artist/gettopalbums_artist_Metallica.xml +704 -0
  36. data/test/fixtures/xml/artist/gettopfans_artist_Metallica.xml +504 -0
  37. data/test/fixtures/xml/artist/gettoptags_artist_Metallica.xml +403 -0
  38. data/test/fixtures/xml/artist/gettoptracks_artist_Metallica.xml +800 -0
  39. data/test/fixtures/xml/tag/gettopalbums_tag_rock.xml +654 -0
  40. data/test/fixtures/xml/tag/gettopartists_tag_rock.xml +504 -0
  41. data/test/fixtures/xml/tag/gettoptags.xml +1253 -0
  42. data/test/fixtures/xml/tag/gettoptracks_tag_rock.xml +704 -0
  43. data/test/fixtures/xml/track/gettopfans_artist_Carrie_Underwood_track_Before_He_Cheats.xml +504 -0
  44. data/test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Before_He_Cheats.xml +403 -0
  45. data/test/fixtures/xml/track/love_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml +2 -0
  46. data/test/fixtures/xml/user/getfriends_user_jnunemaker.xml +173 -0
  47. data/test/fixtures/xml/user/getinfo_user_jnunemaker.xml +22 -0
  48. data/test/fixtures/xml/user/getinfo_user_oaknd1.xml +22 -0
  49. data/test/fixtures/xml/user/getinfo_user_wharle.xml +22 -0
  50. data/test/fixtures/xml/user/getlovedtracks_user_jnunemaker.xml +775 -0
  51. data/test/fixtures/xml/user/getneighbours_user_jnunemaker.xml +503 -0
  52. data/test/fixtures/xml/user/getrecenttracks_user_jnunemaker.xml +133 -0
  53. data/test/fixtures/xml/user/getrecommendedartists_sk_token_user_jnunemaker.xml +553 -0
  54. data/test/fixtures/xml/user/gettopalbums_user_jnunemaker.xml +704 -0
  55. data/test/fixtures/xml/user/gettopartists_user_jnunemaker.xml +554 -0
  56. data/test/fixtures/xml/user/gettoptags_user_jnunemaker.xml +63 -0
  57. data/test/fixtures/xml/user/gettoptracks_user_jnunemaker.xml +750 -0
  58. data/test/fixtures/xml/user/getweeklyalbumchart_from_1138536002_to_1139140802_user_jnunemaker.xml +143 -0
  59. data/test/fixtures/xml/user/getweeklyalbumchart_from__to__user_jnunemaker.xml +31 -0
  60. data/test/fixtures/xml/user/getweeklyartistchart_from_1138536002_to_1139140802_user_jnunemaker.xml +201 -0
  61. data/test/fixtures/xml/user/getweeklyartistchart_from__to__user_jnunemaker.xml +21 -0
  62. data/test/fixtures/xml/user/getweeklychartlist_user_jnunemaker.xml +232 -0
  63. data/test/fixtures/xml/user/getweeklytrackchart_from_1138536002_to_1139140802_user_jnunemaker.xml +883 -0
  64. data/test/fixtures/xml/user/getweeklytrackchart_from__to__user_jnunemaker.xml +423 -0
  65. data/test/mocks/rest.rb +61 -0
  66. data/test/test_helper.rb +17 -0
  67. data/test/unit/test_album.rb +67 -0
  68. data/test/unit/test_artist.rb +69 -0
  69. data/test/unit/test_chart.rb +35 -0
  70. data/test/unit/test_playing.rb +53 -0
  71. data/test/unit/test_scrobble.rb +69 -0
  72. data/test/unit/test_simpleauth.rb +45 -0
  73. data/test/unit/test_tag.rb +57 -0
  74. data/test/unit/test_tokenauth.rb +45 -0
  75. data/test/unit/test_track.rb +44 -0
  76. data/test/unit/test_user.rb +252 -0
  77. metadata +190 -0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ doc/*
2
+ pkg/*
3
+ .swp
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ * v 0.3.0: update api to use v2.0 of the last.fm api and renamed gem to
2
+ * "Rockstar Gem"
3
+ * v 0.2.3: changed the way things get escaped in hopes that it would fix some problems some were having
4
+ * v 0.2.2: a bunch of changes from titanous, mostly refactoring
5
+ * v 0.2.0: added support for scrobbling tracks and now playing submission (Titanous)
6
+ * v 0.1.0: initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2007-2010 John Nunemaker, Bodo Tasche
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,72 @@
1
+ History.txt
2
+ MIT-LICENSE
3
+ Manifest
4
+ README.rdoc
5
+ Rakefile
6
+ examples/album.rb
7
+ examples/artist.rb
8
+ examples/lastfm.yml_example
9
+ examples/scrobble.rb
10
+ examples/tag.rb
11
+ examples/track.rb
12
+ examples/user.rb
13
+ lib/rockstar.rb
14
+ lib/rockstar/album.rb
15
+ lib/rockstar/artist.rb
16
+ lib/rockstar/auth.rb
17
+ lib/rockstar/base.rb
18
+ lib/rockstar/chart.rb
19
+ lib/rockstar/playing.rb
20
+ lib/rockstar/rest.rb
21
+ lib/rockstar/scrobble.rb
22
+ lib/rockstar/session.rb
23
+ lib/rockstar/simpleauth.rb
24
+ lib/rockstar/tag.rb
25
+ lib/rockstar/tokenauth.rb
26
+ lib/rockstar/track.rb
27
+ lib/rockstar/user.rb
28
+ lib/rockstar/version.rb
29
+ test/fixtures/xml/album/getinfo_album_Some_Hearts_artist_Carrie_Underwood.xml
30
+ test/fixtures/xml/artist/getsimilar_artist_Metallica.xml
31
+ test/fixtures/xml/artist/gettopalbums_artist_Metallica.xml
32
+ test/fixtures/xml/artist/gettopfans_artist_Metallica.xml
33
+ test/fixtures/xml/artist/gettoptags_artist_Metallica.xml
34
+ test/fixtures/xml/artist/gettoptracks_artist_Metallica.xml
35
+ test/fixtures/xml/tag/gettopalbums_tag_rock.xml
36
+ test/fixtures/xml/tag/gettopartists_tag_rock.xml
37
+ test/fixtures/xml/tag/gettoptags.xml
38
+ test/fixtures/xml/tag/gettoptracks_tag_rock.xml
39
+ test/fixtures/xml/track/gettopfans_artist_Carrie_Underwood_track_Before_He_Cheats.xml
40
+ test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Before_He_Cheats.xml
41
+ test/fixtures/xml/track/love_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml
42
+ test/fixtures/xml/user/getfriends_user_jnunemaker.xml
43
+ test/fixtures/xml/user/getinfo_user_jnunemaker.xml
44
+ test/fixtures/xml/user/getinfo_user_oaknd1.xml
45
+ test/fixtures/xml/user/getinfo_user_wharle.xml
46
+ test/fixtures/xml/user/getlovedtracks_user_jnunemaker.xml
47
+ test/fixtures/xml/user/getneighbours_user_jnunemaker.xml
48
+ test/fixtures/xml/user/getrecenttracks_user_jnunemaker.xml
49
+ test/fixtures/xml/user/getrecommendedartists_sk_token_user_jnunemaker.xml
50
+ test/fixtures/xml/user/gettopalbums_user_jnunemaker.xml
51
+ test/fixtures/xml/user/gettopartists_user_jnunemaker.xml
52
+ test/fixtures/xml/user/gettoptags_user_jnunemaker.xml
53
+ test/fixtures/xml/user/gettoptracks_user_jnunemaker.xml
54
+ test/fixtures/xml/user/getweeklyalbumchart_from_1138536002_to_1139140802_user_jnunemaker.xml
55
+ test/fixtures/xml/user/getweeklyalbumchart_from__to__user_jnunemaker.xml
56
+ test/fixtures/xml/user/getweeklyartistchart_from_1138536002_to_1139140802_user_jnunemaker.xml
57
+ test/fixtures/xml/user/getweeklyartistchart_from__to__user_jnunemaker.xml
58
+ test/fixtures/xml/user/getweeklychartlist_user_jnunemaker.xml
59
+ test/fixtures/xml/user/getweeklytrackchart_from_1138536002_to_1139140802_user_jnunemaker.xml
60
+ test/fixtures/xml/user/getweeklytrackchart_from__to__user_jnunemaker.xml
61
+ test/mocks/rest.rb
62
+ test/test_helper.rb
63
+ test/unit/test_album.rb
64
+ test/unit/test_artist.rb
65
+ test/unit/test_chart.rb
66
+ test/unit/test_playing.rb
67
+ test/unit/test_scrobble.rb
68
+ test/unit/test_simpleauth.rb
69
+ test/unit/test_tag.rb
70
+ test/unit/test_tokenauth.rb
71
+ test/unit/test_track.rb
72
+ test/unit/test_user.rb
data/README.rdoc ADDED
@@ -0,0 +1,140 @@
1
+ =Rockstar
2
+
3
+ Rockstar is a wrapper for the last.fm audioscrobbler web services (http://www.last.fm/api/). This gem is based on the scrobbler
4
+ gem by John Nunemaker and updated to use the 2.0 version of the last.fm api
5
+
6
+ Below is just a sampling of how easy this lib is to use.
7
+
8
+ Please initialize your api key and secret before using the api:
9
+
10
+ Rockstar.lastfm = YAML.load_file('lastfm.yml')
11
+
12
+ Here is an example lastfm.yml:
13
+
14
+ api_key: "API"
15
+ api_secret: "SECRET"
16
+
17
+ If you want to use the api in an rails app, you could add an initializer in config/initializers/lastm.rb and load a config/lastfm.yml file.
18
+
19
+ rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
20
+ Rockstar.lastfm = YAML.load_file(rails_root + '/config/lastfm.yml')
21
+
22
+ == Users
23
+
24
+ user = Rockstar::User.new('jnunemaker')
25
+
26
+ puts "#{user.username}'s Recent Tracks"
27
+ puts "=" * (user.username.length + 16)
28
+ user.recent_tracks.each { |t| puts t.name }
29
+
30
+ puts
31
+ puts
32
+
33
+ puts "#{user.username}'s Top Tracks"
34
+ puts "=" * (user.username.length + 13)
35
+ user.top_tracks.each { |t| puts "(#{t.playcount}) #{t.name}" }
36
+
37
+ == Albums
38
+
39
+ album = Rockstar::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
40
+
41
+ puts "Album: #{album.name}"
42
+ puts "Artist: #{album.artist}"
43
+ puts "URL: #{album.url}"
44
+ puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"
45
+
46
+ ==Artists
47
+
48
+ artist = Rockstar::Artist.new('Carrie Underwood')
49
+
50
+ puts 'Top Tracks'
51
+ puts "=" * 10
52
+ artist.top_tracks.each { |t| puts "(#{t.name}" }
53
+
54
+ puts
55
+
56
+ puts 'Similar Artists'
57
+ puts "=" * 15
58
+ artist.similar.each { |a| puts "(#{a.match}%) #{a.name}" }
59
+
60
+ ==Tags
61
+
62
+ tag = Rockstar::Tag.new('country')
63
+
64
+ puts 'Top Albums'
65
+ tag.top_albums.each { |a| puts "(#{a.count}) #{a.name} by #{a.artist}" }
66
+
67
+ puts
68
+
69
+ puts 'Top Tracks'
70
+ tag.top_tracks.each { |t| puts "(#{t.count}) #{t.name} by #{t.artist}" }
71
+
72
+ ==Tracks
73
+
74
+ track = Rockstar::Track.new('Carrie Underwood', 'Before He Cheats')
75
+ puts 'Fans'
76
+ puts "=" * 4
77
+ track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
78
+
79
+ # Love a song, session_key is returned by Rockstar::Auth. See Rockstar::TokenAuth or
80
+ # examples/scrobble.rb for a complete example
81
+ track.love(session_key)
82
+
83
+ == Token Authentication (for scrobbling and recommendations)
84
+
85
+ a = Rockstar::Auth.new
86
+ token = a.token
87
+
88
+ puts
89
+ puts "Please open http://www.last.fm/api/auth/?api_key=#{Rockstar.lastfm_api_key}&token=#{token}"
90
+ puts
91
+ puts "Press enter when done."
92
+
93
+ gets
94
+
95
+ session = a.session(token)
96
+
97
+ auth = Rockstar::TokenAuth.new({:username => session.username, :token => session.key})
98
+ auth.handshake!
99
+
100
+ More details can be found in in Rockstar::TokenAuth
101
+
102
+ == Scrobbling
103
+
104
+ scrobble = Rockstar::Scrobble.new(:session_id => auth.session_id,
105
+ :submission_url => auth.submission_url,
106
+ :artist => 'Coldplay',
107
+ :track => 'Viva La Vida',
108
+ :album => "Viva La Vida",
109
+ :time => Time.new,
110
+ :length => 244,
111
+ :track_number => 7)
112
+ scrobble.submit!
113
+ puts "Rockstar Submission Status: #{scrobble.status}"
114
+
115
+ == Now Playing Submission
116
+
117
+ playing = Rockstar::Playing.new(:session_id => auth.session_id,
118
+ :now_playing_url => auth.now_playing_url,
119
+ :artist => 'Anberlin',
120
+ :track => 'Readyfuels',
121
+ :album => 'Blueprints For the Black Market',
122
+ :length => 218,
123
+ :track_number => 1)
124
+
125
+ playing.submit!
126
+ puts "Playing Submission Status: #{playing.status}"
127
+
128
+ == Note on Patches/Pull Requests
129
+
130
+ * Fork the project.
131
+ * Make your feature addition or bug fix.
132
+ * Add tests for it. This is important so I don't break it in a
133
+ future version unintentionally.
134
+ * Commit, do not mess with rakefile, version, or history.
135
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
136
+ * Send me a pull request. Bonus points for topic branches.
137
+
138
+ == Copyright
139
+
140
+ Copyright (c) 2007-2010 John Nunemaker, Bodo Tasche. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # Rakefile
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'lib/rockstar/version'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "rockstar"
10
+ gem.summary = %Q{wrapper for audioscrobbler (last.fm) web services}
11
+ gem.description = %Q{This gem is an updated version of jnunemakers scrobbler gem.}
12
+ gem.email = "bodo@bitboxer.de"
13
+ gem.homepage = "http://github.com/bitboxer/rockstar"
14
+ gem.authors = ["Bodo Tasche"]
15
+ gem.add_dependency("hpricot", ">=0.4.86")
16
+ gem.add_dependency("activesupport", ">=1.4.2")
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1 @@
1
+ lastfm.yml
data/examples/album.rb ADDED
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rockstar'))
2
+
3
+ # Please enter your API-Keys into lastfm.yml first.
4
+ # You can find them here : http://www.lastfm.de/api/account
5
+ Rockstar.lastfm = YAML.load_file(File.join(File.dirname(__FILE__), 'lastfm.yml'))
6
+
7
+ album = Rockstar::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
8
+
9
+ puts "Album: #{album.name}"
10
+ puts "Artist: #{album.artist}"
11
+ puts "URL: #{album.url}"
12
+ puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"
13
+ puts "Large cover: #{album.image_large}"
14
+ puts
15
+ puts
16
+ puts "Summary: #{album.summary}"
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rockstar'))
2
+
3
+ # Please enter your API-Keys into lastfm.yml first.
4
+ # You can find them here : http://www.lastfm.de/api/account
5
+ Rockstar.lastfm = YAML.load_file(File.join(File.dirname(__FILE__), 'lastfm.yml'))
6
+
7
+ artist = Rockstar::Artist.new('Madonna')
8
+
9
+ puts 'Top Tracks'
10
+ puts "=" * 10
11
+ artist.top_tracks.each { |t| puts "#{t.name}" }
12
+
13
+ puts
14
+
15
+ puts 'Similar Artists'
16
+ puts "=" * 15
17
+ artist.similar.each { |a| puts "(#{a.match}%) #{a.name}" }
@@ -0,0 +1,3 @@
1
+ # Please enter your API-Keys. You can find them here : http://www.lastfm.de/api/account
2
+ api_key: "API"
3
+ api_secret: "KEY"
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rockstar'))
2
+
3
+ # Please enter your API-Keys into lastfm.yml first.
4
+ # You can find them here : http://www.lastfm.de/api/account
5
+ Rockstar.lastfm = YAML.load_file(File.join(File.dirname(__FILE__), 'lastfm.yml'))
6
+
7
+ # This is the desktop app aproach to token auth. See Rockstar::TokenAuth for
8
+ # details on how to get a token for a web app.
9
+
10
+ a = Rockstar::Auth.new
11
+ token = a.token
12
+
13
+ puts
14
+ puts "Please open http://www.last.fm/api/auth/?api_key=#{Rockstar.lastfm_api_key}&token=#{token}"
15
+ puts
16
+ puts "Press enter when done."
17
+
18
+ gets
19
+
20
+ session = a.session(token)
21
+
22
+ auth = Rockstar::TokenAuth.new({:username => session.username, :token => session.key})
23
+ auth.handshake!
24
+
25
+ puts "Auth Status: #{auth.status}"
26
+ puts "Session ID: #{auth.session_id}"
27
+ puts "Now Playing URL: #{auth.now_playing_url}"
28
+ puts "Submission URL: #{auth.submission_url}"
29
+
30
+ scrobble = Rockstar::Scrobble.new(:session_id => auth.session_id,
31
+ :submission_url => auth.submission_url,
32
+ :artist => 'Coldplay',
33
+ :track => 'Viva La Vida',
34
+ :album => 'Viva La Vida',
35
+ :time => Time.new,
36
+ :length => 244,
37
+ :track_number => 7)
38
+ scrobble.submit!
39
+ puts "Rockstar Submission Status: #{scrobble.status}"
40
+
41
+ # Love the Song :
42
+ l_status = Rockstar::Track.new('Coldplay', 'Viva La Vida').love(session.key)
43
+
44
+ puts "Love track status : #{l_status}"
45
+
46
+ playing = Rockstar::Playing.new(:session_id => auth.session_id,
47
+ :now_playing_url => auth.now_playing_url,
48
+ :artist => 'Anberlin',
49
+ :track => 'A Day Late',
50
+ :album => 'Never Take Friendship Personal',
51
+ :length => 214,
52
+ :track_number => 5)
53
+
54
+ playing.submit!
55
+ puts "Playing Submission Status: #{playing.status}"
data/examples/tag.rb ADDED
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rockstar'))
2
+
3
+ # Please enter your API-Keys into lastfm.yml first.
4
+ # You can find them here : http://www.lastfm.de/api/account
5
+ Rockstar.lastfm = YAML.load_file(File.join(File.dirname(__FILE__), 'lastfm.yml'))
6
+
7
+ tag = Rockstar::Tag.new('country')
8
+
9
+ puts 'Top Tags '
10
+ Rockstar::Tag.top_tags.each { |a| puts "(#{a.count}) #{a.name}" }
11
+
12
+ puts
13
+
14
+ puts 'Top Albums'
15
+ tag.top_albums.each { |a| puts "(#{a.count}) #{a.name} by #{a.artist}" }
16
+
17
+ puts
18
+
19
+ puts 'Top Tracks'
20
+ tag.top_tracks.each { |t| puts "(#{t.count}) #{t.name} by #{t.artist}" }
data/examples/track.rb ADDED
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rockstar'))
2
+ require 'pp'
3
+
4
+ # Please enter your API-Keys into lastfm.yml first.
5
+ # You can find them here : http://www.lastfm.de/api/account
6
+ Rockstar.lastfm = YAML.load_file(File.join(File.dirname(__FILE__), 'lastfm.yml'))
7
+
8
+ track = Rockstar::Track.new('Carrie Underwood', 'Before He Cheats')
9
+ puts 'Fans'
10
+ puts "=" * 4
11
+ track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
12
+
13
+ track = Rockstar::Track.new('U2 & Green Day', 'The Saints Are Coming')
14
+ pp track.tags
data/examples/user.rb ADDED
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rockstar'))
2
+
3
+ # Please enter your API-Keys into lastfm.yml first.
4
+ # You can find them here : http://www.lastfm.de/api/account
5
+ Rockstar.lastfm = YAML.load_file(File.join(File.dirname(__FILE__), 'lastfm.yml'))
6
+
7
+ user = Rockstar::User.new('jnunemaker')
8
+
9
+ puts "#{user.username}'s Recent Tracks"
10
+ puts "=" * (user.username.length + 16)
11
+ user.recent_tracks.each { |t| puts t.name }
12
+
13
+ puts
14
+ puts
15
+
16
+ puts "#{user.username}'s Top Tracks"
17
+ puts "=" * (user.username.length + 13)
18
+ user.top_tracks.each { |t| puts "(#{t.playcount}) #{t.name}" }
data/lib/rockstar.rb ADDED
@@ -0,0 +1,39 @@
1
+ %w{cgi rubygems hpricot active_support}.each { |x| require x }
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__))
4
+
5
+ require 'rockstar/base'
6
+ require 'rockstar/version'
7
+
8
+ require 'rockstar/album'
9
+ require 'rockstar/artist'
10
+ require 'rockstar/chart'
11
+ require 'rockstar/user'
12
+ require 'rockstar/tag'
13
+ require 'rockstar/track'
14
+
15
+ require 'rockstar/simpleauth'
16
+ require 'rockstar/auth'
17
+ require 'rockstar/session'
18
+ require 'rockstar/tokenauth'
19
+ require 'rockstar/scrobble'
20
+ require 'rockstar/playing'
21
+
22
+ require 'rockstar/rest'
23
+
24
+ module Rockstar
25
+ extend self
26
+
27
+ def lastfm=(args)
28
+ @api_key = args["api_key"]
29
+ @api_secret = args["api_secret"]
30
+ end
31
+
32
+ def lastfm_api_key
33
+ @api_key
34
+ end
35
+
36
+ def lastfm_api_secret
37
+ @api_secret
38
+ end
39
+ end