Class: Rdio::Api
Overview
Provides main API functionality by translating Ruby calls to REST calls to the super class
Constant Summary
Constants inherited from BaseApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#addFriend(user) ⇒ Object
Add a friend to the current user.
-
#addToCollection(objs) ⇒ Object
Add tracks or playlists to the current user’s collection.
-
#addToPlaylist(playlist, tracks) ⇒ Object
Add a track to a playlist.
- #counts(query, types = nil, never_or = nil, extras = nil, start = nil, count = nil) ⇒ Object
-
#createPlaylist(name, description, tracks, extras = nil) ⇒ Object
Create a new playlist in the current user’s collection.
-
#currentUser(extras = nil) ⇒ Object
Get information about the currently logged in user.
-
#deletePlaylist(playlist) ⇒ Object
Delete a playlist.
-
#findUserByEmail(email) ⇒ Object
Find a user either by email address or by their username.
-
#findUserByVanityName(name) ⇒ Object
Find a user either by email address or by their username.
-
#get(objs, type = nil, extras = nil) ⇒ Object
Fetch one or more objects from Rdio.
-
#getActivityStream(user, scope, last_id = nil) ⇒ Object
Get the activity events for a user, a user’s friends, or everyone on Rdio.
-
#getAlbumsForArtist(artist, featuring = nil, extras = nil, start = nil, count = nil) ⇒ Object
Return the albums by (or featuring) an artist.
-
#getAlbumsForArtistInCollection(artist, user = nil) ⇒ Object
Get the albums in the user’s collection by a particular artist.
-
#getAlbumsInCollection(user = nil, start = nil, count = nil, sort = nil, query = nil) ⇒ Object
Get all of the albums in the user’s collection.
-
#getArtistsInCollection(user = nil, start = nil, count = nil, sort = nil, query = nil) ⇒ Object
Get all of the artist in a user’s collection.
-
#getHeavyRotation(user = nil, type = nil, friends = nil, limit = nil) ⇒ Object
Find the most popular artists or albums for a user, their friends or the whole site.
-
#getNewReleases(time = nil, start = nil, count = nil, extras = nil) ⇒ Object
Return new albums released across a timeframe.
-
#getObjectFromShortCode(short_code, type = nil) ⇒ Object
Return the object that the supplied Rdio short-code is a representation of, or null if the short-code is invalid.
-
#getObjectFromUrl(url, type = nil) ⇒ Object
Return the object that the supplied Rdio url is a representation of, or null if the url doesn’t represent an object.
-
#getPlaybackToken(domain = nil) ⇒ Object
Get an playback token.
-
#getPlaylists(extras = nil) ⇒ Object
Get the current user’s playlists.
-
#getTopCharts(type, start = nil, count = nil, extras = nil) ⇒ Object
Return the site-wide most popular items for a given type.
-
#getTracksForAlbumInCollection(album, user = nil, extras = nil) ⇒ Object
Which tracks on the given album are in the user’s collection.
-
#getTracksForArtist(artist, appears_on = nil, start = nil, count = nil, extras = nil) ⇒ Object
Get all of the tracks by this artist.
-
#getTracksForArtistInCollection(artist, user = nil, extras = nil) ⇒ Object
Which tracks from the given artist are in the user’s collection.
-
#getTracksInCollection(user = nil, start = nil, count = nil, sort = nil, query = nil) ⇒ Object
Get all of the tracks in the user’s collection.
-
#initialize(key, secret) ⇒ Api
constructor
A new instance of Api.
-
#removeFriend(user) ⇒ Object
Remove a friend from the current user.
-
#removeFromCollection(objs) ⇒ Object
Remove tracks or playlists from the current user’s collection.
-
#removeFromPlaylist(playlist, index, count, tracks) ⇒ Object
Remove an item from a playlist by its position in the playlist.
-
#search(query, types = nil, never_or = nil, extras = nil, start = nil, count = nil) ⇒ Object
Search for artists, albums, tracks, users or all kinds of objects.
-
#searchSuggestions(query, extras) ⇒ Object
Match the supplied prefix against artists, albums, tracks and people in the Rdio system.
Methods inherited from BaseApi
#call, convert_args, #get_pin, #get_pin=, #return_object
Constructor Details
#initialize(key, secret) ⇒ Api
Returns a new instance of Api.
9 10 11 |
# File 'lib/rdio/api.rb', line 9 def initialize(key,secret) super key,secret end |
Instance Method Details
#addFriend(user) ⇒ Object
Add a friend to the current user.
14 15 16 17 18 19 |
# File 'lib/rdio/api.rb', line 14 def addFriend(user) method = 'addFriend' type = true args = {:user=>user} return_object type,method,args,true end |
#addToCollection(objs) ⇒ Object
Add tracks or playlists to the current user’s collection.
22 23 24 25 26 27 |
# File 'lib/rdio/api.rb', line 22 def addToCollection(objs) method = 'addToCollection' type = true args = {:keys=>keys(objs)} return_object type,method,args,true end |
#addToPlaylist(playlist, tracks) ⇒ Object
Add a track to a playlist.
30 31 32 33 34 35 |
# File 'lib/rdio/api.rb', line 30 def addToPlaylist(playlist,tracks) method = 'addToPlaylist' type = true args = {:playlist=>playlist, :tracks=>keys(tracks)} return_object type,method,args,true end |
#counts(query, types = nil, never_or = nil, extras = nil, start = nil, count = nil) ⇒ Object
339 340 341 342 |
# File 'lib/rdio/api.rb', line 339 def counts(query,types=nil,never_or=nil,extras=nil,start=nil,count=nil) obj = search_json query,types,never_or,extras,start,count return JSONObj.new obj end |
#createPlaylist(name, description, tracks, extras = nil) ⇒ Object
Create a new playlist in the current user’s collection. The new playlist will be returned if the creation is successful, otherwise null will be returned.
40 41 42 43 44 45 46 47 |
# File 'lib/rdio/api.rb', line 40 def createPlaylist(name,description,tracks,extras=nil) method = 'createPlaylist' type = Playlist args = {:name=>name,:description=>description, :tracks=>keys(tracks)} args[:extras] = extras if extras return_object type,method,args,true end |
#currentUser(extras = nil) ⇒ Object
Get information about the currently logged in user.
50 51 52 53 54 55 56 |
# File 'lib/rdio/api.rb', line 50 def currentUser(extras=nil) method = 'currentUser' type = User args = {} args[:extras] = extras if extras return_object type,method,args,true end |
#deletePlaylist(playlist) ⇒ Object
Delete a playlist.
59 60 61 62 63 64 |
# File 'lib/rdio/api.rb', line 59 def deletePlaylist(playlist) method = 'deletePlaylist' type = Boolean args = {:playlist=>playlist} return_object type,method,args,true end |
#findUserByEmail(email) ⇒ Object
Find a user either by email address or by their username. Exactly one of email or vanityName must be supplied.
68 69 70 71 72 73 |
# File 'lib/rdio/api.rb', line 68 def findUserByEmail(email) method = 'findUser' type = User args = {:email=>email} return_object type,method,args end |
#findUserByVanityName(name) ⇒ Object
Find a user either by email address or by their username. Exactly one of email or vanityName must be supplied.
77 78 79 80 81 82 |
# File 'lib/rdio/api.rb', line 77 def findUserByVanityName(name) method = 'findUser' type = User args = {:vanityName=>name} return_object type,method,args end |
#get(objs, type = nil, extras = nil) ⇒ Object
Fetch one or more objects from Rdio.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rdio/api.rb', line 85 def get(objs,type=nil,extras=nil) if not objs.is_a? Array objs = [objs] end method = 'get' cls = type args = {:keys=>keys(objs)} args[:extras] = extras if extras json = call method,args if Rdio::log_json Rdio::log "json: #{json}" end create_object type,json,true end |
#getActivityStream(user, scope, last_id = nil) ⇒ Object
Get the activity events for a user, a user’s friends, or everyone on Rdio.
102 103 104 105 106 107 108 109 |
# File 'lib/rdio/api.rb', line 102 def getActivityStream(user,scope,last_id=nil) method = 'getActivityStream' type = ActivityStream args = {:user=>user,:scope=>scope} args[:last_id] = last_id if last_id auth = user return_object type,method,args,auth end |
#getAlbumsForArtist(artist, featuring = nil, extras = nil, start = nil, count = nil) ⇒ Object
Return the albums by (or featuring) an artist.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rdio/api.rb', line 112 def getAlbumsForArtist(artist,featuring=nil,extras=nil,start=nil,count=nil) method = 'getAlbumsForArtist' type = Album args = {:artist=>artist} args[:featuring] = featuring if featuring args[:extras] = extras if extras args[:start] = start if start args[:count] = count if count return_object type,method,args end |
#getAlbumsForArtistInCollection(artist, user = nil) ⇒ Object
Get the albums in the user’s collection by a particular artist.
124 125 126 127 128 129 130 131 |
# File 'lib/rdio/api.rb', line 124 def getAlbumsForArtistInCollection(artist,user=nil) method = 'getAlbumsForArtistInCollection' type = Album args = {:artist=>artist} args[:user] = user if user auth = !!user return_object type,method,args,auth end |
#getAlbumsInCollection(user = nil, start = nil, count = nil, sort = nil, query = nil) ⇒ Object
Get all of the albums in the user’s collection.
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rdio/api.rb', line 134 def getAlbumsInCollection(user=nil,start=nil,count=nil,sort=nil,query=nil) method = 'getAlbumsInCollection' type = Album args = {} args[:user] = user if user args[:start] = start if start args[:count] = count if count args[:sort] = sort if sort args[:query] = query if query auth = !!user return_object type,method,args,auth end |
#getArtistsInCollection(user = nil, start = nil, count = nil, sort = nil, query = nil) ⇒ Object
Get all of the artist in a user’s collection.
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rdio/api.rb', line 148 def getArtistsInCollection(user=nil,start=nil,count=nil,sort=nil,query=nil) method = 'getArtistsInCollection' type = Artist args = {} args[:user] = user if user args[:start] = start if start args[:count] = count if count args[:sort] = sort if sort args[:query] = query if query auth = !!user return_object type,method,args,auth end |
#getHeavyRotation(user = nil, type = nil, friends = nil, limit = nil) ⇒ Object
Find the most popular artists or albums for a user, their friends or the whole site.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/rdio/api.rb', line 163 def getHeavyRotation(user=nil,type=nil,friends=nil,limit=nil) method = 'getHeavyRotation' cls = TODO if type == 'artist' cls = Artist elsif type == 'album' cls = Album end args = {} args[:user] = user if user args[:type] = type if type args[:friends] = friends if friends args[:limit] = limit if limit return_object cls,method,args end |
#getNewReleases(time = nil, start = nil, count = nil, extras = nil) ⇒ Object
Return new albums released across a timeframe.
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/rdio/api.rb', line 180 def getNewReleases(time=nil,start=nil,count=nil,extras=nil) method = 'getNewReleases' type = Album args = {} args[:time] = time if time args[:start] = start if start args[:count] = count if count args[:extras] = extras if extras return_object type,method,args end |
#getObjectFromShortCode(short_code, type = nil) ⇒ Object
Return the object that the supplied Rdio short-code is a representation of, or null if the short-code is invalid.
193 194 195 196 197 198 |
# File 'lib/rdio/api.rb', line 193 def getObjectFromShortCode(short_code,type=nil) method = 'getObjectFromShortCode' type = BaseObj if not type args = {:short_code=>short_code} return_object type,method,args,true end |
#getObjectFromUrl(url, type = nil) ⇒ Object
Return the object that the supplied Rdio url is a representation of, or null if the url doesn’t represent an object.
202 203 204 205 206 207 |
# File 'lib/rdio/api.rb', line 202 def getObjectFromUrl(url,type=nil) method = 'getObjectFromUrl' type = BaseObj if not type args = {:url=>url} return_object type,method,args,true end |
#getPlaybackToken(domain = nil) ⇒ Object
Get an playback token. If you are using this for web playback you must supply a domain.
211 212 213 214 215 216 217 |
# File 'lib/rdio/api.rb', line 211 def getPlaybackToken(domain=nil) method = 'getPlaybackToken' type = String args = {} args[:domain] = domain if domain return_object type,method,args,true end |
#getPlaylists(extras = nil) ⇒ Object
Get the current user’s playlists.
220 221 222 223 224 225 226 |
# File 'lib/rdio/api.rb', line 220 def getPlaylists(extras=nil) method = 'getPlaylists' type = Playlist args = {} args[:extras] = extras if extras return_object type,method,args,true end |
#getTopCharts(type, start = nil, count = nil, extras = nil) ⇒ Object
Return the site-wide most popular items for a given type.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/rdio/api.rb', line 229 def getTopCharts(type,start=nil,count=nil,extras=nil) method = 'getTopCharts' cls = TODO case type when 'Artist' cls = Artist when 'Album' cls = Album when 'Track' cls = Track when 'Playlist' cls = Playlist end args = {:type=>type} return_object cls,method,args end |
#getTracksForAlbumInCollection(album, user = nil, extras = nil) ⇒ Object
Which tracks on the given album are in the user’s collection.
247 248 249 250 251 252 253 254 |
# File 'lib/rdio/api.rb', line 247 def getTracksForAlbumInCollection(album,user=nil,extras=nil) method = 'getTracksForAlbumInCollection' type = Track args = {:album=>album} args[:user] = user if user args[:extras] = extras if extras return_object type,method,args end |
#getTracksForArtist(artist, appears_on = nil, start = nil, count = nil, extras = nil) ⇒ Object
Get all of the tracks by this artist.
257 258 259 260 261 262 263 264 265 266 |
# File 'lib/rdio/api.rb', line 257 def getTracksForArtist(artist,appears_on=nil,start=nil,count=nil,extras=nil) method = 'getTracksForArtist' type = Track args = {:artist=>artist} args[:appears_on] = appears_on if appears_on args[:start] = start if start args[:count] = count if count args[:extras] = extras if extras return_object type,method,args end |
#getTracksForArtistInCollection(artist, user = nil, extras = nil) ⇒ Object
Which tracks from the given artist are in the user’s collection.
269 270 271 272 273 274 275 276 |
# File 'lib/rdio/api.rb', line 269 def getTracksForArtistInCollection(artist,user=nil,extras=nil) method = 'getTracksForArtistInCollection' type = Track args = {:artist=>artist} args[:user] = user if user args[:extras] = extras if extras return_object type,method,args end |
#getTracksInCollection(user = nil, start = nil, count = nil, sort = nil, query = nil) ⇒ Object
Get all of the tracks in the user’s collection.
279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/rdio/api.rb', line 279 def getTracksInCollection(user=nil,start=nil,count=nil,sort=nil,query=nil) method = 'getTracksInCollection' type = Track args = {} args[:user] = user if user args[:start] = start if start args[:count] = count if count args[:sort] = sort if sort args[:query] = query if query return_object type,method,args end |
#removeFriend(user) ⇒ Object
Remove a friend from the current user.
292 293 294 295 296 297 |
# File 'lib/rdio/api.rb', line 292 def removeFriend(user) method = 'removeFriend' type = Boolean args = {:user=>user} return_object type,method,args,true end |
#removeFromCollection(objs) ⇒ Object
Remove tracks or playlists from the current user’s collection.
300 301 302 303 304 305 |
# File 'lib/rdio/api.rb', line 300 def removeFromCollection(objs) method = 'removeFromCollection' type = Boolean args = {:keys=>keys(objs)} return_object type,method,args end |
#removeFromPlaylist(playlist, index, count, tracks) ⇒ Object
Remove an item from a playlist by its position in the playlist.
308 309 310 311 312 313 314 |
# File 'lib/rdio/api.rb', line 308 def removeFromPlaylist(playlist,index,count,tracks) method = 'removeFromPlaylist' type = TODO args = {:playlist=>playlist,:index=>index, :count=>count,:tracks=>keys(tracks)} return_object type,method,args,truex end |
#search(query, types = nil, never_or = nil, extras = nil, start = nil, count = nil) ⇒ Object
Search for artists, albums, tracks, users or all kinds of objects.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/rdio/api.rb', line 317 def search(query,types=nil,never_or=nil,extras=nil,start=nil,count=nil) result = search_json query,types,never_or,extras,start,count return result if not result results = result['results'] || [] api = self # # This start out nil, because we need to reference classes in # types.rb and this gets loaded after this file. There's # probably a better way to do this. # if not @@types2classes @@types2classes = { 'r' => Artist, 'a' => Album, 's' => User, 't' => Track, 'p' => Playlist } end results.map {|o| @@types2classes[o['type']].new(api).fill o} end |
#searchSuggestions(query, extras) ⇒ Object
Match the supplied prefix against artists, albums, tracks and people in the Rdio system. Return the first ten matches.
346 347 348 349 350 351 352 |
# File 'lib/rdio/api.rb', line 346 def searchSuggestions(query,extras) method = 'searchSuggestions' type = TODO args = {:query=>query} args[:extras] = extras if extras return_object type,method,args end |