summaryrefslogtreecommitdiffstats
path: root/modern.go
diff options
context:
space:
mode:
Diffstat (limited to 'modern.go')
-rw-r--r--modern.go21
1 files changed, 13 insertions, 8 deletions
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