diff options
Diffstat (limited to 'modern.go')
| -rw-r--r-- | modern.go | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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 |
