| Class | Scrobbler::User |
| In: |
lib/scrobbler/user.rb
|
| Parent: | Base |
| age | [RW] | |
| avatar | [RW] | |
| cluster | [RW] | profile attributes |
| country | [RW] | |
| gender | [RW] | |
| id | [RW] | profile attributes |
| match | [RW] | neighbor attributes |
| mbox_sha1sum | [RW] | profile attributes |
| playcount | [RW] | |
| realname | [RW] | profile attributes |
| registered | [RW] | profile attributes |
| registered_unixtime | [RW] | |
| url | [RW] | profile attributes |
| username | [R] | attributes needed to initialize |
| weight | [RW] | track fans attributes |
# File lib/scrobbler/user.rb, line 72
72: def find(*args)
73: options = {:include_profile => false}
74: options.merge!(args.pop) if args.last.is_a?(Hash)
75: users = args.flatten.inject([]) { |users, u| users << User.new(u, options); users }
76: users.length == 1 ? users.pop : users
77: end
# File lib/scrobbler/user.rb, line 80
80: def initialize(username, o={})
81: options = {:include_profile => false}.merge(o)
82: raise ArgumentError if username.blank?
83: @username = username
84: load_profile() if options[:include_profile]
85: end
# File lib/scrobbler/user.rb, line 63
63: def new_from_xml(xml, doc=nil)
64: u = User.new((xml)['username'])
65: u.url = (xml).at(:url).inner_html if (xml).at(:url)
66: u.avatar = (xml).at(:image).inner_html if (xml).at(:image)
67: u.weight = (xml).at(:weight).inner_html if (xml).at(:weight)
68: u.match = (xml).at(:match).inner_html if (xml).at(:match)
69: u
70: end
# File lib/scrobbler/user.rb, line 87
87: def api_path
88: "/#{API_VERSION}/user/#{CGI::escape(username)}"
89: end
# File lib/scrobbler/user.rb, line 165
165: def charts(force=false)
166: get_instance(:weeklychartlist, :charts, :chart, force)
167: end
# File lib/scrobbler/user.rb, line 91
91: def current_events(format=:ics)
92: format = :ics if format.to_s == 'ical'
93: raise ArgumentError unless ['ics', 'rss'].include?(format.to_s)
94: "#{API_URL.chop}#{api_path}/events.#{format}"
95: end
# File lib/scrobbler/user.rb, line 141
141: def friends(force=false)
142: get_instance(:friends, :friends, :user, force)
143: end
# File lib/scrobbler/user.rb, line 97
97: def friends_events(format=:ics)
98: format = :ics if format.to_s == 'ical'
99: raise ArgumentError unless ['ics', 'rss'].include?(format.to_s)
100: "#{API_URL.chop}#{api_path}/friendevents.#{format}"
101: end
# File lib/scrobbler/user.rb, line 109
109: def load_profile
110: doc = self.class.fetch_and_parse("#{api_path}/profile.xml")
111: @id = (doc).at(:profile)['id']
112: @cluster = (doc).at(:profile)['cluster']
113: @url = (doc).at(:url).inner_html
114: @realname = (doc).at(:realname).inner_html
115: @mbox_sha1sum = (doc).at(:mbox_sha1sum).inner_html
116: @registered = (doc).at(:registered).inner_html
117: @registered_unixtime = (doc).at(:registered)['unixtime']
118: @age = (doc).at(:age).inner_html
119: @gender = (doc).at(:gender).inner_html
120: @country = (doc).at(:country).inner_html
121: @playcount = (doc).at(:playcount).inner_html
122: @avatar = (doc).at(:avatar).inner_html
123: end
# File lib/scrobbler/user.rb, line 145
145: def neighbours(force=false)
146: get_instance(:neighbours, :neighbours, :user, force)
147: end
# File lib/scrobbler/user.rb, line 153
153: def recent_banned_tracks(force=false)
154: get_instance(:recentbannedtracks, :recent_banned_tracks, :track, force)
155: end
# File lib/scrobbler/user.rb, line 157
157: def recent_loved_tracks(force=false)
158: get_instance(:recentlovedtracks, :recent_loved_tracks, :track, force)
159: end
# File lib/scrobbler/user.rb, line 149
149: def recent_tracks(force=false)
150: get_instance(:recenttracks, :recent_tracks, :track, force)
151: end
# File lib/scrobbler/user.rb, line 161
161: def recommendations(force=false)
162: get_instance(:systemrecs, :recommendations, :artist, force)
163: end
# File lib/scrobbler/user.rb, line 103
103: def recommended_events(format=:ics)
104: format = :ics if format.to_s == 'ical'
105: raise ArgumentError unless ['ics', 'rss'].include?(format.to_s)
106: "#{API_URL.chop}#{api_path}/eventsysrecs.#{format}"
107: end
# File lib/scrobbler/user.rb, line 129
129: def top_albums(force=false)
130: get_instance(:topalbums, :top_albums, :album, force)
131: end
# File lib/scrobbler/user.rb, line 125
125: def top_artists(force=false)
126: get_instance(:topartists, :top_artists, :artist, force)
127: end
# File lib/scrobbler/user.rb, line 137
137: def top_tags(force=false)
138: get_instance(:toptags, :top_tags, :tag, force)
139: end
# File lib/scrobbler/user.rb, line 133
133: def top_tracks(force=false)
134: get_instance(:toptracks, :top_tracks, :track, force)
135: end
# File lib/scrobbler/user.rb, line 175
175: def weekly_album_chart(from=nil, to=nil)
176: qs = create_query_string_from_timestamps(from, to)
177: doc = self.class.fetch_and_parse("#{api_path}/weeklyalbumchart.xml#{qs}")
178: (doc/:album).inject([]) { |elements, el| elements << Album.new_from_xml(el); elements }
179: end
# File lib/scrobbler/user.rb, line 169
169: def weekly_artist_chart(from=nil, to=nil)
170: qs = create_query_string_from_timestamps(from, to)
171: doc = self.class.fetch_and_parse("#{api_path}/weeklyartistchart.xml#{qs}")
172: (doc/:artist).inject([]) { |elements, el| elements << Artist.new_from_xml(el); elements }
173: end
# File lib/scrobbler/user.rb, line 181
181: def weekly_track_chart(from=nil, to=nil)
182: qs = create_query_string_from_timestamps(from, to)
183: doc = self.class.fetch_and_parse("#{api_path}/weeklytrackchart.xml#{qs}")
184: (doc/:track).inject([]) { |elements, el| elements << Track.new_from_xml(el); elements }
185: end