Skip to content

Commit

Permalink
api: GET artists
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkay committed Nov 22, 2011
1 parent 47f2017 commit e16077b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ be authenticated using HTTP basic authentication.
* artist/<mbid>
* GET: artist info, no auth

* artists
* artists/<userid>
* GET: list of all artists for the user (mbid, name, sort_name,
disambiguation)
* PUT: follow a new artist, return the artist info or the list of artists if
Expand Down
15 changes: 15 additions & 0 deletions api/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ def read(self, request, mbid):
'disambiguation': artist.disambiguation,
}

class ArtistsHandler(BaseHandler):
allowed_methods = ('GET',)

def read(self, request, userid):
if request.user.username != userid:
return rc.FORBIDDEN

artists = Artist.get_by_user(user=request.user)
return [{
'mbid': artist.mbid,
'name': artist.name,
'sort_name': artist.sort_name,
'disambiguation': artist.disambiguation,
} for artist in artists]

class ReleaseHandler(AnonymousBaseHandler):
allowed_methods = ('GET',)

Expand Down
4 changes: 2 additions & 2 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
auth = {'authentication': HttpBasicAuthentication(realm="api")}

artist_handler = Resource(handler=ArtistHandler)
#artists_handler = Resource(handler=ArtistsHandler, **auth)
artists_handler = Resource(handler=ArtistsHandler, **auth)
release_handler = Resource(handler=ReleaseHandler)

urlpatterns = patterns('',
(r'artist/(?P<mbid>[0-9a-f\-]{36})', artist_handler),
# url(r'artists', artists_handler),
(r'artists/(?P<userid>[0-9a-z]{30})', artists_handler),
(r'release/(?P<mbid>[0-9a-f\-]{36})', release_handler),
)

0 comments on commit e16077b

Please sign in to comment.