diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2016-11-22 22:42:22 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2016-11-22 22:42:22 -0500 |
| commit | f7a85af3fc9065d15ec9fd3084252351ff598035 (patch) | |
| tree | c6f5fdf0ba10717f956940cd990a238b0186b2ce | |
| parent | fbb328b6c33470f8aec74fcb5e6e7d0388067c1e (diff) | |
| download | lastfm-api-f7a85af3fc9065d15ec9fd3084252351ff598035.tar.gz | |
start working on TrackScrobble
| -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 |
