From 7034036c50f857456fb6c4cb45c39d6ac911bbe9 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 11 Dec 2016 21:02:18 -0500 Subject: basic scrobbling seems to work now --- modern.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'modern.go') diff --git a/modern.go b/modern.go index a01f29b..946335d 100644 --- a/modern.go +++ b/modern.go @@ -12,7 +12,7 @@ type Api interface { AuthGetToken(*http.Request) ApiResponse AuthGetSession(*http.Request) ApiResponse AuthGetMobileSession(*http.Request) ApiResponse - TrackScrobble(*http.Request, http.ResponseWriter) ApiResponse + TrackScrobble(*http.Request) (ApiResponse, error) } type ApiResponse interface { @@ -84,15 +84,16 @@ func (store *SqlStore) AuthGetSession(r *http.Request) ApiResponse { return response } -func (store *SqlStore) TrackScrobble(r *http.Request, w http.ResponseWriter) ApiResponse { - if session, err := store.GetSession(r.FormValue("s")); err != nil { +func (store *SqlStore) TrackScrobble(r *http.Request) (ApiResponse, error) { + if session, err := store.GetSession(r.FormValue("sk")); err != nil { + fmt.Printf("%v\n", err) + return struct{}{}, err + } else { scrobbles := parseScrobbles(r.Form, session) store.PutScrobbles(scrobbles) - fmt.Fprintln(w, "OK") - } else { - fmt.Fprintln(w, "BADSESSION") + return Scrobbles{Scrobbles: scrobbles, + Attrs: Attrs{1, 0}}, nil } - return struct{}{} } func ApiHandler(ds DataStore, w http.ResponseWriter, r *http.Request) { @@ -104,7 +105,11 @@ func ApiHandler(ds DataStore, w http.ResponseWriter, r *http.Request) { case "auth.getSession": response = ds.AuthGetSession(r) case "track.scrobble": - response = ds.TrackScrobble(r, w) + if r, err := ds.TrackScrobble(r); err != nil { + fmt.Printf("%v\n", err) + } else { + response = r + } } var text []byte -- cgit v1.2.3-70-g09d2