aboutsummaryrefslogtreecommitdiffstats
path: root/modern.go
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2016-11-22 22:42:22 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2016-11-22 22:42:22 -0500
commitf7a85af3fc9065d15ec9fd3084252351ff598035 (patch)
treec6f5fdf0ba10717f956940cd990a238b0186b2ce /modern.go
parentfbb328b6c33470f8aec74fcb5e6e7d0388067c1e (diff)
downloadlastfm-api-f7a85af3fc9065d15ec9fd3084252351ff598035.tar.gz
start working on TrackScrobble
Diffstat (limited to 'modern.go')
-rw-r--r--modern.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/modern.go b/modern.go
index 8a384c3..ee69dc4 100644
--- a/modern.go
+++ b/modern.go
@@ -11,6 +11,7 @@ type Api interface {
AuthGetToken(*http.Request) ApiResponse
AuthGetSession(*http.Request) ApiResponse
AuthGetMobileSession(*http.Request) ApiResponse
+ TrackScrobble(*http.Request, http.ResponseWriter) ApiResponse
}
type ApiResponse interface {
@@ -78,17 +79,27 @@ func (store *SqlStore) AuthGetSession(r *http.Request) ApiResponse {
return response
}
-func (store *SqlStore) TrackScrobble(r *http.Request) ApiResponse {
+func (store *SqlStore) TrackScrobble(r *http.Request, w http.ResponseWriter) ApiResponse {
+ if session, err := store.GetSession(r.FormValue("s")); err != nil {
+ scrobbles := parseScrobbles(r.Form, session)
+ store.PutScrobbles(scrobbles)
+ fmt.Fprintln(w, "OK")
+ } else {
+ fmt.Fprintln(w, "BADSESSION")
+ }
return struct{}{}
}
func ApiHandler(ds DataStore, w http.ResponseWriter, r *http.Request) {
method := r.FormValue("method")
var response ApiResponse
- if method == "auth.getToken" {
+ switch method {
+ case "auth.getToken":
response = ds.AuthGetToken(r)
- } else if method == "auth.getSession" {
+ case "auth.getSession":
response = ds.AuthGetSession(r)
+ case "track.scrobble":
+ response = ds.TrackScrobble(r, w)
}
var text []byte