}
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
}
return err
}
- var errs appengine.MultiError
-
- for _, collection := range []string{"activities", "sleep"} {
- if err := c.Unsubscribe(ctx, collection); err != nil {
- errs = append(errs, fmt.Errorf("Unsubscribe(%q) = %v", collection, err))
- continue
- }
- log.Infof(ctx, "Successfully unsubscribed from %q", collection)
- }
-
- if err := c.DeleteToken(ctx); err != nil {
- errs = append(errs, fmt.Errorf("DeleteToken() = %v", err))
- }
- if len(errs) != 0 {
- return errs
+ if err := c.UnsubscribeAll(ctx); err != nil {
+ log.Errorf(ctx, "UnsubscribeAll() = %v", err)
+ return fmt.Errorf("deleting all subscriptions failed")
}
redirectURL := r.URL
}
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
}
// 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
}
}
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
}