Class: Scrobbler::User

Inherits:
Base
  • Object
show all
Extended by:
ImageClassFuncs
Includes:
ImageObjectFuncs
Defined in:
lib/scrobbler/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ImageClassFuncs

maybe_image_node

Methods included from ImageObjectFuncs

#check_image_node, #image

Methods inherited from Base

api_key=, connection, get, maybe_streamable_attribute, maybe_streamable_node, post_request, request, sanitize, secret=

Constructor Details

#initialize(username, input = {}) ⇒ User

Returns a new instance of User.

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
84
# File 'lib/scrobbler/user.rb', line 77

def initialize(username, input={})
  data = {:include_profile => false}.merge(input)
  raise ArgumentError if username.blank?
  @username = username
  @name = @username
  load_profile() if data[:include_profile]
  populate_data(data)
end

Instance Attribute Details

#matchObject (readonly)

Returns the value of attribute match.



53
54
55
# File 'lib/scrobbler/user.rb', line 53

def match
  @match
end

#nameObject (readonly)

Returns the value of attribute name.



53
54
55
# File 'lib/scrobbler/user.rb', line 53

def name
  @name
end

#realnameObject (readonly)

Returns the value of attribute realname.



53
54
55
# File 'lib/scrobbler/user.rb', line 53

def realname
  @realname
end

#urlObject (readonly)

Returns the value of attribute url.



53
54
55
# File 'lib/scrobbler/user.rb', line 53

def url
  @url
end

#usernameObject (readonly)

Returns the value of attribute username.



53
54
55
# File 'lib/scrobbler/user.rb', line 53

def username
  @username
end

#weightObject (readonly)

Returns the value of attribute weight.



53
54
55
# File 'lib/scrobbler/user.rb', line 53

def weight
  @weight
end

Class Method Details

.find(*args) ⇒ Object



69
70
71
72
73
74
# File 'lib/scrobbler/user.rb', line 69

def find(*args)
  options = {:include_profile => false}
  options.merge!(args.pop) if args.last.is_a?(Hash)
  users = args.flatten.inject([]) { |users, u| users << User.new(u, options); users }
  users.length == 1 ? users.pop : users
end

.new_from_libxml(xml) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/scrobbler/user.rb', line 56

def new_from_libxml(xml)
  data = {}
  xml.children.each do |child|
    data[:name] = child.content if child.name == 'name'
    data[:url] = child.content if child.name == 'url'
    data[:weight] = child.content.to_i if child.name == 'weight'
    data[:match] = child.content if child.name == 'match'
    data[:realname] = child.content if child.name == 'realname'
    maybe_image_node(data, child)
  end
  User.new(data[:name], data)
end

Instance Method Details

#events(force = false) ⇒ Object

Get a list of upcoming events that this user is attending.

Supports ical, ics or rss as its format



89
90
91
# File 'lib/scrobbler/user.rb', line 89

def events(force=false)
  get_response('user.getevents', :events, 'events', 'event', {'user'=>@username}, force)
end

#friends(force = false, page = 1, limit = 50) ⇒ Object

Get a list of the user’s friends on Last.fm.



94
95
96
# File 'lib/scrobbler/user.rb', line 94

def friends(force=false, page=1, limit=50)
  get_response('user.getfriends', :friends, 'friends', 'user', {'user'=>@username, 'page'=>page.to_s, 'limit'=>limit.to_s}, force)
end

#load_infoObject

Get information about a user profile.

Raises:

  • (NotImplementedError)


99
100
101
102
# File 'lib/scrobbler/user.rb', line 99

def load_info
    # This function requires authentication, but SimpleAuth is not yet 2.0
    raise NotImplementedError
end

#loved_tracks(force = false) ⇒ Object

Get the last 50 tracks loved by a user.



105
106
107
# File 'lib/scrobbler/user.rb', line 105

def loved_tracks(force=false)
    get_response('user.getlovedtracks', :loved_tracks, 'lovedtracks', 'track', {'user'=>@username}, force)
end

#neighbours(force = false) ⇒ Object

Get a list of a user’s neighbours on Last.fm.



110
111
112
# File 'lib/scrobbler/user.rb', line 110

def neighbours(force=false)
  get_response('user.getneighbours', :neighbours, 'neighbours', 'user', {'user'=>@username}, force)
end

#past_events(format = :ics) ⇒ Object

Get a paginated list of all events a user has attended in the past.

Raises:

  • (NotImplementedError)


115
116
117
118
# File 'lib/scrobbler/user.rb', line 115

def past_events(format=:ics)
  # This needs a Event class, which is yet not available
  raise NotImplementedError
end

#playlists(force = false) ⇒ Object

Get a list of a user’s playlists on Last.fm.



121
122
123
124
# File 'lib/scrobbler/user.rb', line 121

def playlists(force=false)
                      #(api_method, instance_name, parent, element, parameters, force=false)
  get_response('user.getplaylists', :playlist, 'playlists', 'playlist', {'user'=>@username}, force)
