jonaustin-rockstar 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +8 -0
  3. data/Gemfile +10 -0
  4. data/Gemfile.lock +62 -0
  5. data/History.txt +6 -0
  6. data/MIT-LICENSE +19 -0
  7. data/Manifest +72 -0
  8. data/README.md +173 -0
  9. data/Rakefile +32 -0
  10. data/VERSION +1 -0
  11. data/examples/.gitignore +1 -0
  12. data/examples/album.rb +16 -0
  13. data/examples/artist.rb +25 -0
  14. data/examples/geo.rb +60 -0
  15. data/examples/lastfm.yml_example +3 -0
  16. data/examples/scrobble.rb +45 -0
  17. data/examples/tag.rb +20 -0
  18. data/examples/track.rb +14 -0
  19. data/examples/user.rb +18 -0
  20. data/lib/rockstar.rb +46 -0
  21. data/lib/rockstar/album.rb +104 -0
  22. data/lib/rockstar/artist.rb +183 -0
  23. data/lib/rockstar/auth.rb +38 -0
  24. data/lib/rockstar/base.rb +48 -0
  25. data/lib/rockstar/chart.rb +31 -0
  26. data/lib/rockstar/event.rb +73 -0
  27. data/lib/rockstar/geo.rb +47 -0
  28. data/lib/rockstar/library.rb +13 -0
  29. data/lib/rockstar/metro.rb +26 -0
  30. data/lib/rockstar/rest.rb +66 -0
  31. data/lib/rockstar/session.rb +19 -0
  32. data/lib/rockstar/tag.rb +100 -0
  33. data/lib/rockstar/track.rb +265 -0
  34. data/lib/rockstar/user.rb +205 -0
  35. data/lib/rockstar/venue.rb +59 -0
  36. data/lib/rockstar/version.rb +3 -0
  37. data/rockstar.gemspec +176 -0
  38. data/test/fixtures/xml/album/getinfo_album_Radio_Retalation_artist_Thievery_Corporation.xml +21 -0
  39. data/test/fixtures/xml/album/getinfo_album_Some_Hearts_artist_Carrie_Underwood.xml +63 -0
  40. data/test/fixtures/xml/artist/getevents_artist_Metallica.xml +1064 -0
  41. data/test/fixtures/xml/artist/getimages_artist_Metallica_page_2.xml +1074 -0
  42. data/test/fixtures/xml/artist/getinfo_artist_Metallica.xml +115 -0
  43. data/test/fixtures/xml/artist/getinfo_mbid_65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab.xml +115 -0
  44. data/test/fixtures/xml/artist/getsimilar_artist_Metallica.xml +1203 -0
  45. data/test/fixtures/xml/artist/gettopalbums_artist_Metallica.xml +704 -0
  46. data/test/fixtures/xml/artist/gettopfans_artist_Metallica.xml +504 -0
  47. data/test/fixtures/xml/artist/gettoptags_artist_Metallica.xml +403 -0
  48. data/test/fixtures/xml/artist/gettoptracks_artist_Metallica.xml +800 -0
  49. data/test/fixtures/xml/geo/getevents_location_london.xml +531 -0
  50. data/test/fixtures/xml/geo/getmetros_country_germany.xml +44 -0
  51. data/test/fixtures/xml/geo/gettopartists_country_spain_limit_50_page_.xml +561 -0
  52. data/test/fixtures/xml/geo/gettoptracks_country_spain_limit_50_page_.xml +1004 -0
  53. data/test/fixtures/xml/library/getalbums_user_jnunemaker.xml +704 -0
  54. data/test/fixtures/xml/library/getartists_user_jnunemaker.xml +554 -0
  55. data/test/fixtures/xml/tag/gettopalbums_tag_rock.xml +654 -0
  56. data/test/fixtures/xml/tag/gettopartists_tag_rock.xml +504 -0
  57. data/test/fixtures/xml/tag/gettoptags.xml +1253 -0
  58. data/test/fixtures/xml/tag/gettoptracks_tag_rock.xml +704 -0
  59. data/test/fixtures/xml/track/getinfo_artist_Carrie_Underwood_track_Before_He_Cheats.xml +55 -0
  60. data/test/fixtures/xml/track/getinfo_artist_Karrie_Underwood_track_Before_He_Cheats.xml +55 -0
  61. data/test/fixtures/xml/track/getsimilar_artist_Carrie_Underwood_limit_10_track_Before_He_Cheats.xml +185 -0
  62. data/test/fixtures/xml/track/gettopfans_artist_Carrie_Underwood_track_Before_He_Cheats.xml +504 -0
  63. data/test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Before_He_Cheats.xml +403 -0
  64. data/test/fixtures/xml/track/gettoptags_artist_Carrie_Underwood_track_Wasted.xml +405 -0
  65. data/test/fixtures/xml/track/love_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml +2 -0
  66. data/test/fixtures/xml/track/updatenowplaying_artist_Carrie_Underwood_sk_tag_track_Before_He_Cheats.xml +10 -0
  67. data/test/fixtures/xml/user/getevents_sk_token_user_bodot.xml +513 -0
  68. data/test/fixtures/xml/user/getfriends_user_jnunemaker.xml +173 -0
  69. data/test/fixtures/xml/user/getinfo_user_jnunemaker.xml +22 -0
  70. data/test/fixtures/xml/user/getinfo_user_oaknd1.xml +22 -0
  71. data/test/fixtures/xml/user/getinfo_user_wharle.xml +22 -0
  72. data/test/fixtures/xml/user/getlovedtracks_user_jnunemaker.xml +775 -0
  73. data/test/fixtures/xml/user/getneighbours_user_jnunemaker.xml +503 -0
  74. data/test/fixtures/xml/user/getrecenttracks_user_jnunemaker.xml +133 -0
  75. data/test/fixtures/xml/user/getrecommendedartists_sk_token_user_jnunemaker.xml +553 -0
  76. data/test/fixtures/xml/user/gettopalbums_user_jnunemaker.xml +704 -0
  77. data/test/fixtures/xml/user/gettopartists_period_3month_user_jnunemaker.xml +710 -0
  78. data/test/fixtures/xml/user/gettopartists_period_overall_user_jnunemaker.xml +554 -0
  79. data/test/fixtures/xml/user/gettoptags_user_jnunemaker.xml +63 -0
  80. data/test/fixtures/xml/user/gettoptracks_user_jnunemaker.xml +750 -0
  81. data/test/fixtures/xml/user/getweeklyalbumchart_from_1138536002_to_1139140802_user_jnunemaker.xml +143 -0
  82. data/test/fixtures/xml/user/getweeklyalbumchart_from__to__user_jnunemaker.xml +31 -0
  83. data/test/fixtures/xml/user/getweeklyartistchart_from_1138536002_to_1139140802_user_jnunemaker.xml +201 -0
  84. data/test/fixtures/xml/user/getweeklyartistchart_from__to__user_jnunemaker.xml +21 -0
  85. data/test/fixtures/xml/user/getweeklychartlist_user_jnunemaker.xml +232 -0
  86. data/test/fixtures/xml/user/getweeklytrackchart_from_1138536002_to_1139140802_user_jnunemaker.xml +883 -0
  87. data/test/fixtures/xml/user/getweeklytrackchart_from__to__user_jnunemaker.xml +423 -0
  88. data/test/fixtures/xml/venue/getevents_venue_8807850.xml +280 -0
  89. data/test/fixtures/xml/venue/search_country__limit__page__venue_country_DE_venue_cotton.xml +72 -0
  90. data/test/mocks/rest.rb +50 -0
  91. data/test/test_helper.rb +18 -0
  92. data/test/unit/test_album.rb +76 -0
  93. data/test/unit/test_artist.rb +123 -0
  94. data/test/unit/test_chart.rb +35 -0
  95. data/test/unit/test_geo.rb +51 -0
  96. data/test/unit/test_library.rb +65 -0
  97. data/test/unit/test_rockstar.rb +15 -0
  98. data/test/unit/test_tag.rb +57 -0
  99. data/test/unit/test_track.rb +93 -0
  100. data/test/unit/test_user.rb +309 -0
  101. data/test/unit/test_venue.rb +20 -0
  102. metadata +243 -0
