X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=kraftakt.go;h=8d562996688c99d5fecb12bb23dcbbd6ae8dbd76;hb=5b245cc42860c980c321c1c1829cdc373d53ac53;hp=e84b03a5e37aacf29e7748e0ddd585357a507888;hpb=1b0eaa82adf8853641ac460743020f83e889a4a3;p=kraftakt.git diff --git a/kraftakt.go b/kraftakt.go index e84b03a..8d56299 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -137,12 +137,7 @@ func loginHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ * } func fitbitConnectHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, u *app.User) error { - c, err := fitbit.NewClient(ctx, "", u) - if err != nil { - return err - } - - http.Redirect(w, r, c.AuthURL(ctx), http.StatusTemporaryRedirect) + http.Redirect(w, r, fitbit.AuthURL(ctx, u), http.StatusTemporaryRedirect) return nil } @@ -202,12 +197,7 @@ func fitbitDisconnectHandler(ctx context.Context, w http.ResponseWriter, r *http } func googleConnectHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, u *app.User) error { - c, err := gfit.NewClient(ctx, u) - if err != nil { - return err - } - - http.Redirect(w, r, c.AuthURL(ctx), http.StatusTemporaryRedirect) + http.Redirect(w, r, gfit.AuthURL(ctx, u), http.StatusTemporaryRedirect) return nil } @@ -287,6 +277,8 @@ func fitbitNotifyHandler(ctx context.Context, w http.ResponseWriter, r *http.Req // handleNotifications parses fitbit notifications and requests the individual // activities from Fitbit. It is executed asynchronously via the delay package. func handleNotifications(ctx context.Context, payload []byte) error { + log.Debugf(ctx, "NOTIFY -> %s", payload) + if err := app.LoadConfig(ctx); err != nil { return err } @@ -312,7 +304,7 @@ func handleNotifications(ctx context.Context, payload []byte) error { } func handleNotification(ctx context.Context, s *fitbit.Subscription) error { - u, err := app.UserByID(ctx, s.SubscriptionID) + u, err := fitbit.UserFromSubscriberID(ctx, s.SubscriptionID) if err != nil { return err }