end

#recent_tracks(force = false, parameters = {}) ⇒ Object

Get a list of the recent tracks listened to by this user. Indicates now playing track if the user is currently listening.

Possible parameters:

- limit: An integer used to limit the number of tracks returned.


131
132
133
134
# File 'lib/scrobbler/user.rb', line 131

def recent_tracks(force=false, parameters={})
  parameters.merge!({'user' => @username})
  get_response('user.getrecenttracks', :recent_tracks, 'recenttracks', 'track', parameters, force)
end

Get Last.fm artist recommendations for a user

Raises:

  • (NotImplementedError)


137
138
139
140
# File 'lib/scrobbler/user.rb', line 137

def recommended_artists
    # This function require authentication, but SimpleAuth is not yet 2.0
    raise NotImplementedError
end

Get a paginated list of all events recommended to a user by Last.fm, based on their listening profile.

Raises:

  • (NotImplementedError)


144
145
146
147
# File 'lib/scrobbler/user.rb', line 144

def recommended_events
    # This function require authentication, but SimpleAuth is not yet 2.0
    raise NotImplementedError
end

#shout(message) ⇒ Object

Shout on this user’s shoutbox

Raises:

  • (NotImplementedError)


216
217
218
219
# File 'lib/scrobbler/user.rb', line 216

def shout(message)
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

#shoutsObject

Get shouts for this user.

Raises:

  • (NotImplementedError)


150
151
152
153
# File 'lib/scrobbler/user.rb', line 150

def shouts
  # This needs a Shout class which is yet not available
  raise NotImplementedError
end

#top_albums(force = false, period = 'overall') ⇒ Object

Get the top albums listened to by a user. You can stipulate a time period. Sends the overall chart by default.



157
158
159
# File 'lib/scrobbler/user.rb', line 157

def top_albums(force=false, period='overall')
  get_response('user.gettopalbums', :top_albums, 'topalbums', 'album', {'user'=>@username, 'period'=>period}, force)
end

#top_artists(force = false, period = 'overall') ⇒ Object

Get the top artists listened to by a user. You can stipulate a time period. Sends the overall chart by default.



163
164
165
# File 'lib/scrobbler/user.rb', line 163

def top_artists(force=false, period='overall')
  get_response('user.gettopartists', :top_artists, 'topartists', 'artist', {'user' => @username, 'period'=>period}, force)
end

#top_tags(force = false) ⇒ Object

Get the top tags used by this user.



168
169
170
# File 'lib/scrobbler/user.rb', line 168

def top_tags(force=false)
  get_response('user.gettoptags', :top_tags, 'toptags', 'tag', {'user'=>@username}, force)
end

#top_tracks(force = false, period = 'overall') ⇒ Object

Get the top tracks listened to by a user. You can stipulate a time period. Sends the overall chart by default.



174
175
176
# File 'lib/scrobbler/user.rb', line 174

def top_tracks(force=false, period='overall')
  get_response('user.gettoptracks', :top_tracks, 'toptracks', 'track', {'user'=>@username, 'period'=>period}, force)
end

#weekly_album_chart(from = nil, to = nil) ⇒ Object

Get an album chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent album chart for this user.



181
182
183
184
185
186
# File 'lib/scrobbler/user.rb', line 181

def weekly_album_chart(from=nil, to=nil)
  parameters = {'user' => @username}
  parameters['from'] = from unless from.nil?
  parameters['to'] = to unless to.nil?
  get_response('user.getweeklyalbumchart', nil, 'weeklyalbumchart', 'album', parameters, true)
end

#weekly_artist_chart(from = nil, to = nil) ⇒ Object

Get an artist chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent artist chart for this user.



191
192
193
194
195
196
# File 'lib/scrobbler/user.rb', line 191

def weekly_artist_chart(from=nil, to=nil)
  parameters = {'user' => @username}
  parameters['from'] = from unless from.nil?
  parameters['to'] = to unless to.nil?
  get_response('user.getweeklyartistchart', nil, 'weeklyartistchart', 'artist', parameters, true)
end

#weekly_chart_list(force = false) ⇒ Object

Get a list of available charts for this user, expressed as date ranges which can be sent to the chart services.

Raises:

  • (NotImplementedError)


200
201
202
203
# File 'lib/scrobbler/user.rb', line 200

def weekly_chart_list(force=false)
  # @todo
  raise NotImplementedError
end

#weekly_track_chart(from = nil, to = nil) ⇒ Object

Get a track chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent track chart for this user.



208
209
210
211
212
213
# File 'lib/scrobbler/user.rb', line 208

def weekly_track_chart(from=nil, to=nil)
  parameters = {'user' => @username}
  parameters['from'] = from unless from.nil?
  parameters['to'] = to unless to.nil?
  get_response('user.getweeklytrackchart', nil, 'weeklytrackchart', 'track', parameters, true)
end