@@ -0,0 +1,265 @@
1
+ # Below is an example of how to get the top fans for a track.
2
+ #
3
+ # track = Rockstar::Track.new('Carrie Underwood', 'Before He Cheats')
4
+ # puts 'Fans'
5
+ # puts "=" * 4
6
+ # track.fans.each { |u| puts u.username }
7
+ #
8
+ # Which would output something like:
9
+ #
10
+ # track = Rockstar::Track.new('Carrie Underwood', 'Before He Cheats')
11
+ # puts 'Fans'
12
+ # puts "=" * 4
13
+ # track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
14
+ #
15
+ # Fans
16
+ # ====
17
+ # (69163) PimpinRose
18
+ # (7225) selene204
19
+ # (7000) CelestiaLegends
20
+ # (6817) muehllr
21
+ # (5387) Mudley
22
+ # (5368) ilovejohnny1984
23
+ # (5232) MeganIAD
24
+ # (5132) Veric
25
+ # (5097) aeVnar
26
+ # (3390) kristaaan
27
+ # (3239) kelseaowns
28
+ # (2780) syndication
29
+ # (2735) mkumm
30
+ # (2706) Kimmybeebee
31
+ # (2648) skorpcroze
32
+ # (2549) mistergreg
33
+ # (2449) mlmjcace
34
+ # (2302) tiNEey
35
+ # (2169) ajsbabiegirl
36
+
37
+ class BadSessionError < StandardError; end
38
+ class UnavailableError < StandardError; end
39
+ class RequestFailedError < StandardError; end
40
+
41
+
42
+ module Rockstar
43
+ class Track < Base
44
+ attr_accessor :artist, :artist_mbid, :name, :mbid, :playcount, :rank, :url, :now_playing
45
+ attr_accessor :summary, :content, :streamable, :album, :album_mbid, :date, :date_uts, :duration
46
+ alias_method :now_playing?, :now_playing
47
+
48
+ # only seems to be used on top tracks for tag
49
+ attr_accessor :count, :thumbnail, :image, :images
50
+
51
+ # for weekly top tracks
52
+ attr_accessor :chartposition
53
+
54
+ class << self
55
+ def new_from_xml(xml, doc=nil)
56
+ artist = (xml).at(:artist)['name'] if (xml).at(:artist) && !(xml).at(:artist)['name'].nil?
57
+ artist = (xml).at(:artist).at(:name).inner_html if artist.nil? && (xml).at(:artist) && (xml).at(:artist).at(:name)
58
+ artist = (xml).at(:artist).inner_html if artist.nil? && (xml).at(:artist)
59
+ artist = doc.root['artist'] if artist.nil? && doc.root['artist']
60
+ name = (xml).at(:name).inner_html if (xml).at(:name)
61
+ name = xml['name'] if name.nil? && xml['name']
62
+
63
+ track = Track.new(artist, name)
64
+ track.load_info(xml)
65
+ track
66
+ end
67
+
68
+ def love(artist, track, session_key)
69
+ doc = Hpricot::XML(Track.connection.post("track.love", true, {:track => track, :artist => artist, :sk => session_key}))
70
+ doc.at("lfm")["status"]
71
+ end
72
+
73
+ # Scrobble a song
74
+ #
75
+ # Possible parameters:
76
+ # session_key (required) : the session key you got during authentification
77
+ # track (required) : name of the track
78
+ # artist (required) : name of the artist of the track
79
+ # time (required) : a time object set to the time the track started playing
80
+ # album : Name of the album
81
+ # albumArtist : Name of the album artist if artist differs
82
+ # trackNumber : Number of the track
83
+ # mbid : MusicBrainz ID of the track
84
+ # duration : track length
85
+ def scrobble(params = {})
86
+ if params[:session_key].blank? || params[:track].blank? || params[:time].nil? || params[:artist].blank?
87
+ raise ArgumentError, "Missing required argument"
88
+ end
89
+
90
+ query = {
91
+ :sk => params[:session_key],
92
+ "track[0]" => params[:track],
93
+ "timestamp[0]"=> params[:time].utc.to_i,
94
+ "artist[0]" => params[:artist]
95
+ }
96
+
97
+ query["album[0]"] = params[:album] if !params[:album].blank?
98
+ query["albumArtist[0]"] = params[:albumArtist] if !params[:albumArtist].blank?
99
+ query["trackNumber[0]"] = params[:trackNumber] if !params[:trackNumber].blank?
100
+ query["mbid[0]"] = params[:mbid] if !params[:mbid].blank?
101
+ query["duration[0]"] = params[:duration] if !params[:duration].blank?
102
+
103
+ doc = Hpricot::XML(Track.connection.post("track.scrobble", true, query))
104
+
105
+ if doc.at("lfm")["status"] == "failed"
106
+ case doc.at("lfm").at("error")["code"].to_i
107
+ when 9
108
+ raise BadSessionError, doc.at("lfm").at("error").inner_html
109
+ when 11, 16
110
+ raise UnavailableError, doc.at("lfm").at("error").inner_html
111
+ else
112
+ raise RequestFailedError, doc.at("lfm").at("error").inner_html
113
+ end
114
+ end
115
+
116
+ doc.at("lfm")["status"]
117
+ end
118
+
119
+ # Update the current playing song
120
+ #
121
+ # Possible parameters:
122
+ # session_key (required) : the session key you got during authentification
123
+ # track (required) : name of the track
124
+ # artist (required) : name of the artist of the track
125
+ # album : Name of the album
126
+ # albumArtist : Name of the album artist if artist differs
127
+ # trackNumber : Number of the track
128
+ # mbid : MusicBrainz ID of the track
129
+ # duration : track length
130
+ def updateNowPlaying(params = {})
131
+ if params[:session_key].blank? || params[:track].blank? || params[:artist].blank?
132
+ raise ArgumentError, "Missing required argument"
133
+ end
134
+
135
+ query = {
136
+ :sk => params[:session_key],
137
+ "track" => params[:track],
138
+ "artist" => params[:artist]
139
+ }
140
+
141
+ query["album"] = params[:album] if !params[:album].blank?
142
+ query["albumArtist"] = params[:albumArtist] if !params[:albumArtist].blank?
143
+ query["trackNumber"] = params[:trackNumber] if !params[:trackNumber].blank?
144
+ query["mbid"] = params[:mbid] if !params[:mbid].blank?
145
+ query["duration"] = params[:duration] if !params[:duration].blank?
146
+
147
+ doc = Hpricot::XML(Track.connection.post("track.updateNowPlaying", true, query))
148
+
149
+ if doc.at("lfm")["status"] == "failed"
150
+ case doc.at("lfm").at("error")["code"].to_i
151
+ when 9
152
+ raise BadSessionError, doc.at("lfm").at("error").inner_html
153
+ when 11, 16
154
+ raise UnavailableError, doc.at("lfm").at("error").inner_html
155
+ else
156
+ raise RequestFailedError, doc.at("lfm").at("error").inner_html
157
+ end
158
+ end
159
+
160
+ doc.at("lfm")["status"]
161
+ end
162
+
163
+ end
164
+
165
+ def initialize(artist, name, o={})
166
+ raise ArgumentError, "Artist is required" if artist.blank?
167
+ raise ArgumentError, "Name is required" if name.blank?
168
+ @artist = artist
169
+ @name = name
170
+
171
+ options = {:include_info => false}.merge(o)
172
+ load_info if options[:include_info]
173
+ end
174
+
175
+ def load_info(xml=nil)
176
+ unless xml
177
+ doc = self.class.fetch_and_parse("track.getInfo", {:artist => @artist, :track => @name})
178
+ xml = (doc / :track).first
179
+ end
180
+
181
+ return self if xml.nil?
182
+
183
+ self.now_playing = xml['nowplaying'] == 'true' ? true : false
184
+ self.artist_mbid = (xml).at(:artist)['mbid'] if (xml).at(:artist) && (xml).at(:artist)['mbid']
185
+ self.artist_mbid = (xml).at(:artist).at(:mbid).inner_html if artist_mbid.nil? && (xml).at(:artist) && (xml).at(:artist).at(:mbid)
186
+ self.mbid = (xml).at(:mbid).inner_html if (xml).at(:mbid)
187
+ self.playcount = (xml).at(:playcount).inner_html if (xml).at(:playcount)
188
+ self.chartposition = self.rank = xml['rank'] if xml['rank']
189
+ self.url = Base.fix_url((xml).at(:url).inner_html) if (xml).at(:url)
190
+ self.streamable = (xml).at(:track)['streamable'] if (xml).at(:track) && (xml).at(:track)['streamable']
191
+ self.streamable = (xml).at(:streamable).inner_html == '1' ? 'yes' : 'no' if streamable.nil? && (xml).at(:streamable)
192
+ self.duration = (xml).at(:duration).inner_html.to_i if (xml).at(:duration)
193
+
194
+ self.count = xml['count'] if xml['count']
195
+ self.album = (xml).at(:album).inner_html if (xml).at(:album)
196
+ self.album_mbid = (xml).at(:album)['mbid'] if (xml).at(:album) && (xml).at(:album)['mbid']
197
+ self.date = Base.parse_time((xml).at(:date).inner_html) if (xml).at(:date)
198
+ self.date_uts = (xml).at(:date)['uts'] if (xml).at(:date) && (xml).at(:date)['uts']
199
+
200
+ if wiki_xml = xml.at(:wiki)
201
+ self.summary = wiki_xml.at(:summary).to_plain_text if wiki_xml.at(:summary)
202
+ self.content = wiki_xml.at(:content).to_plain_text if wiki_xml.at(:content)
203
+ end
204
+
205
+ self.images = {}
206
+ (xml/'image').each {|image|
207
+ self.images[image['size']] = image.inner_html if self.images[image['size']].nil?
208
+ }
209
+
210
+ self.thumbnail = images['small']
211
+ self.image = images['medium']
212
+
213
+ self
214
+ end
215
+
216
+ def albums(force=false)
217
+ get_instance("track.getInfo", :albums, :album, {:track => @name, :artist => @artist}, force)
218
+ end
219
+
220
+ def fans(force=false)
221
+ get_instance("track.getTopFans", :fans, :user, {:track => @name, :artist => @artist}, force)
222
+ end
223
+
224
+ def tags(force=false)
225
+ get_instance("track.getTopTags", :tags, :tag, {:track => @name, :artist => @artist}, force)
226
+ end
227
+
228
+ def similar(limit = 10, force = false)
229
+ get_instance('track.getSimilar', :similar, :track, {:track => @name, :artist => @artist, :limit => limit}, force)
230
+ end
231
+
232
+ # The session_key is returned by auth.session.key
233
+ def love(session_key)
234
+ Track.love(@artist, @name, session_key)
235
+ end
236
+
237
+ # scrobble this track
238
+ # time : a time object set to the time the track started playing
239
+ # session_key: the session key you got during authentification
240
+ def scrobble(time, session_key)
241
+ Track.scrobble({
242
+ :session_key => session_key,
243
+ :time => time,
244
+ :track => @name,
245
+ :artist => @artist,
246
+ :album => @album,
247
+ :mbid => @mbid
248
+ })
249
+ end
250
+
251
+ # inform last.fm that this track is currently playing
252
+ # time : a time object set to the time the track started playing
253
+ # session_key: the session key you got during authentification
254
+ def updateNowPlaying(time, session_key)
255
+ Track.updateNowPlaying({
256
+ :session_key => session_key,
257
+ :time => time,
258
+ :track => @name,
259
+ :artist => @artist,
260
+ :album => @album,
261
+ :mbid => @mbid
262
+ })
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,205 @@
1
+ # Probably the most common use of this lib would be to get your most recent tracks or your top tracks. Below are some code samples.
2
+ # user = Rockstar::User.new('jnunemaker')
3
+ #
4
+ # puts "#{user.username}'s Recent Tracks"
5
+ # puts "=" * (user.username.length + 16)
6
+ # user.recent_tracks.each { |t| puts t.name }
7
+ #
8
+ # puts
9
+ # puts
10
+ #
11
+ # puts "#{user.username}'s Top Tracks"
12
+ # puts "=" * (user.username.length + 13)
13
+ # user.top_tracks.each { |t| puts "(#{t.playcount}) #{t.name}" }
14
+ #
15
+ # Which would output something like:
16
+ #
17
+ # jnunemaker's Recent Tracks
18
+ # ==========================
19
+ # Everything You Want
20
+ # You're a God
21
+ # Bitter Sweet Symphony [Original Version]
22
+ # Lord I Guess I'll Never Know
23
+ # Country Song
24
+ # Bitter Sweet Symphony (Radio Edit)
25
+ #
26
+ #
27
+ # jnunemaker's Top Tracks
28
+ # =======================
29
+ # (62) Probably Wouldn't Be This Way
30
+ # (55) Not Ready To Make Nice
31
+ # (45) Easy Silence
32
+ # (43) Song 2
33
+ # (40) Everybody Knows
34
+ # (39) Before He Cheats
35
+ # (39) Something's Gotta Give
36
+ # (38) Hips Don't Lie (featuring Wyclef Jean)
37
+ # (37) Unwritten
38
+ # (37) Move Along
39
+ # (37) Dance, Dance
40
+ # (36) We Belong Together
41
+ # (36) Jesus, Take the Wheel
42
+ # (36) Black Horse and the Cherry Tree (radio version)
43
+ # (35) Photograph
44
+ # (35) You're Beautiful
45
+ # (35) Walk Away
46
+ # (34) Stickwitu
47
+ module Rockstar
48
+ class User < Base
49
+ # attributes needed to initialize
50
+ attr_reader :username, :period
51
+
52
+ # profile attributes
53
+ attr_accessor :id, :cluster, :url, :realname, :mbox_sha1sum, :registered
54
+ attr_accessor :registered_unixtime, :age, :gender, :country, :playcount, :avatar, :realname, :images
55
+
56
+ # neighbor attributes
57
+ attr_accessor :match
58
+
59
+ # track fans attributes
60
+ attr_accessor :weight
61
+
62
+ class << self
63
+ def new_from_xml(xml, doc=nil)
64
+ u = User.new((xml).at(:name).inner_html)
65
+ u.url = Base.fix_url((xml).at(:url).inner_html) if (xml).at(:url)
66
+
67
+ u.images = {}
68
+ (xml/'image').each {|image|
69
+ u.images[image['size']] = image.inner_html if u.images[image['size']].nil?
70
+ }
71
+
72
+ u.avatar = u.images['small']
73
+
74
+ u.weight = (xml).at(:weight).inner_html if (xml).at(:weight)
75
+ u.match = (xml).at(:match).inner_html if (xml).at(:match)
76
+ u.realname= (xml).at(:realname).inner_html if (xml).at(:realname)
77
+ u
78
+ end
79
+
80
+ def find(*args)
81
+ options = {:include_profile => false}
82
+ options.merge!(args.pop) if args.last.is_a?(Hash)
83
+ users = args.flatten.inject([]) { |users, u| users << User.new(u, options); users }
84
+ users.length == 1 ? users.pop : users
85
+ end
86
+ end
87
+
88
+ def initialize(username, o={})
89
+ options = {:include_profile => false, :period => 'overall'}.merge(o)
90
+ raise ArgumentError if username.blank?
91
+ @username = username
92
+ @period = options[:period]
93
+ load_profile() if options[:include_profile]
94
+ end
95
+
96
+ def load_profile
97
+ doc = self.class.fetch_and_parse("user.getInfo", {:user => @username})
98
+ @id = (doc).at(:id).inner_html
99
+ @url = Base.fix_url((doc).at(:url).inner_html)
100
+ @realname = (doc).at(:realname).inner_html
101
+ @registered = (doc).at(:registered).inner_html
102
+ @registered_unixtime = (doc).at(:registered)['unixtime']
103
+ @age = (doc).at(:age).inner_html
104
+ @gender = (doc).at(:gender).inner_html
105
+ @country = (doc).at(:country).inner_html
106
+ @playcount = (doc).at(:playcount).inner_html
107
+
108
+ @images = {}
109
+ (doc/'image').each {|image|
110
+ @images[image['size']] = image.inner_html
111
+ }
112
+
113
+ @avatar = @images["small"]
114
+ end
115
+
116
+ def top_artists(force=false, options = {})
117
+ default_options = {
118
+ :period => self.period
119
+ }
120
+ options = default_options.merge(options)
121
+ options[:user] = @username
122
+
123
+ get_instance("user.getTopArtists", :top_artists, :artist, options, force)
124
+ end
125
+
126
+ def top_albums(force=false)
127
+ get_instance("user.getTopAlbums", :top_albums, :album, {:user => @username}, force)
128
+ end
129
+
130
+ def top_tracks(force=false)
131
+ get_instance("user.getTopTracks", :top_tracks, :track, {:user => @username}, force)
132
+ end
133
+
134
+ def top_tags(force=false)
135
+ get_instance("user.getTopTags", :top_tags, :tag, {:user => @username}, force)
136
+ end
137
+
138
+ def friends(force=false)
139
+ get_instance("user.getFriends", :friends, :user, {:user => @username}, force)
140
+ end
141
+
142
+ def neighbours(force=false)
143
+ get_instance("user.getNeighbours", :neighbours, :user, {:user => @username}, force)
144
+ end
145
+
146
+ def recent_tracks(force=false)
147
+ get_instance("user.getRecentTracks", :recent_tracks, :track, {:user => @username}, force)
148
+ end
149
+
150
+ def recent_loved_tracks(force=false)
151
+ get_instance("user.getLovedTracks", :recent_loved_tracks, :track, {:user => @username}, force)
152
+ end
153
+
154
+ # The session_key is returned by auth.session.key
155
+ def recommended_artists(session_key, force=false)
156
+ get_instance("user.getRecommendedArtists", :recommendations, :artist, {:user => @username, :sk => session_key}, force)
157
+ end
158
+
159
+ def charts(force=false)
160
+ get_instance("user.getWeeklyChartList", :charts, :chart, {:user => @username}, force)
161
+ end
162
+
163
+ def weekly_artist_chart(from=nil, to=nil)
164
+ doc = self.class.fetch_and_parse("user.getWeeklyArtistChart", {:user => @username, :from => from, :to => to})
165
+ (doc/:artist).inject([]) { |elements, el| elements << Artist.new_from_xml(el); elements }
166
+ end
167
+
168
+ def weekly_album_chart(from=nil, to=nil)
169
+ doc = self.class.fetch_and_parse("user.getWeeklyAlbumChart", {:user => @username, :from => from, :to => to})
170
+ (doc/:album).inject([]) { |elements, el| elements << Album.new_from_xml(el); elements }
171
+ end
172
+
173
+ def weekly_track_chart(from=nil, to=nil)
174
+ doc = self.class.fetch_and_parse("user.getWeeklyTrackChart", {:user => @username, :from => from, :to => to})
175
+ (doc/:track).inject([]) { |elements, el| elements << Track.new_from_xml(el); elements }
176
+ end
177
+
178
+ # Wrappers for Rockstar::Library
179
+ def artists(force=false, options = {})
180
+ default_options = {
181
+ :user => @username
182
+ }
183
+ options = default_options.merge(options)
184
+
185
+ library = Rockstar::Library.new
186
+ library.artists(false, options)
187
+ end
188
+
189
+ def albums(force=false, options = {})
190
+ default_options = {
191
+ :user => @username
192
+ }
193
+ options = default_options.merge(options)
194
+
195
+ library = Rockstar::Library.new
196
+ library.albums(false, options)
197
+ end
198
+
199
+ # Get the recommendated events for the user, auth.session.key needed.
200
+ def events(session_key, force = false)
201
+ get_instance("user.getEvents", :events, :event, {:user => @username, :sk => session_key}, force)
202
+ end
203
+
204
+ end
205
+ end